forked from Scaffold-Stark/scaffold-stark-2
-
Notifications
You must be signed in to change notification settings - Fork 19
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
1e513f3
commit 405fd38
Showing
17 changed files
with
1,593 additions
and
237 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
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 |
---|---|---|
@@ -1,16 +1,88 @@ | ||
import ButtonStyle from "~~/components/ButtonStyle/ButtonStyle"; | ||
"use client"; | ||
|
||
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 { useScaffoldContractRead } from "~~/hooks/scaffold-stark/useScaffoldContractRead"; | ||
import { useScaffoldContractWrite } from "~~/hooks/scaffold-stark/useScaffoldContractWrite"; | ||
import { notification } from "~~/utils/scaffold-stark"; | ||
import { addToIPFS } from "~~/utils/scaffold-stark/simpleNFT/ipfs-fetch"; | ||
import { useScaffoldContract } from "~~/hooks/scaffold-stark/useScaffoldContract"; | ||
import nftsMetadata from "~~/utils/scaffold-stark/simpleNFT/nftsMetadata"; | ||
|
||
const MyNFTs: NextPage = () => { | ||
const { address: connectedAddress, isConnected, isConnecting } = useAccount(); | ||
console.log(connectedAddress); | ||
|
||
const { data: yourCollectibleContract } = useScaffoldContract({ | ||
contractName: "Challenge0", | ||
}); | ||
|
||
const { writeAsync: mintItem, error: error } = useScaffoldContractWrite({ | ||
contractName: "Challenge0", | ||
functionName: "mint_item", | ||
args: [ | ||
connectedAddress ?? "", | ||
`[${new TextEncoder().encode("Your string here").toString()}]`, | ||
], | ||
}); | ||
|
||
// console.log(mintItem) | ||
// console.log(error) | ||
|
||
const { data: tokenIdCounter } = useScaffoldContractRead({ | ||
contractName: "Challenge0", | ||
functionName: "token_id_counter", | ||
watch: true, | ||
cacheOnBlock: true, | ||
}); | ||
|
||
const handleMintItem = async () => { | ||
// circle back to the zero item if we've reached the end of the array | ||
if (tokenIdCounter === undefined) 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], | ||
}); | ||
} catch (error) { | ||
notification.remove(notificationId); | ||
console.error(error); | ||
} | ||
}; | ||
|
||
function Page() { | ||
return ( | ||
<main className="flex flex-col flex-1"> | ||
<div className="flex flex-col items-center p-10"> | ||
<h1 className="text-4xl font-bold text-center mb-4">My NFTs</h1> | ||
<ButtonStyle>Mint NFT</ButtonStyle> | ||
<MyHoldings></MyHoldings> | ||
<> | ||
<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" onClick={handleMintItem}> | ||
Mint NFT | ||
</button> | ||
)} | ||
</div> | ||
</main> | ||
<MyHoldings /> | ||
</> | ||
); | ||
} | ||
}; | ||
|
||
export default Page; | ||
export default MyNFTs; |
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
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
Oops, something went wrong.