Skip to content

Commit

Permalink
fix: minting process
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo committed Apr 25, 2024
1 parent b613cfa commit 7883f39
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
18 changes: 15 additions & 3 deletions packages/nextjs/app/myNFTs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { useScaffoldContractWrite } from "~~/hooks/scaffold-stark/useScaffoldCon
import { notification } from "~~/utils/scaffold-stark";
import { addToIPFS } from "~~/utils/simpleNFT/ipfs-fetch";
import nftsMetadata from "~~/utils/simpleNFT/nftsMetadata";
import { useState } from "react";

const MyNFTs: NextPage = () => {
const { address: connectedAddress, isConnected, isConnecting } = useAccount();
const [status, setStatus] = useState("Mint NFT");

const { writeAsync: mintItem } = useScaffoldContractWrite({
contractName: "Challenge0",
Expand All @@ -26,6 +28,7 @@ const MyNFTs: NextPage = () => {
});

const handleMintItem = async () => {
setStatus("Minting NFT");
// circle back to the zero item if we've reached the end of the array
if (tokenIdCounter === undefined) return;

Expand All @@ -43,9 +46,11 @@ const MyNFTs: NextPage = () => {
await mintItem({
args: [connectedAddress, uploadedItem.path],
});
setStatus("Updating NFT List");
} catch (error) {
notification.remove(notificationId);
console.error(error);
setStatus("Mint NFT");
}
};

Expand All @@ -62,12 +67,19 @@ const MyNFTs: NextPage = () => {
{!isConnected || isConnecting ? (
<CustomConnectButton />
) : (
<button className="btn btn-secondary" onClick={handleMintItem}>
Mint NFT
<button
className="btn btn-secondary"
disabled={status !== "Mint NFT"}
onClick={handleMintItem}
>
{status !== "Mint NFT" && (
<span className="loading loading-spinner loading-xs"></span>
)}
{status}
</button>
)}
</div>
<MyHoldings />
<MyHoldings setStatus={setStatus} />
</>
);
};
Expand Down
10 changes: 7 additions & 3 deletions packages/nextjs/components/SimpleNFT/MyHoldings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useEffect, useState } from "react";
import { Dispatch, SetStateAction, useEffect, useState } from "react";
import { NFTCard } from "./NFTcard";
import { useAccount } from "@starknet-react/core";
import { useScaffoldContract } from "~~/hooks/scaffold-stark/useScaffoldContract";
Expand All @@ -16,7 +16,11 @@ export interface Collectible extends Partial<NFTMetaData> {
owner: string;
}

export const MyHoldings = () => {
export const MyHoldings = ({
setStatus,
}: {
setStatus: Dispatch<SetStateAction<string>>;
}) => {
const { address: connectedAddress } = useAccount();
const [myAllCollectibles, setMyAllCollectibles] = useState<Collectible[]>([]);
const [allCollectiblesLoading, setAllCollectiblesLoading] = useState(false);
Expand Down Expand Up @@ -77,7 +81,7 @@ export const MyHoldings = () => {
setAllCollectiblesLoading(false);
};

updateMyCollectibles();
updateMyCollectibles().finally(() => setStatus("Mint NFT"));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [connectedAddress, myTotalBalance]);

Expand Down
2 changes: 0 additions & 2 deletions packages/nextjs/components/SimpleNFT/NFTcard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useState } from "react";
import ButtonStyle from "../ButtonStyle/ButtonStyle";
import { Collectible } from "./MyHoldings";
import { AddressInput } from "../scaffold-stark";
import { Address } from "../scaffold-stark";
Expand All @@ -8,7 +7,6 @@ import { useScaffoldContractWrite } from "~~/hooks/scaffold-stark/useScaffoldCon
export const NFTCard = ({ nft }: { nft: Collectible }) => {
const [transferToAddress, setTransferToAddress] = useState("");

console.log(BigInt(nft.id.toString()));
const { writeAsync: transferNFT } = useScaffoldContractWrite({
contractName: "Challenge0",
functionName: "transfer_from",
Expand Down

0 comments on commit 7883f39

Please sign in to comment.