From 9178642461376ad2cbb30aba33d20fe35c3feb75 Mon Sep 17 00:00:00 2001 From: Gonzalo D'elia Date: Wed, 5 Mar 2025 15:53:12 -0300 Subject: [PATCH] Update TVL formatting for small values --- .../manageStake/strategyDetails.tsx | 1 - .../stake/_components/manageStake/tvl.tsx | 4 +- .../_components/stakePointsCards/index.tsx | 4 +- webapp/test/utils/format.test.ts | 40 +++++++++---------- webapp/utils/format.ts | 18 ++++----- 5 files changed, 32 insertions(+), 35 deletions(-) diff --git a/webapp/app/[locale]/stake/_components/manageStake/strategyDetails.tsx b/webapp/app/[locale]/stake/_components/manageStake/strategyDetails.tsx index f9f5a7bf..93360e86 100644 --- a/webapp/app/[locale]/stake/_components/manageStake/strategyDetails.tsx +++ b/webapp/app/[locale]/stake/_components/manageStake/strategyDetails.tsx @@ -37,7 +37,6 @@ export const StrategyDetails = function ({ token }: Props) {
- $ diff --git a/webapp/app/[locale]/stake/_components/manageStake/tvl.tsx b/webapp/app/[locale]/stake/_components/manageStake/tvl.tsx index eaa1a483..6eaeb7d9 100644 --- a/webapp/app/[locale]/stake/_components/manageStake/tvl.tsx +++ b/webapp/app/[locale]/stake/_components/manageStake/tvl.tsx @@ -2,7 +2,7 @@ import { RenderFiatBalance } from 'components/fiatBalance' import { useTotalSupply } from 'hooks/useTotalSupply' import { type StakeToken } from 'types/stake' import { type EvmToken } from 'types/token' -import { formatLargeFiatNumber } from 'utils/format' +import { formatTVL } from 'utils/format' import { isNativeAddress } from 'utils/nativeToken' import { getWrappedEther } from 'utils/token' @@ -15,7 +15,7 @@ const TokenTvl = function ({ token }: { token: EvmToken }) { return ( export const formatFiatNumber = (value: number | string) => fiatRounder(value, { shouldFormat: true }) -export const formatLargeFiatNumber = function (amount: number | string) { - // for less than one million, use the regular format. - if (Big(amount).lt(1_000_000)) { - return formatFiatNumber(amount) +export const formatTVL = function (amount: number | string) { + if (Big(amount).lt(100_000)) { + // for less than 100k, return "< 100k" + const formatted = new Intl.NumberFormat('en-US', { + notation: 'compact', + }).format(100_000) + return `< $${formatted}` } - // for larger than that, use the million format. - return new Intl.NumberFormat('en-US', { notation: 'compact' }).format( - // @ts-expect-error NumberFormat.format accept strings, typings are wrong. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format#parameters - amount, - ) + // For the rest, show the full format + return `$${formatFiatNumber(amount)}` }