Skip to content

Commit 8973174

Browse files
committed
Dashboard: Fix erc20 asset page crash when number of tokens claimed is a fraction (#7597)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on updating the `SupplyClaimedProgress` component to use `claimedSupplyTokens` and `totalSupplyTokens` as `number` types instead of `bigint`, along with minor adjustments in related components and UI elements. ### Detailed summary - Changed `enable-background` to `enableBackground` in `DiscordIcon.tsx`. - Updated `SupplyClaimedProgress` props from `claimedSupply` and `totalSupply` (bigint) to `claimedSupplyTokens` and `totalSupplyTokens` (number). - Adjusted calculations and conditions in `SupplyClaimedProgress` for new props. - Modified test cases in stories to reflect new prop types. - Updated UI elements to display supply values correctly based on the new number type. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Updated supply progress components and related usage to use number types instead of bigints, with new prop names for clarity. * Improved handling and display of "unlimited" supply scenarios in supply progress components. * Adjusted percentage calculation and formatting for claimed supply progress. * **Style** * Corrected SVG attribute naming in the Discord icon to ensure proper rendering. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c160e91 commit 8973174

File tree

6 files changed

+62
-26
lines changed

6 files changed

+62
-26
lines changed

apps/dashboard/src/@/icons/brand-icons/DiscordIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { SVGProps } from "react";
33
export function DiscordIcon(props: SVGProps<SVGSVGElement>) {
44
return (
55
<svg
6-
enable-background="new 0 0 100 100"
6+
enableBackground="new 0 0 100 100"
77
viewBox="0 0 100 100"
88
xmlns="http://www.w3.org/2000/svg"
99
{...props}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/_components/supply-claimed-progress.stories.tsx

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,57 @@ export const Variants: Story = {
1717
function StoryVariants() {
1818
return (
1919
<div className="container max-w-md space-y-10 py-10">
20+
<BadgeContainer label="5.5 / Unlimited Supply">
21+
<SupplyClaimedProgress
22+
claimedSupplyTokens={5.5}
23+
totalSupplyTokens="unlimited"
24+
/>
25+
</BadgeContainer>
26+
2027
<BadgeContainer label="10 / Unlimited Supply">
21-
<SupplyClaimedProgress claimedSupply={10n} totalSupply="unlimited" />
28+
<SupplyClaimedProgress
29+
claimedSupplyTokens={10}
30+
totalSupplyTokens="unlimited"
31+
/>
2232
</BadgeContainer>
2333

2434
<BadgeContainer label="500/1000 Supply">
25-
<SupplyClaimedProgress claimedSupply={500n} totalSupply={1000n} />
35+
<SupplyClaimedProgress
36+
claimedSupplyTokens={500}
37+
totalSupplyTokens={1000}
38+
/>
39+
</BadgeContainer>
40+
41+
<BadgeContainer label="123.45/1000 Supply">
42+
<SupplyClaimedProgress
43+
claimedSupplyTokens={123.45}
44+
totalSupplyTokens={1000}
45+
/>
2646
</BadgeContainer>
2747

2848
<BadgeContainer label="10/1M Supply">
29-
<SupplyClaimedProgress claimedSupply={10n} totalSupply={1000000n} />
49+
<SupplyClaimedProgress
50+
claimedSupplyTokens={10}
51+
totalSupplyTokens={1000000}
52+
/>
3053
</BadgeContainer>
3154

3255
<BadgeContainer label="0/1M Supply">
33-
<SupplyClaimedProgress claimedSupply={0n} totalSupply={1000000n} />
56+
<SupplyClaimedProgress
57+
claimedSupplyTokens={0}
58+
totalSupplyTokens={1000000}
59+
/>
3460
</BadgeContainer>
3561

3662
<BadgeContainer label="10/10 Supply">
37-
<SupplyClaimedProgress claimedSupply={10n} totalSupply={10n} />
63+
<SupplyClaimedProgress
64+
claimedSupplyTokens={10}
65+
totalSupplyTokens={10}
66+
/>
3867
</BadgeContainer>
3968

4069
<BadgeContainer label="0 Supply - don't show anything">
41-
<SupplyClaimedProgress claimedSupply={0n} totalSupply={0n} />
70+
<SupplyClaimedProgress claimedSupplyTokens={0} totalSupplyTokens={0} />
4271
</BadgeContainer>
4372
</div>
4473
);

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/_components/supply-claimed-progress.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,46 @@ import { Progress } from "@/components/ui/progress";
33
import { supplyFormatter } from "../nft/format";
44

55
export function SupplyClaimedProgress(props: {
6-
claimedSupply: bigint;
7-
totalSupply: bigint | "unlimited";
6+
claimedSupplyTokens: number;
7+
totalSupplyTokens: number | "unlimited";
88
}) {
99
// if total supply is unlimited
10-
if (props.totalSupply === "unlimited") {
10+
if (props.totalSupplyTokens === "unlimited") {
1111
return (
1212
<p className="flex items-center justify-between gap-2">
1313
<span className="font-medium text-sm">Claimed Supply </span>
1414
<span className="flex items-center gap-1 font-bold text-sm">
15-
{supplyFormatter.format(props.claimedSupply)} /{" "}
15+
{supplyFormatter.format(props.claimedSupplyTokens)} /{" "}
1616
<InfinityIcon aria-label="Unlimited" className="size-4" />
1717
</span>
1818
</p>
1919
);
2020
}
2121

2222
// if total supply is 0 - don't show anything
23-
if (props.totalSupply === 0n) {
23+
if (props.totalSupplyTokens === 0) {
2424
return null;
2525
}
2626

2727
// multiply by 10k to have precision up to 2 decimal places in percentage value
28-
const soldFractionTimes10KBigInt =
29-
(props.claimedSupply * 10000n) / props.totalSupply;
3028

31-
const soldPercentage = Number(soldFractionTimes10KBigInt) / 100;
29+
const soldPercentage =
30+
(props.claimedSupplyTokens / props.totalSupplyTokens) * 100;
31+
32+
const percentToShow = soldPercentage.toFixed(2);
3233

3334
return (
3435
<div className="space-y-2">
3536
<div className="flex items-center justify-between">
3637
<span className="font-medium text-sm">Supply Claimed</span>
3738
<span className="font-bold text-sm">
38-
{supplyFormatter.format(props.claimedSupply)} /{" "}
39-
{supplyFormatter.format(props.totalSupply)}
39+
{supplyFormatter.format(props.claimedSupplyTokens)} /{" "}
40+
{supplyFormatter.format(props.totalSupplyTokens)}
4041
</span>
4142
</div>
4243
<Progress className="h-2.5" value={soldPercentage} />
4344
<p className="font-medium text-muted-foreground text-xs">
44-
{soldPercentage === 0 && props.claimedSupply !== 0n && "~"}
45-
{soldPercentage.toFixed(2)}% Sold
45+
{percentToShow === "0.00" ? "~0.00%" : `${percentToShow}%`} Sold
4646
</p>
4747
</div>
4848
);

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/claim-tokens/claim-tokens-ui.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@ export function TokenDropClaim(props: {
325325
<div className="h-4" />
326326

327327
<SupplyClaimedProgress
328-
claimedSupply={BigInt(
328+
claimedSupplyTokens={Number(
329329
toTokens(props.claimCondition.supplyClaimed, props.decimals),
330330
)}
331-
totalSupply={
331+
totalSupplyTokens={
332332
props.claimCondition.maxClaimableSupply === maxUint256
333333
? "unlimited"
334-
: BigInt(
334+
: Number(
335335
toTokens(
336336
props.claimCondition.maxClaimableSupply,
337337
props.decimals,

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/buy-edition-drop/buy-edition-drop.client.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { ChainMetadata } from "thirdweb/chains";
1010
import { getApprovalForTransaction } from "thirdweb/extensions/erc20";
1111
import { claimTo } from "thirdweb/extensions/erc1155";
1212
import { useActiveAccount, useSendAndConfirmTransaction } from "thirdweb/react";
13+
import { maxUint256 } from "thirdweb/utils";
1314
import * as z from "zod";
1415
import {
1516
reportAssetBuyFailed,
@@ -225,8 +226,12 @@ export function BuyEditionDrop(props: BuyEditionDropProps) {
225226

226227
{claimCondition.data ? (
227228
<SupplyClaimedProgress
228-
claimedSupply={claimCondition.data.supplyClaimed}
229-
totalSupply={claimCondition.data.maxClaimableSupply}
229+
claimedSupplyTokens={Number(claimCondition.data.supplyClaimed)}
230+
totalSupplyTokens={
231+
claimCondition.data.maxClaimableSupply === maxUint256
232+
? "unlimited"
233+
: Number(claimCondition.data.maxClaimableSupply)
234+
}
230235
/>
231236
) : (
232237
<Skeleton className="h-[62px] w-full" />

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/buy-nft-drop/buy-nft-drop-ui.client.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ export function BuyNFTDropUI(props: BuyNFTDropUIProps) {
231231
)}
232232

233233
<SupplyClaimedProgress
234-
claimedSupply={BigInt(props.totalNFTs) - props.totalUnclaimedSupply}
235-
totalSupply={BigInt(props.totalNFTs)}
234+
claimedSupplyTokens={Number(
235+
BigInt(props.totalNFTs) - props.totalUnclaimedSupply,
236+
)}
237+
totalSupplyTokens={Number(props.totalNFTs)}
236238
/>
237239

238240
<div className="flex flex-col gap-1.5 rounded-lg bg-muted/50 p-3">

0 commit comments

Comments
 (0)