diff --git a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/components/airdrop-tab.tsx b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/components/airdrop-tab.tsx index 52ed99a4c1e..d9a86ef36b9 100644 --- a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/components/airdrop-tab.tsx +++ b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/components/airdrop-tab.tsx @@ -129,7 +129,7 @@ const AirdropTab: React.FC = ({ contract, tokenId }) => { - Aidrop NFTs + Airdrop NFTs >; /** * If useUpdateMetadata (NFT Drop, Edition Drop) -> use `updateMetadata` * else (NFT Collection, Edition) -> use `setTokenURI` @@ -62,6 +58,7 @@ export const UpdateNftMetadata: React.FC = ({ contract, nft, useUpdateMetadata, + setOpen, }) => { const trackEvent = useTrack(); const address = useActiveAccount()?.address; @@ -101,14 +98,6 @@ export const UpdateNftMetadata: React.FC = ({ values: transformedQueryData, }); - const modalContext = useModalContext(); - - const { onSuccess, onError } = useTxNotifications( - "NFT Metadata updated successfully", - "Metadata update failed", - contract, - ); - const setFile = (file: File) => { if (file.type.includes("image")) { // image files @@ -173,237 +162,234 @@ export const UpdateNftMetadata: React.FC = ({ const showCoverImageUpload = watch("animation_url") instanceof File || watch("external_url") instanceof File; - const { mutate, isPending } = useSendAndConfirmTransaction(); + const sendAndConfirmTx = useSendAndConfirmTransaction(); return ( - <> - - Update NFT Metadata - - -
{ - if (!address) { - onError("Please connect your wallet to update metadata."); - return; - } - trackEvent({ - category: "nft", - action: "update-metadata", - label: "attempt", - }); + { + if (!address) { + toast.error("Please connect your wallet to update metadata."); + return; + } + trackEvent({ + category: "nft", + action: "update-metadata", + label: "attempt", + }); - const newMetadata = parseAttributes({ - ...data, - image: data.image || data.customImage || nft.metadata.image, - animation_url: - data.animation_url || - data.customAnimationUrl || - nft.metadata.animation_url, - }); + try { + const newMetadata = parseAttributes({ + ...data, + image: data.image || data.customImage || nft.metadata.image, + animation_url: + data.animation_url || + data.customAnimationUrl || + nft.metadata.animation_url, + }); - const transaction = useUpdateMetadata - ? // For Drop contracts, we need to call the `updateBatchBaseURI` method - nft.type === "ERC721" - ? updateMetadata721({ - contract, - targetTokenId: BigInt(nft.id), - newMetadata, - }) - : updateMetadata1155({ - contract, - targetTokenId: BigInt(nft.id), - newMetadata, - }) - : // For Collection contracts, we need to call the `setTokenURI` method - nft.type === "ERC721" - ? updateTokenURI721({ - contract, - tokenId: BigInt(nft.id), - newMetadata, - }) - : updateTokenURI1155({ - contract, - tokenId: BigInt(nft.id), - newMetadata, - }); - mutate(transaction, { - onSuccess: () => { - trackEvent({ - category: "nft", - action: "update-metadata", - label: "success", - }); - onSuccess(); - modalContext.onClose(); - }, - // biome-ignore lint/suspicious/noExplicitAny: FIXME - onError: (error: any) => { - trackEvent({ - category: "nft", - action: "update-metadata", - label: "error", - error, + const transaction = useUpdateMetadata + ? // For Drop contracts, we need to call the `updateBatchBaseURI` method + nft.type === "ERC721" + ? updateMetadata721({ + contract, + targetTokenId: BigInt(nft.id), + newMetadata, + }) + : updateMetadata1155({ + contract, + targetTokenId: BigInt(nft.id), + newMetadata, + }) + : // For Collection contracts, we need to call the `setTokenURI` method + nft.type === "ERC721" + ? updateTokenURI721({ + contract, + tokenId: BigInt(nft.id), + newMetadata, + }) + : updateTokenURI1155({ + contract, + tokenId: BigInt(nft.id), + newMetadata, }); - onError(error); - }, - }); - })} - > -
- Metadata - -
- - Name - - {errors?.name?.message} - - - Media - {nft?.metadata && !mediaFileUrl && ( -
- -
+ const promise = sendAndConfirmTx.mutateAsync(transaction, { + onSuccess: () => { + trackEvent({ + category: "nft", + action: "update-metadata", + label: "success", + }); + setOpen(false); + }, + // biome-ignore lint/suspicious/noExplicitAny: FIXME + onError: (error: any) => { + trackEvent({ + category: "nft", + action: "update-metadata", + label: "error", + error, + }); + }, + }); + + toast.promise(promise, { + loading: "Updating NFT metadata", + error: "Failed to update NFT metadata", + success: "NFT metadata updated successfully", + }); + } catch (err) { + console.error(err); + toast.error("Failed to update NFT metadata"); + } + })} + > +
+ Metadata + +
+ + Name + + {errors?.name?.message} + + + Media +
+ {nft?.metadata && !mediaFileUrl && ( + + )} + +
+ + You can upload image, audio, video, html, text, pdf, and 3d model + files here. + + + {mediaFileError?.message as unknown as string} + +
+ {showCoverImageUpload && ( + + Cover Image + setValue("image", file)} + className="rounded border border-border transition-all" + /> + + You can optionally upload an image as the cover of your NFT. + + + {errors?.image?.message as unknown as string} + + + )} + + Description +