Skip to content

Commit

Permalink
start auction fucntion
Browse files Browse the repository at this point in the history
  • Loading branch information
devsisingh committed Oct 23, 2023
1 parent d7d2151 commit 6e38215
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Components/placemarket.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import DateTimePicker from './Datetimepicker';
import { removeItem } from "../pages/api/removeitem";
import { updatePrice } from "../pages/api/updateprice";
import { updateTime } from "../pages/api/updatetime";
import { startAuction } from "../pages/api/startauction";
import { acceptbidendauction } from "../pages/api/acceptbidendauction";
import { useAccount } from "wagmi";

const MyAssets = () => {
Expand Down Expand Up @@ -386,6 +388,14 @@ refineArray.auctionStarteds = refineArray.auctionStarteds.map((asset) => {
setShowModal2(false);
}

async function auctionNft(nft) {
setLoading(true);
const updateauctiontime = (months * 30 * 24) + (days * 24) + (hours);
await startAuction(nft, tradhubAddress, updateauctiontime*60*60);
setLoading(false);
setShowModal(false);
}

const handleInputChange = () => {
setToggle1(!toggle1); // Toggle the state
};
Expand Down Expand Up @@ -452,7 +462,7 @@ refineArray.auctionStarteds = refineArray.auctionStarteds.map((asset) => {
{
toggle2 && (
<>
<p className="font-semibold text-gray-900 mt-4 mb-2">
{/* <p className="font-semibold text-gray-900 mt-4 mb-2">
Set starting Price
</p>
<div className="mb-2">
Expand All @@ -465,7 +475,7 @@ refineArray.auctionStarteds = refineArray.auctionStarteds.map((asset) => {
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
required
/>
</div>
</div> */}
<p className="font-semibold text-gray-900 mt-4 mb-2">Set Duration</p>
{/* <div className="mb-2"> */}
<button
Expand All @@ -485,7 +495,7 @@ refineArray.auctionStarteds = refineArray.auctionStarteds.map((asset) => {
<button
className="text-white bg-blue-500 text-sm px-20 py-3 mt-4 rounded-full border border-white shadow hover:shadow-lg outline-none focus:outline-none mr-1 mb-1 ease-linear transition-all duration-150"
type="button"
onClick={() => auctionNft(selectedNFT, price)}
onClick={() => auctionNft(selectedNFT)}
>
Set
</button>
Expand Down
16 changes: 16 additions & 0 deletions pages/api/startauction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ethers } from "ethers";
import Tradhub from '../../artifacts/contracts/tradehub/TradeHub.sol/TradeHub.json';
import etherContract from "../../utils/web3Modal";

export const startAuction = async (nft, tradhubAddress, auctiontime) => {
const tradhubContarct = await etherContract(tradhubAddress, Tradhub.abi)

try {
const transaction = await tradhubContarct.startAuction(nft.itemId,auctiontime);
console.log(transaction);
await transaction.wait();
} catch (e) {
console.log(e?.data?.message);
console.error(e);
}
};

0 comments on commit 6e38215

Please sign in to comment.