-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62a3aca
commit 7e4c4ca
Showing
16 changed files
with
1,002 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
"prettier": "^3.2.5" | ||
}, | ||
"dependencies": { | ||
"framer-motion": "^11.5.6", | ||
"postcss": "^8.4.38" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
'use client' | ||
|
||
import { useParams } from 'next/navigation' | ||
import type { NextPage } from "next"; | ||
import { useAccount } from "@starknet-react/core"; | ||
import { CustomConnectButton } from "~~/components/scaffold-stark/CustomConnectButton"; | ||
import { MyHoldings } from "~~/components/SimpleNFT/MyHoldings"; | ||
import { useScaffoldReadContract } from "~~/hooks/scaffold-stark/useScaffoldReadContract"; | ||
import { useScaffoldWriteContract } from "~~/hooks/scaffold-stark/useScaffoldWriteContract"; | ||
import { notification } from "~~/utils/scaffold-stark"; | ||
import { addToIPFS } from "~~/utils/simpleNFT/ipfs-fetch"; | ||
import nftsMetadata from "~~/utils/simpleNFT/nftsMetadata"; | ||
import { useState } from "react"; | ||
|
||
const SubmissionPage: NextPage = () => { | ||
const params = useParams() | ||
const { id } = params | ||
|
||
// Fetch submission data here if needed | ||
// For example, from an API endpoint | ||
|
||
const { address: connectedAddress, isConnected, isConnecting } = useAccount(); | ||
const [status, setStatus] = useState("Mint NFT"); | ||
|
||
const { writeAsync: mintItem } = useScaffoldWriteContract({ | ||
contractName: "YourCollectible", | ||
functionName: "mint_item", | ||
args: [connectedAddress, ""], | ||
}); | ||
|
||
const { data: tokenIdCounter, refetch } = useScaffoldReadContract({ | ||
contractName: "YourCollectible", | ||
functionName: "current", | ||
watch: false, | ||
}); | ||
|
||
const handleMintItem = async () => { | ||
setStatus("Minting NFT"); | ||
// circle back to the zero item if we've reached the end of the array | ||
if (tokenIdCounter === undefined) { | ||
setStatus("Mint NFT"); | ||
return; | ||
} | ||
|
||
const tokenIdCounterNumber = Number(tokenIdCounter); | ||
const currentTokenMetaData = | ||
nftsMetadata[tokenIdCounterNumber % nftsMetadata.length]; | ||
const notificationId = notification.loading("Uploading to IPFS"); | ||
try { | ||
const uploadedItem = await addToIPFS(currentTokenMetaData); | ||
|
||
// First remove previous loading notification and then show success notification | ||
notification.remove(notificationId); | ||
notification.success("Metadata uploaded to IPFS"); | ||
|
||
await mintItem({ | ||
args: [connectedAddress, uploadedItem.path], | ||
}); | ||
setStatus("Updating NFT List"); | ||
refetch(); | ||
} catch (error) { | ||
notification.remove(notificationId); | ||
console.error(error); | ||
setStatus("Mint NFT"); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="flex items-center flex-col pt-10"> | ||
<div className="px-5"> | ||
<h1 className="text-center mb-8"> | ||
<span className="block text-4xl font-bold">My NFTs</span> | ||
</h1> | ||
</div> | ||
</div> | ||
<div className="flex justify-center"> | ||
{!isConnected || isConnecting ? ( | ||
<CustomConnectButton /> | ||
) : ( | ||
<button | ||
className="btn btn-secondary text-white" | ||
disabled={status !== "Mint NFT"} | ||
onClick={handleMintItem} | ||
> | ||
{status !== "Mint NFT" && ( | ||
<span className="loading loading-spinner loading-xs"></span> | ||
)} | ||
{status} | ||
</button> | ||
)} | ||
</div> | ||
<MyHoldings setStatus={setStatus} /> | ||
</> | ||
) | ||
} | ||
|
||
export default SubmissionPage; |
Oops, something went wrong.