Commit ed8aa082 authored by Jack Short's avatar Jack Short Committed by GitHub

chore: remove extra decimals on cards (#4757)

* chore: removing decimals

* only on cards

* slight fix

* updating across app
parent 53f4fb9e
...@@ -110,7 +110,7 @@ export const CollectionAsset = ({ ...@@ -110,7 +110,7 @@ export const CollectionAsset = ({
<Card.SecondaryRow> <Card.SecondaryRow>
<Card.SecondaryDetails> <Card.SecondaryDetails>
<Card.SecondaryInfo> <Card.SecondaryInfo>
{notForSale ? '' : `${formatWeiToDecimal(asset.currentEthPrice)} ETH`} {notForSale ? '' : `${formatWeiToDecimal(asset.currentEthPrice, true)} ETH`}
</Card.SecondaryInfo> </Card.SecondaryInfo>
{(asset.marketplace === Markets.NFTX || asset.marketplace === Markets.NFT20) && <Card.Pool />} {(asset.marketplace === Markets.NFTX || asset.marketplace === Markets.NFT20) && <Card.Pool />}
</Card.SecondaryDetails> </Card.SecondaryDetails>
......
...@@ -35,7 +35,7 @@ export const WithCommaCell = ({ value }: CellProps) => <span>{value.value ? putC ...@@ -35,7 +35,7 @@ export const WithCommaCell = ({ value }: CellProps) => <span>{value.value ? putC
export const EthCell = ({ value }: { value: number }) => ( export const EthCell = ({ value }: { value: number }) => (
<Row justifyContent="flex-end" color="textPrimary"> <Row justifyContent="flex-end" color="textPrimary">
{value ? <>{formatWeiToDecimal(value.toString())} ETH</> : '-'} {value ? <>{formatWeiToDecimal(value.toString(), true)} ETH</> : '-'}
</Row> </Row>
) )
...@@ -66,7 +66,7 @@ export const EthWithDayChange = ({ value }: CellProps) => ( ...@@ -66,7 +66,7 @@ export const EthWithDayChange = ({ value }: CellProps) => (
export const WeiWithDayChange = ({ value }: CellProps) => ( export const WeiWithDayChange = ({ value }: CellProps) => (
<Column gap="4"> <Column gap="4">
<Row justifyContent="flex-end" color="textPrimary"> <Row justifyContent="flex-end" color="textPrimary">
{value && value.value ? <>{formatWeiToDecimal(value.value.toString())} ETH</> : '-'} {value && value.value ? <>{formatWeiToDecimal(value.value.toString(), true)} ETH</> : '-'}
</Row> </Row>
{value.change ? ( {value.change ? (
<Box <Box
......
...@@ -41,7 +41,11 @@ export const numberToWei = (amount: number) => { ...@@ -41,7 +41,11 @@ export const numberToWei = (amount: number) => {
return parseEther(amount.toString()) 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 '-' if (!amount) return '-'
const amountInDecimals = parseFloat(amount.toString()) const amountInDecimals = parseFloat(amount.toString())
...@@ -49,16 +53,13 @@ export const ethNumberStandardFormatter = (amount: string | number | undefined, ...@@ -49,16 +53,13 @@ export const ethNumberStandardFormatter = (amount: string | number | undefined,
if (amountInDecimals < 0.0001) return `< ${conditionalDollarSign}0.00001` if (amountInDecimals < 0.0001) return `< ${conditionalDollarSign}0.00001`
if (amountInDecimals < 1) return `${conditionalDollarSign}${amountInDecimals.toFixed(3)}` if (amountInDecimals < 1) return `${conditionalDollarSign}${amountInDecimals.toFixed(3)}`
return ( const formattedPrice = (removeZeroes ? parseFloat(amountInDecimals.toFixed(2)) : amountInDecimals.toFixed(2))
conditionalDollarSign +
amountInDecimals
.toFixed(2)
.toString() .toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ',') .replace(/\B(?=(\d{3})+(?!\d))/g, ',')
) return conditionalDollarSign + formattedPrice
} }
export const formatWeiToDecimal = (amount: string) => { export const formatWeiToDecimal = (amount: string, removeZeroes = false) => {
if (!amount) return '-' if (!amount) return '-'
return ethNumberStandardFormatter(formatEther(amount)) return ethNumberStandardFormatter(formatEther(amount), false, removeZeroes)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment