From 6030bf17c266feb35c3da36176076b76a575b0c5 Mon Sep 17 00:00:00 2001 From: kien-ngo Date: Tue, 5 Nov 2024 17:35:03 +0000 Subject: [PATCH] [Dashboard] Fix NFT supply info (#5309) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem solved Short description of the bug fixed or feature added --- ## PR-Codex overview This PR focuses on enhancing the `SupplyCards` component by updating how supply data is fetched and displayed, specifically by introducing the `startTokenId` and refining the calculation of unclaimed supply. ### Detailed summary - Added `startTokenId` to the imports from `thirdweb/extensions/erc721`. - Changed `claimedSupplyQuery` to `nextTokenIdQuery`. - Introduced `startTokenIdQuery` for calculating the real total supply. - Updated unclaimed supply calculation to use `realTotalSupply`. - Adjusted loading states and displayed values for total supply and unclaimed supply. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../nfts/components/supply-cards.tsx | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/supply-cards.tsx b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/supply-cards.tsx index 8c69caa4171..feb071fa39e 100644 --- a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/supply-cards.tsx +++ b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/supply-cards.tsx @@ -1,8 +1,13 @@ "use client"; import { Skeleton, Stat, StatLabel, StatNumber } from "@chakra-ui/react"; +import { useMemo } from "react"; import type { ThirdwebContract } from "thirdweb"; -import { nextTokenIdToMint, totalSupply } from "thirdweb/extensions/erc721"; +import { + nextTokenIdToMint, + startTokenId, + totalSupply, +} from "thirdweb/extensions/erc721"; import { useReadContract } from "thirdweb/react"; import { Card } from "tw-components"; @@ -11,35 +16,44 @@ interface SupplyCardsProps { } export const SupplyCards: React.FC = ({ contract }) => { - const claimedSupplyQuery = useReadContract(totalSupply, { + const nextTokenIdQuery = useReadContract(nextTokenIdToMint, { contract, }); - const totalSupplyQuery = useReadContract(nextTokenIdToMint, { + + const totalSupplyQuery = useReadContract(totalSupply, { contract, }); - const unclaimedSupply = ( - (totalSupplyQuery?.data || 0n) - (claimedSupplyQuery?.data || 0n) - ).toString(); + const startTokenIdQuery = useReadContract(startTokenId, { contract }); + + const realTotalSupply = useMemo( + () => (nextTokenIdQuery.data || 0n) - (startTokenIdQuery.data || 0n), + [nextTokenIdQuery.data, startTokenIdQuery.data], + ); + + const unclaimedSupply = useMemo( + () => (realTotalSupply - (totalSupplyQuery?.data || 0n)).toString(), + [realTotalSupply, totalSupplyQuery.data], + ); return (
Total Supply - - {totalSupplyQuery?.data?.toString()} + + {realTotalSupply.toString()} Claimed Supply - - {claimedSupplyQuery?.data?.toString()} + + {totalSupplyQuery?.data?.toString()} Unclaimed Supply {unclaimedSupply}