From ed8aa08255cd4041ee642e5ee28f0abeea526fa4 Mon Sep 17 00:00:00 2001 From: Jack Short Date: Fri, 30 Sep 2022 11:04:16 -0400 Subject: [PATCH] chore: remove extra decimals on cards (#4757) * chore: removing decimals * only on cards * slight fix * updating across app --- .../components/collection/CollectionAsset.tsx | 2 +- src/nft/components/explore/Cells/Cells.tsx | 4 ++-- src/nft/utils/currency.ts | 21 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/nft/components/collection/CollectionAsset.tsx b/src/nft/components/collection/CollectionAsset.tsx index 997b64ae8e..4a4f7416b2 100644 --- a/src/nft/components/collection/CollectionAsset.tsx +++ b/src/nft/components/collection/CollectionAsset.tsx @@ -110,7 +110,7 @@ export const CollectionAsset = ({ - {notForSale ? '' : `${formatWeiToDecimal(asset.currentEthPrice)} ETH`} + {notForSale ? '' : `${formatWeiToDecimal(asset.currentEthPrice, true)} ETH`} {(asset.marketplace === Markets.NFTX || asset.marketplace === Markets.NFT20) && } diff --git a/src/nft/components/explore/Cells/Cells.tsx b/src/nft/components/explore/Cells/Cells.tsx index 28efd34958..b8452f4fd2 100644 --- a/src/nft/components/explore/Cells/Cells.tsx +++ b/src/nft/components/explore/Cells/Cells.tsx @@ -35,7 +35,7 @@ export const WithCommaCell = ({ value }: CellProps) => {value.value ? putC export const EthCell = ({ value }: { value: number }) => ( - {value ? <>{formatWeiToDecimal(value.toString())} ETH : '-'} + {value ? <>{formatWeiToDecimal(value.toString(), true)} ETH : '-'} ) @@ -66,7 +66,7 @@ export const EthWithDayChange = ({ value }: CellProps) => ( export const WeiWithDayChange = ({ value }: CellProps) => ( - {value && value.value ? <>{formatWeiToDecimal(value.value.toString())} ETH : '-'} + {value && value.value ? <>{formatWeiToDecimal(value.value.toString(), true)} ETH : '-'} {value.change ? ( { return parseEther(amount.toString()) } -export const ethNumberStandardFormatter = (amount: string | number | undefined, includeDollarSign = false): string => { +export const ethNumberStandardFormatter = ( + amount: string | number | undefined, + includeDollarSign = false, + removeZeroes = false +): string => { if (!amount) return '-' const amountInDecimals = parseFloat(amount.toString()) @@ -49,16 +53,13 @@ export const ethNumberStandardFormatter = (amount: string | number | undefined, if (amountInDecimals < 0.0001) return `< ${conditionalDollarSign}0.00001` if (amountInDecimals < 1) return `${conditionalDollarSign}${amountInDecimals.toFixed(3)}` - return ( - conditionalDollarSign + - amountInDecimals - .toFixed(2) - .toString() - .replace(/\B(?=(\d{3})+(?!\d))/g, ',') - ) + const formattedPrice = (removeZeroes ? parseFloat(amountInDecimals.toFixed(2)) : amountInDecimals.toFixed(2)) + .toString() + .replace(/\B(?=(\d{3})+(?!\d))/g, ',') + return conditionalDollarSign + formattedPrice } -export const formatWeiToDecimal = (amount: string) => { +export const formatWeiToDecimal = (amount: string, removeZeroes = false) => { if (!amount) return '-' - return ethNumberStandardFormatter(formatEther(amount)) + return ethNumberStandardFormatter(formatEther(amount), false, removeZeroes) }