From 8973174ad5499ea9d62e057e35eaeaf37fe68db8 Mon Sep 17 00:00:00 2001 From: MananTank Date: Fri, 11 Jul 2025 20:38:47 +0000 Subject: [PATCH] Dashboard: Fix erc20 asset page crash when number of tokens claimed is a fraction (#7597) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## 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}` ## 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. --- .../src/@/icons/brand-icons/DiscordIcon.tsx | 2 +- .../supply-claimed-progress.stories.tsx | 41 ++++++++++++++++--- .../_components/supply-claimed-progress.tsx | 24 +++++------ .../claim-tokens/claim-tokens-ui.tsx | 6 +-- .../buy-edition-drop.client.tsx | 9 +++- .../buy-nft-drop/buy-nft-drop-ui.client.tsx | 6 ++- 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/apps/dashboard/src/@/icons/brand-icons/DiscordIcon.tsx b/apps/dashboard/src/@/icons/brand-icons/DiscordIcon.tsx index 38f5403eb20..3de6f7e92cf 100644 --- a/apps/dashboard/src/@/icons/brand-icons/DiscordIcon.tsx +++ b/apps/dashboard/src/@/icons/brand-icons/DiscordIcon.tsx @@ -3,7 +3,7 @@ import type { SVGProps } from "react"; export function DiscordIcon(props: SVGProps) { return ( + + + + - + - + + + + + - + - + - + - + ); diff --git a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/_components/supply-claimed-progress.tsx b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/_components/supply-claimed-progress.tsx index 6ecc3eb7c71..c1a81bc96bf 100644 --- a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/_components/supply-claimed-progress.tsx +++ b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/_components/supply-claimed-progress.tsx @@ -3,16 +3,16 @@ import { Progress } from "@/components/ui/progress"; import { supplyFormatter } from "../nft/format"; export function SupplyClaimedProgress(props: { - claimedSupply: bigint; - totalSupply: bigint | "unlimited"; + claimedSupplyTokens: number; + totalSupplyTokens: number | "unlimited"; }) { // if total supply is unlimited - if (props.totalSupply === "unlimited") { + if (props.totalSupplyTokens === "unlimited") { return (

Claimed Supply - {supplyFormatter.format(props.claimedSupply)} /{" "} + {supplyFormatter.format(props.claimedSupplyTokens)} /{" "}

@@ -20,29 +20,29 @@ export function SupplyClaimedProgress(props: { } // if total supply is 0 - don't show anything - if (props.totalSupply === 0n) { + if (props.totalSupplyTokens === 0) { return null; } // multiply by 10k to have precision up to 2 decimal places in percentage value - const soldFractionTimes10KBigInt = - (props.claimedSupply * 10000n) / props.totalSupply; - const soldPercentage = Number(soldFractionTimes10KBigInt) / 100; + const soldPercentage = + (props.claimedSupplyTokens / props.totalSupplyTokens) * 100; + + const percentToShow = soldPercentage.toFixed(2); return (
Supply Claimed - {supplyFormatter.format(props.claimedSupply)} /{" "} - {supplyFormatter.format(props.totalSupply)} + {supplyFormatter.format(props.claimedSupplyTokens)} /{" "} + {supplyFormatter.format(props.totalSupplyTokens)}

- {soldPercentage === 0 && props.claimedSupply !== 0n && "~"} - {soldPercentage.toFixed(2)}% Sold + {percentToShow === "0.00" ? "~0.00%" : `${percentToShow}%`} Sold

); diff --git a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/claim-tokens/claim-tokens-ui.tsx b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/claim-tokens/claim-tokens-ui.tsx index 6e3c8784764..4db3e3c1b0f 100644 --- a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/claim-tokens/claim-tokens-ui.tsx +++ b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/claim-tokens/claim-tokens-ui.tsx @@ -325,13 +325,13 @@ export function TokenDropClaim(props: {
) : ( diff --git a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/buy-nft-drop/buy-nft-drop-ui.client.tsx b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/buy-nft-drop/buy-nft-drop-ui.client.tsx index 4150a45917d..b5aa723ad3c 100644 --- a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/buy-nft-drop/buy-nft-drop-ui.client.tsx +++ b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/nft/overview/buy-nft-drop/buy-nft-drop-ui.client.tsx @@ -231,8 +231,10 @@ export function BuyNFTDropUI(props: BuyNFTDropUIProps) { )}