Skip to content

Commit 2d6b751

Browse files
committed
update
1 parent cc47b7b commit 2d6b751

File tree

1 file changed

+21
-7
lines changed
  • apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components

1 file changed

+21
-7
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/supply-cards.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
"use client";
22

33
import { Skeleton, Stat, StatLabel, StatNumber } from "@chakra-ui/react";
4+
import { useMemo } from "react";
45
import type { ThirdwebContract } from "thirdweb";
5-
import { nextTokenIdToMint, totalSupply } from "thirdweb/extensions/erc721";
6+
import {
7+
nextTokenIdToMint,
8+
startTokenId,
9+
totalSupply,
10+
} from "thirdweb/extensions/erc721";
611
import { useReadContract } from "thirdweb/react";
712
import { Card } from "tw-components";
813

@@ -11,23 +16,32 @@ interface SupplyCardsProps {
1116
}
1217

1318
export const SupplyCards: React.FC<SupplyCardsProps> = ({ contract }) => {
14-
const claimedSupplyQuery = useReadContract(totalSupply, {
19+
const totalSupplyQuery = useReadContract(nextTokenIdToMint, {
1520
contract,
1621
});
17-
const totalSupplyQuery = useReadContract(nextTokenIdToMint, {
22+
23+
const claimedSupplyQuery = useReadContract(totalSupply, {
1824
contract,
1925
});
2026

21-
const unclaimedSupply = (
22-
(totalSupplyQuery?.data || 0n) - (claimedSupplyQuery?.data || 0n)
23-
).toString();
27+
const startTokenIdQuery = useReadContract(startTokenId, { contract });
28+
29+
const realTotalSupply = useMemo(
30+
() => (totalSupplyQuery.data || 0n) - (startTokenIdQuery.data || 0n),
31+
[totalSupplyQuery.data, startTokenIdQuery.data],
32+
);
33+
34+
const unclaimedSupply = useMemo(
35+
() => (realTotalSupply - (claimedSupplyQuery?.data || 0n)).toString(),
36+
[realTotalSupply, claimedSupplyQuery.data],
37+
);
2438

2539
return (
2640
<div className="flex flex-col gap-3 md:flex-row md:gap-6">
2741
<Card as={Stat}>
2842
<StatLabel mb={{ base: 1, md: 0 }}>Total Supply</StatLabel>
2943
<Skeleton isLoaded={totalSupplyQuery.isSuccess}>
30-
<StatNumber>{totalSupplyQuery?.data?.toString()}</StatNumber>
44+
<StatNumber>{realTotalSupply.toString()}</StatNumber>
3145
</Skeleton>
3246
</Card>
3347
<Card as={Stat}>

0 commit comments

Comments
 (0)