Skip to content

Commit acc7674

Browse files
committed
update
1 parent cc47b7b commit acc7674

File tree

1 file changed

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

1 file changed

+25
-11
lines changed

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

Lines changed: 25 additions & 11 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,35 +16,44 @@ interface SupplyCardsProps {
1116
}
1217

1318
export const SupplyCards: React.FC<SupplyCardsProps> = ({ contract }) => {
14-
const claimedSupplyQuery = useReadContract(totalSupply, {
19+
const nextTokenIdQuery = useReadContract(nextTokenIdToMint, {
1520
contract,
1621
});
17-
const totalSupplyQuery = useReadContract(nextTokenIdToMint, {
22+
23+
const totalSupplyQuery = 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+
() => (nextTokenIdQuery.data || 0n) - (startTokenIdQuery.data || 0n),
31+
[nextTokenIdQuery.data, startTokenIdQuery.data],
32+
);
33+
34+
const unclaimedSupply = useMemo(
35+
() => (realTotalSupply - (totalSupplyQuery?.data || 0n)).toString(),
36+
[realTotalSupply, totalSupplyQuery.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>
29-
<Skeleton isLoaded={totalSupplyQuery.isSuccess}>
30-
<StatNumber>{totalSupplyQuery?.data?.toString()}</StatNumber>
43+
<Skeleton isLoaded={nextTokenIdQuery.isSuccess}>
44+
<StatNumber>{realTotalSupply.toString()}</StatNumber>
3145
</Skeleton>
3246
</Card>
3347
<Card as={Stat}>
3448
<StatLabel mb={{ base: 1, md: 0 }}>Claimed Supply</StatLabel>
35-
<Skeleton isLoaded={claimedSupplyQuery.isSuccess}>
36-
<StatNumber>{claimedSupplyQuery?.data?.toString()}</StatNumber>
49+
<Skeleton isLoaded={totalSupplyQuery.isSuccess}>
50+
<StatNumber>{totalSupplyQuery?.data?.toString()}</StatNumber>
3751
</Skeleton>
3852
</Card>
3953
<Card as={Stat}>
4054
<StatLabel mb={{ base: 1, md: 0 }}>Unclaimed Supply</StatLabel>
4155
<Skeleton
42-
isLoaded={totalSupplyQuery.isSuccess && claimedSupplyQuery.isSuccess}
56+
isLoaded={totalSupplyQuery.isSuccess && nextTokenIdQuery.isSuccess}
4357
>
4458
<StatNumber>{unclaimedSupply}</StatNumber>
4559
</Skeleton>

0 commit comments

Comments
 (0)