diff --git a/src/components/EarningAreaChart/TooltipContent.tsx b/src/components/EarningAreaChart/TooltipContent.tsx index 3e64e42e4c..f3367de4f2 100644 --- a/src/components/EarningAreaChart/TooltipContent.tsx +++ b/src/components/EarningAreaChart/TooltipContent.tsx @@ -79,7 +79,7 @@ const Tokens: React.FC = ({ tokens }) => { lineHeight: '14px', }} > - {formatDisplayNumber({ value: token.amount })} + {formatDisplayNumber(token.amount, { significantDigits: 6 })} ) @@ -153,7 +153,8 @@ const TooltipContent: React.FC = ({ dataEntry, setHoverValue }) => { whiteSpace: 'nowrap', }} > - My Total Earnings: {formatDisplayNumber({ value: dataEntry.totalValue, style: 'currency' })} + My Total Earnings:{' '} + {formatDisplayNumber(dataEntry.totalValue, { style: 'currency', significantDigits: 6 })} = ({ dataEntry, setHoverValue }) => { whiteSpace: 'nowrap', }} > - Pool Fees: {formatDisplayNumber({ value: dataEntry.poolFeesValue, style: 'currency' })} + Pool Fees:{' '} + {formatDisplayNumber(dataEntry.poolFeesValue, { style: 'currency', significantDigits: 6 })} = ({ dataEntry, setHoverValue }) => { whiteSpace: 'nowrap', }} > - Farm Rewards: {formatDisplayNumber({ value: dataEntry.farmRewardsValue, style: 'currency' })} + Farm Rewards:{' '} + {formatDisplayNumber(dataEntry.farmRewardsValue, { style: 'currency', significantDigits: 6 })} { fill={theme.subText} textAnchor="middle" > - {formatDisplayNumber({ value, style: 'currency', fractionDigits: 3 })} + {formatDisplayNumber(value, { style: 'currency', fractionDigits: 3 })} )} @@ -83,7 +83,7 @@ const EarningAreaChart: React.FC = ({ data, setHoverValue = EMPTY_FUNCTIO tickLine={false} stroke={theme.subText} tickFormatter={(value: any, _index: number) => - formatDisplayNumber({ value, style: 'currency', fractionDigits: 2 }) + formatDisplayNumber(value, { style: 'currency', fractionDigits: 2 }) } width={54} /> diff --git a/src/components/EarningPieChart/index.tsx b/src/components/EarningPieChart/index.tsx index 5a1d99e8ad..26dca83f20 100644 --- a/src/components/EarningPieChart/index.tsx +++ b/src/components/EarningPieChart/index.tsx @@ -145,8 +145,8 @@ const Legend: React.FC = ({ whiteSpace: 'nowrap', }} > - {formatDisplayNumber({ value, style: 'currency', fractionDigits: 2 })} ( - {formatDisplayNumber({ value: percent / 100, style: 'percent', fractionDigits: 3 })}) + {formatDisplayNumber(value, { style: 'currency', fractionDigits: 2 })} ( + {formatDisplayNumber(percent / 100, { style: 'percent', fractionDigits: 3 })}) diff --git a/src/components/Header/web3/SelectNetwork.tsx b/src/components/Header/web3/SelectNetwork.tsx index 6af4257e3d..5cb6b18179 100644 --- a/src/components/Header/web3/SelectNetwork.tsx +++ b/src/components/Header/web3/SelectNetwork.tsx @@ -75,7 +75,7 @@ function SelectNetwork(): JSX.Element | null { const userEthBalance = useNativeBalance() const labelContent = useMemo(() => { if (!userEthBalance) return networkInfo.name - const balanceFixedStr = formatDisplayNumber({ value: userEthBalance, significantDigits: 6 }) + const balanceFixedStr = formatDisplayNumber(userEthBalance, { significantDigits: 6 }) return `${balanceFixedStr} ${NativeCurrencies[chainId].symbol}` }, [userEthBalance, chainId, networkInfo]) const walletSupportsChain = useWalletSupportedChains() diff --git a/src/components/ProAmm/ProAmmPriceRangeConfirm.tsx b/src/components/ProAmm/ProAmmPriceRangeConfirm.tsx index e83dace7c8..c1a48aadcb 100644 --- a/src/components/ProAmm/ProAmmPriceRangeConfirm.tsx +++ b/src/components/ProAmm/ProAmmPriceRangeConfirm.tsx @@ -80,8 +80,7 @@ export default function ProAmmPriceRangeConfirm({ - 1 {baseCurrency.symbol} = {formatDisplayNumber({ value: price, significantDigits: 6 })}{' '} - {quoteCurrency.symbol} + 1 {baseCurrency.symbol} = {formatDisplayNumber(price, { significantDigits: 6 })} {quoteCurrency.symbol} diff --git a/src/components/SwapForm/TradeSummary.tsx b/src/components/SwapForm/TradeSummary.tsx index ee3dbc7cf4..6bbc3825e8 100644 --- a/src/components/SwapForm/TradeSummary.tsx +++ b/src/components/SwapForm/TradeSummary.tsx @@ -70,8 +70,7 @@ type TooltipTextOfSwapFeeProps = { feeAmountText: string } export const TooltipTextOfSwapFee: React.FC = ({ feeBips, feeAmountText }) => { - const feePercent = formatDisplayNumber({ - value: Number(feeBips) / Number(BIPS_BASE.toString()), + const feePercent = formatDisplayNumber(Number(feeBips) / Number(BIPS_BASE.toString()), { style: 'percent', fractionDigits: 2, }) diff --git a/src/components/YieldPools/FarmingPoolAPRCell.tsx b/src/components/YieldPools/FarmingPoolAPRCell.tsx index 9ffc678f61..83c1d376a6 100644 --- a/src/components/YieldPools/FarmingPoolAPRCell.tsx +++ b/src/components/YieldPools/FarmingPoolAPRCell.tsx @@ -44,7 +44,7 @@ export const APRTooltipContent = ({ Total APR:{' '} - {formatDisplayNumber({ value: (poolAPR + maxFarmAPR) / 100, style: 'percent', fractionDigits: 2 })} + {formatDisplayNumber((poolAPR + maxFarmAPR) / 100, { style: 'percent', fractionDigits: 2 })} Pool APR:{' '} - {formatDisplayNumber({ value: poolAPR / 100, style: 'percent', fractionDigits: 2 })} + {formatDisplayNumber(poolAPR / 100, { style: 'percent', fractionDigits: 2 })} Farm APR:{' '} - {formatDisplayNumber({ value: farmAPR / 100, style: 'percent', fractionDigits: 2 })} + {formatDisplayNumber(farmAPR / 100, { style: 'percent', fractionDigits: 2 })} Farm APR:{' '} - {formatDisplayNumber({ value: farmV2APR / 100, style: 'percent', fractionDigits: 2 })} + {formatDisplayNumber(farmV2APR / 100, { style: 'percent', fractionDigits: 2 })} = ({ text={} > - {formatDisplayNumber({ value: (poolAPR + maxFarmAPR) / 100, style: 'percent', fractionDigits: 2 })} + {formatDisplayNumber((poolAPR + maxFarmAPR) / 100, { style: 'percent', fractionDigits: 2 })} @@ -218,9 +218,7 @@ export const ClassicFarmingPoolAPRCell = ({ poolAPR, farm }: { poolAPR: number; gap: '4px', }} > - - {formatDisplayNumber({ value: (poolAPR + farmAPR) / 100, style: 'percent', fractionDigits: 2 })} - + {formatDisplayNumber((poolAPR + farmAPR) / 100, { style: 'percent', fractionDigits: 2 })} }> diff --git a/src/components/swapv2/TradePrice.tsx b/src/components/swapv2/TradePrice.tsx index 6555e20fb8..be8b493881 100644 --- a/src/components/swapv2/TradePrice.tsx +++ b/src/components/swapv2/TradePrice.tsx @@ -24,7 +24,7 @@ export default function TradePrice({ price, label, icon, style = {}, color }: Tr const [showInverted, setShowInverted] = useState(false) let formattedPrice try { - formattedPrice = formatDisplayNumber({ value: showInverted ? price?.invert() : price, significantDigits: 7 }) + formattedPrice = formatDisplayNumber(showInverted ? price?.invert() : price, { significantDigits: 7 }) } catch (error) {} const show = Boolean(price?.baseCurrency && price?.quoteCurrency && formattedPrice) diff --git a/src/pages/AddLiquidityV2/components/NewPoolNote.tsx b/src/pages/AddLiquidityV2/components/NewPoolNote.tsx index 766e228329..bf1bc4bc85 100644 --- a/src/pages/AddLiquidityV2/components/NewPoolNote.tsx +++ b/src/pages/AddLiquidityV2/components/NewPoolNote.tsx @@ -43,12 +43,10 @@ function NewPoolNote({ maxCharacters={24} text={ !invertMarketPrice - ? `1 ${baseCurrency?.symbol} = ${formatDisplayNumber({ - value: marketPrice, + ? `1 ${baseCurrency?.symbol} = ${formatDisplayNumber(marketPrice, { significantDigits: 6, })} ${quoteCurrency?.symbol}` - : `1 ${quoteCurrency?.symbol} = ${formatDisplayNumber({ - value: 1 / marketPrice, + : `1 ${quoteCurrency?.symbol} = ${formatDisplayNumber(1 / marketPrice, { significantDigits: 6, })} ${baseCurrency?.symbol}` } diff --git a/src/pages/AddLiquidityV2/index.tsx b/src/pages/AddLiquidityV2/index.tsx index 70e48216ab..6b6de01c6f 100644 --- a/src/pages/AddLiquidityV2/index.tsx +++ b/src/pages/AddLiquidityV2/index.tsx @@ -806,11 +806,11 @@ export default function AddLiquidity() { Note: A very small amount of your liquidity about{' '} - {formatDisplayNumber({ value: amountUnlockUSD, style: 'currency', significantDigits: 6 })}{' '} + {formatDisplayNumber(amountUnlockUSD, { style: 'currency', significantDigits: 6 })}{' '} - ({formatDisplayNumber({ value: amountUnlocks[Field.CURRENCY_A], significantDigits: 6 })}{' '} + ({formatDisplayNumber(amountUnlocks[Field.CURRENCY_A], { significantDigits: 6 })}{' '} {amountUnlocks[Field.CURRENCY_A].currency.symbol},{' '} - {formatDisplayNumber({ value: amountUnlocks[Field.CURRENCY_B], significantDigits: 6 })}{' '} + {formatDisplayNumber(amountUnlocks[Field.CURRENCY_B], { significantDigits: 6 })}{' '} {amountUnlocks[Field.CURRENCY_B].currency.symbol}) {' '} will be used to first initialize the pool. Read more{' '} @@ -830,10 +830,9 @@ export default function AddLiquidity() { {noLiquidity ? ( The pool’s current price of 1 {baseCurrency.symbol} ={' '} - {formatDisplayNumber({ value: invertPrice ? price.invert() : price, significantDigits: 4 })}{' '} + {formatDisplayNumber(invertPrice ? price.invert() : price, { significantDigits: 4 })}{' '} {quoteCurrency.symbol} deviates from the market price (1 {baseCurrency.symbol} ={' '} - {formatDisplayNumber({ - value: usdPrices[tokenA.wrapped.address] / usdPrices[tokenB.wrapped.address], + {formatDisplayNumber(usdPrices[tokenA.wrapped.address] / usdPrices[tokenB.wrapped.address], { significantDigits: 4, })}{' '} {quoteCurrency.symbol}). You might have high impermanent loss after the pool is created @@ -841,10 +840,9 @@ export default function AddLiquidity() { ) : ( The pool’s current price of 1 {baseCurrency.symbol} ={' '} - {formatDisplayNumber({ value: invertPrice ? price.invert() : price, significantDigits: 4 })}{' '} + {formatDisplayNumber(invertPrice ? price.invert() : price, { significantDigits: 4 })}{' '} {quoteCurrency.symbol} deviates from the market price (1 {baseCurrency.symbol} ={' '} - {formatDisplayNumber({ - value: usdPrices[tokenA.wrapped.address] / usdPrices[tokenB.wrapped.address], + {formatDisplayNumber(usdPrices[tokenA.wrapped.address] / usdPrices[tokenB.wrapped.address], { significantDigits: 4, })}{' '} {quoteCurrency.symbol}). You might have high impermanent loss after you add liquidity to this pool @@ -1102,8 +1100,7 @@ export default function AddLiquidity() { @@ -1546,10 +1543,12 @@ export default function AddLiquidity() { diff --git a/src/pages/GrantProgram/SingleProgram/LeaderBoardSection/index.tsx b/src/pages/GrantProgram/SingleProgram/LeaderBoardSection/index.tsx index 2dbaf5aeac..a12f8ea50b 100644 --- a/src/pages/GrantProgram/SingleProgram/LeaderBoardSection/index.tsx +++ b/src/pages/GrantProgram/SingleProgram/LeaderBoardSection/index.tsx @@ -42,7 +42,7 @@ const rankByConfigs: RankByConfig[] = [ }, { extracter: (p: ProjectRanking) => { - return formatDisplayNumber({ value: p.totalVolume, style: 'currency', significantDigits: 10, fractionDigits: 0 }) + return formatDisplayNumber(p.totalVolume, { style: 'currency', significantDigits: 10, fractionDigits: 0 }) }, param: 'total_volume', title: t`Trading Volume`, diff --git a/src/pages/GrantProgram/SingleProgram/Stats.tsx b/src/pages/GrantProgram/SingleProgram/Stats.tsx index cd9c520fd7..5a1d28b5d6 100644 --- a/src/pages/GrantProgram/SingleProgram/Stats.tsx +++ b/src/pages/GrantProgram/SingleProgram/Stats.tsx @@ -124,9 +124,7 @@ const Stats: React.FC = ({ participants, trades, volume }) => { } value={ - volume - ? formatDisplayNumber({ value: volume, style: 'currency', fractionDigits: 2, significantDigits: 6 }) - : volume + volume ? formatDisplayNumber(volume, { style: 'currency', fractionDigits: 2, significantDigits: 6 }) : volume } title="Total Trading Volume" /> diff --git a/src/pages/MyEarnings/ClassicPools/SinglePool/Position.tsx b/src/pages/MyEarnings/ClassicPools/SinglePool/Position.tsx index e2b9dcf2a0..103b399e42 100644 --- a/src/pages/MyEarnings/ClassicPools/SinglePool/Position.tsx +++ b/src/pages/MyEarnings/ClassicPools/SinglePool/Position.tsx @@ -59,13 +59,14 @@ const Position: React.FC = ({ poolEarning, chainId }) => { const myLiquidityBalance = poolEarning.liquidityTokenBalanceIncludingStake !== '0' && poolEarning.pool.totalSupply !== '0' - ? formatDisplayNumber({ - value: - (+poolEarning.liquidityTokenBalanceIncludingStake * +poolEarning.pool.reserveUSD) / + ? formatDisplayNumber( + (+poolEarning.liquidityTokenBalanceIncludingStake * +poolEarning.pool.reserveUSD) / +poolEarning.pool.totalSupply, - style: 'currency', - significantDigits: 6, - }) + { + style: 'currency', + significantDigits: 6, + }, + ) : '--' const myShareOfPool = +poolEarning.liquidityTokenBalanceIncludingStake / +poolEarning.pool.totalSupply @@ -98,11 +99,13 @@ const Position: React.FC = ({ poolEarning, chainId }) => { ) const liquidityStaked = +poolEarning.liquidityTokenBalanceIncludingStake - +poolEarning.liquidityTokenBalance - const myStakedBalance = formatDisplayNumber({ - value: (liquidityStaked * +poolEarning.pool.reserveUSD) / +poolEarning.pool.totalSupply, - style: 'currency', - significantDigits: 6, - }) + const myStakedBalance = formatDisplayNumber( + (liquidityStaked * +poolEarning.pool.reserveUSD) / +poolEarning.pool.totalSupply, + { + style: 'currency', + significantDigits: 6, + }, + ) const stakedShare = liquidityStaked / +poolEarning.pool.totalSupply @@ -158,15 +161,13 @@ const Position: React.FC = ({ poolEarning, chainId }) => { - {formatDisplayNumber({ value: pooledToken0, significantDigits: 6 })}{' '} - {unwrappedToken(token0).symbol} + {formatDisplayNumber(pooledToken0, { significantDigits: 6 })} {unwrappedToken(token0).symbol} - {formatDisplayNumber({ value: pooledToken1, significantDigits: 6 })}{' '} - {unwrappedToken(token1).symbol} + {formatDisplayNumber(pooledToken1, { significantDigits: 6 })} {unwrappedToken(token1).symbol} @@ -188,15 +189,13 @@ const Position: React.FC = ({ poolEarning, chainId }) => { - {formatDisplayNumber({ value: stakedToken0, significantDigits: 6 })}{' '} - {unwrappedToken(token0).symbol} + {formatDisplayNumber(stakedToken0, { significantDigits: 6 })} {unwrappedToken(token0).symbol} - {formatDisplayNumber({ value: stakedToken1, significantDigits: 6 })}{' '} - {unwrappedToken(token1).symbol} + {formatDisplayNumber(stakedToken1, { significantDigits: 6 })} {unwrappedToken(token1).symbol} @@ -208,18 +207,15 @@ const Position: React.FC = ({ poolEarning, chainId }) => { - + ) diff --git a/src/pages/MyEarnings/ClassicPools/SinglePool/index.tsx b/src/pages/MyEarnings/ClassicPools/SinglePool/index.tsx index 6f2335d46c..3047e1709f 100644 --- a/src/pages/MyEarnings/ClassicPools/SinglePool/index.tsx +++ b/src/pages/MyEarnings/ClassicPools/SinglePool/index.tsx @@ -126,13 +126,14 @@ const SinglePool: React.FC = ({ poolEarning, chainId }) => { ) const myLiquidityBalance = poolEarning.liquidityTokenBalanceIncludingStake !== '0' && poolEarning.pool.totalSupply !== '0' - ? formatDisplayNumber({ - value: - (+poolEarning.liquidityTokenBalanceIncludingStake * +poolEarning.pool.reserveUSD) / + ? formatDisplayNumber( + (+poolEarning.liquidityTokenBalanceIncludingStake * +poolEarning.pool.reserveUSD) / +poolEarning.pool.totalSupply, - style: 'currency', - significantDigits: 4, - }) + { + style: 'currency', + significantDigits: 4, + }, + ) : '--' const here = ( @@ -267,8 +268,7 @@ const SinglePool: React.FC = ({ poolEarning, chainId }) => { = ({ poolEarning, chainId }) => { value={ - {formatDisplayNumber({ - value: (+poolEarning.pool.apr + +poolEarning.pool.farmApr) / 100, + {formatDisplayNumber((+poolEarning.pool.apr + +poolEarning.pool.farmApr) / 100, { style: 'percent', fractionDigits: 2, })} @@ -310,16 +309,17 @@ const SinglePool: React.FC = ({ poolEarning, chainId }) => { /> = ({ poolEarning, chainId }) => { @@ -475,21 +475,19 @@ const SinglePool: React.FC = ({ poolEarning, chainId }) => {
- {formatDisplayNumber({ - value: ampLiquidity, + {formatDisplayNumber(ampLiquidity, { style: 'currency', significantDigits: 7, })} - {formatDisplayNumber({ value: poolEarning.pool.reserveUSD, style: 'currency', significantDigits: 7 })} + {formatDisplayNumber(poolEarning.pool.reserveUSD, { style: 'currency', significantDigits: 7 })}
- {formatDisplayNumber({ - value: (+poolEarning.pool.apr + +poolEarning.pool.farmApr) / 100, + {formatDisplayNumber((+poolEarning.pool.apr + +poolEarning.pool.farmApr) / 100, { style: 'percent', fractionDigits: 2, })} @@ -507,21 +505,19 @@ const SinglePool: React.FC = ({ poolEarning, chainId }) => { - {formatDisplayNumber({ - value: Number(poolEarning.pool.volumeUsd) - Number(poolEarning.pool.volumeUsdOneDayAgo), + {formatDisplayNumber(Number(poolEarning.pool.volumeUsd) - Number(poolEarning.pool.volumeUsdOneDayAgo), { style: 'currency', significantDigits: 4, })} - {formatDisplayNumber({ - value: Number(poolEarning.pool.feeUSD) - Number(poolEarning.pool.feesUsdOneDayAgo), + {formatDisplayNumber(Number(poolEarning.pool.feeUSD) - Number(poolEarning.pool.feesUsdOneDayAgo), { style: 'currency', significantDigits: 4, })} {myLiquidityBalance} - {formatDisplayNumber({ value: poolEarningToday, style: 'currency', significantDigits: 4 })} + {formatDisplayNumber(poolEarningToday, { style: 'currency', significantDigits: 4 })} = ({ isLoading, data, className, h ? tokens[item.chainId]?.[item.address]?.symbol || '' : item.symbol, }))} - totalValue={formatDisplayNumber({ value: data.totalValue, style: 'currency', significantDigits: 3 })} + totalValue={formatDisplayNumber(data.totalValue, { style: 'currency', significantDigits: 3 })} /> )} diff --git a/src/pages/MyEarnings/ElasticPools/SinglePool/index.tsx b/src/pages/MyEarnings/ElasticPools/SinglePool/index.tsx index bfa4293e2c..c05561cdc3 100644 --- a/src/pages/MyEarnings/ElasticPools/SinglePool/index.tsx +++ b/src/pages/MyEarnings/ElasticPools/SinglePool/index.tsx @@ -273,8 +273,7 @@ const SinglePool: React.FC = ({ poolEarning, chainId, positionEarnings, p = ({ poolEarning, chainId, positionEarnings, p } > - {formatDisplayNumber({ value: (poolAPR + farmAPR) / 100, style: 'percent', fractionDigits: 2 })} + {formatDisplayNumber((poolAPR + farmAPR) / 100, { style: 'percent', fractionDigits: 2 })} @@ -312,31 +311,28 @@ const SinglePool: React.FC = ({ poolEarning, chainId, positionEarnings, p /> @@ -436,8 +432,7 @@ const SinglePool: React.FC = ({ poolEarning, chainId, positionEarnings, p - {formatDisplayNumber({ - value: poolEarning.totalValueLockedUsd, + {formatDisplayNumber(poolEarning.totalValueLockedUsd, { style: 'currency', significantDigits: 7, fractionDigits: 4, @@ -459,27 +454,25 @@ const SinglePool: React.FC = ({ poolEarning, chainId, positionEarnings, p } > - {formatDisplayNumber({ value: (poolAPR + farmAPR) / 100, style: 'percent', fractionDigits: 2 })} + {formatDisplayNumber((poolAPR + farmAPR) / 100, { style: 'percent', fractionDigits: 2 })} - {formatDisplayNumber({ - value: Number(poolEarning.volumeUsd) - Number(poolEarning.volumeUsdOneDayAgo), + {formatDisplayNumber(Number(poolEarning.volumeUsd) - Number(poolEarning.volumeUsdOneDayAgo), { style: 'currency', significantDigits: 4, })} - {formatDisplayNumber({ - value: Number(poolEarning.feesUsd) - Number(poolEarning.feesUsdOneDayAgo), + {formatDisplayNumber(Number(poolEarning.feesUsd) - Number(poolEarning.feesUsdOneDayAgo), { style: 'currency', significantDigits: 4, })} - {formatDisplayNumber({ value: myLiquidityUsd, style: 'currency', significantDigits: 4 })} - {formatDisplayNumber({ value: poolEarningToday, style: 'currency', significantDigits: 4 })} + {formatDisplayNumber(myLiquidityUsd, { style: 'currency', significantDigits: 4 })} + {formatDisplayNumber(poolEarningToday, { style: 'currency', significantDigits: 4 })} = props => { - {earningToday ? formatDisplayNumber({ value: earningToday.totalValue, style: 'currency' }) : '--'} - + {formatDisplayNumber(earningToday?.totalValue, { style: 'currency', significantDigits: 6 })} } text={ <> @@ -78,7 +76,7 @@ const EarningView: React.FC = props => { > - {formatDisplayNumber({ value: token.amount })} {token.symbol} + {formatDisplayNumber(token.amount, { significantDigits: 6 })} {token.symbol} ))} @@ -98,8 +96,8 @@ const EarningView: React.FC = props => { - {myPoolAPR ? myPoolAPR.toFixed(2) + '%' : '--'} - {myFarmAPR ? myFarmAPR.toFixed(2) + '%' : '--'} + {formatDisplayNumber(myPoolAPR / 100, { style: 'percent', fractionDigits: 2 })} + {formatDisplayNumber(myFarmAPR / 100, { style: 'percent', fractionDigits: 2 })} diff --git a/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx b/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx index eb667b6f1c..b51b52c3e7 100644 --- a/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx +++ b/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx @@ -199,7 +199,7 @@ const PositionView: React.FC = props => { {formatDisplayNumber({ value: liquidityInUsd, style: 'currency' })}} + anchor={{formatDisplayNumber(liquidityInUsd, { style: 'currency', significantDigits: 6 })}} disabled={!liquidityInUsd || Number.isNaN(liquidityInUsd)} text={
@@ -221,7 +221,9 @@ const PositionView: React.FC = props => { {myStakedBalance ? ( {formatDisplayNumber({ value: myStakedBalance, style: 'currency' })}} + anchor={ + {formatDisplayNumber(myStakedBalance, { style: 'currency', significantDigits: 6 })} + } text={
@@ -274,7 +276,7 @@ const PositionView: React.FC = props => { anchor={ {+positionEarning.pendingRewardUSD - ? formatDisplayNumber({ value: positionEarning.pendingRewardUSD, style: 'currency' }) + ? formatDisplayNumber(positionEarning.pendingRewardUSD, { style: 'currency', significantDigits: 6 }) : '--'} } diff --git a/src/pages/MyEarnings/ShareModal.tsx b/src/pages/MyEarnings/ShareModal.tsx index 50bd046021..426565de64 100644 --- a/src/pages/MyEarnings/ShareModal.tsx +++ b/src/pages/MyEarnings/ShareModal.tsx @@ -281,7 +281,7 @@ export default function ShareModal({ isOpen, setIsOpen, title, value, poolInfo } {renderPool()} - {formatDisplayNumber({ value, style: 'currency' })} + {formatDisplayNumber(value, { style: 'currency', fractionDigits: 2 })} diff --git a/src/pages/MyEarnings/TotalEarningsAndChainSelect.tsx b/src/pages/MyEarnings/TotalEarningsAndChainSelect.tsx index 22fd82fd33..764c1cee8d 100644 --- a/src/pages/MyEarnings/TotalEarningsAndChainSelect.tsx +++ b/src/pages/MyEarnings/TotalEarningsAndChainSelect.tsx @@ -136,11 +136,10 @@ const TotalEarningsAndChainSelect: React.FC = ({ totalEarningToday, total return -- } - const totalValue = formatDisplayNumber({ value: totalEarningToday, style: 'currency', significantDigits: 6 }) + const totalValue = formatDisplayNumber(totalEarningToday, { style: 'currency', significantDigits: 6 }) const diffPercent = totalEarningYesterday && !Number.isNaN(totalEarningYesterday) - ? formatDisplayNumber({ - value: totalEarningToday / totalEarningYesterday - 1, + ? formatDisplayNumber(totalEarningToday / totalEarningYesterday - 1, { style: 'percent', fractionDigits: 2, significantDigits: 6, diff --git a/src/utils/fee.ts b/src/utils/fee.ts index 33d90db40e..daba1d412a 100644 --- a/src/utils/fee.ts +++ b/src/utils/fee.ts @@ -40,8 +40,9 @@ export const calculateFeeFromBuildData = ( const feeUsd = buildData.feeUsd return { - feeAmount: formatDisplayNumber({ value: fee, significantDigits: 10 }), - feeAmountUsd: feeUsd && feeUsd !== '0' ? formatDisplayNumber({ value: feeUsd, style: 'currency' }) : '', + feeAmount: formatDisplayNumber(fee, { significantDigits: 10 }), + feeAmountUsd: + feeUsd && feeUsd !== '0' ? formatDisplayNumber(feeUsd, { style: 'currency', significantDigits: 10 }) : '', currency: currencyAmountToTakeFee.currency, } } diff --git a/src/utils/formatTickPrice.ts b/src/utils/formatTickPrice.ts index 1f2ebe62d2..fcd6fa47c9 100644 --- a/src/utils/formatTickPrice.ts +++ b/src/utils/formatTickPrice.ts @@ -2,7 +2,7 @@ import { Currency, Price } from '@kyberswap/ks-sdk-core' import { Bound } from 'state/mint/proamm/type' -import { formatPrice } from './formatCurrencyAmount' +import { formatDisplayNumber } from './numbers' export function formatTickPrice( price: Price | undefined, @@ -17,5 +17,5 @@ export function formatTickPrice( if (!price && placeholder !== undefined) { return placeholder } - return formatPrice(price, 5) + return formatDisplayNumber(price, { significantDigits: 6 }) } diff --git a/src/utils/numbers.ts b/src/utils/numbers.ts index a6984742b9..f3865eabab 100644 --- a/src/utils/numbers.ts +++ b/src/utils/numbers.ts @@ -82,7 +82,7 @@ const log10 = (n: Fraction): number => { return Math.log10(parsedN) } -const parseNum = (value: FormatParam['value']): Fraction => { +const parseNum = (value: FormatValue): Fraction => { try { if ( typeof value === 'string' || @@ -111,24 +111,46 @@ const parseNum = (value: FormatParam['value']): Fraction => { } } -type FormatParam = { - value: string | number | bigint | JSBI | Fraction | undefined | null +type FormatValue = string | number | bigint | JSBI | Fraction | undefined | null +type FormatOptions = { style?: 'decimal' | 'currency' | 'percent' fractionDigits?: number // usually for percent & currency styles significantDigits?: number // usually for decimal style fallback?: string allowNegative?: boolean } +interface RequiredFraction extends FormatOptions { + fractionDigits: number // usually for percent & currency styles +} +interface RequiredSignificant extends FormatOptions { + significantDigits: number // usually for percent & currency styles +} // todo: deprecated others format functions and all .toSignificant() to only use this function -export const formatDisplayNumber = ({ - value, - style = 'decimal', - significantDigits, - fractionDigits, - fallback = '--', - allowNegative = false, -}: FormatParam): string => { +/** + * Format number to displaying to the UI + * @example + * // returns 0.2 + * formatDisplayNumber(0.2, { style: 'decimal', significantDigits: 6 }) + * @example + * // returns $0.2 + * formatDisplayNumber(0.2, { style: 'currency', significantDigits: 6 }) + * @example + * // returns 20% + * formatDisplayNumber(0.2, { style: 'percent', significantDigits: 6 }) + * @example + * @returns {string} Returns the formatted number in string + */ +export const formatDisplayNumber = ( + value: FormatValue, + { + style = 'decimal', + significantDigits, + fractionDigits, + fallback = '--', + allowNegative = false, + }: RequiredFraction | RequiredSignificant, +): string => { const currency = style === 'currency' ? '$' : '' const percent = style === 'percent' ? '%' : '' const fallbackResult = `${currency}${fallback}${percent}` @@ -147,7 +169,7 @@ export const formatDisplayNumber = ({ const decimal = shownFraction.toSignificant(30).split('.')[1] const negative = shownFraction.lessThan(BIG_INT_ZERO) ? '-' : '' const numberOfLeadingZeros = -Math.floor( - log10(shownFraction.lessThan(0) ? shownFraction.multiply(-1) : shownFraction) + 1, + log10(shownFraction.lessThan(0) ? shownFraction.invert() : shownFraction) + 1, ) const slicedDecimal = decimal .replace(/^0+/, '') @@ -164,7 +186,9 @@ export const formatDisplayNumber = ({ return `${negative}${currency}0.0${subscripts}${slicedDecimal}${percent}` } - return `${negative}${currency}0${slicedDecimal.length ? '.' + slicedDecimal : ''}${percent}` + return `${negative}${currency}0${ + slicedDecimal.length ? '.' + '0'.repeat(numberOfLeadingZeros) + slicedDecimal : '' + }${percent}` } const formatter = Intl.NumberFormat('en-US', {