Skip to content

Commit 49dc83f

Browse files
Merge pull request #629 from curvefi/feat/filter-giga-usd
feat: hide USD values > 100T
2 parents 852a980 + 0033c7a commit 49dc83f

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

packages/curve-ui-kit/src/shared/ui/Metric.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react'
1+
import { useMemo, useState } from 'react'
22

33
import Alert from '@mui/material/Alert'
44
import Stack from '@mui/material/Stack'
@@ -13,6 +13,7 @@ import { TypographyVariantKey } from '@ui-kit/themes/typography'
1313
import { abbreviateNumber, scaleSuffix } from '@ui-kit/utils'
1414
import { Duration } from '../../themes/design/0_primitives'
1515
import AlertTitle from '@mui/material/AlertTitle'
16+
import { MAX_USD_VALUE } from 'ui'
1617

1718
const { Spacing, IconSize } = SizesAndSpaces
1819

@@ -94,6 +95,14 @@ type MetricValueProps = Required<Pick<Props, 'value' | 'formatter' | 'abbreviate
9495
copyValue: () => void
9596
}
9697

98+
function runFormatter(value: number, formatter: (value: number) => string, abbreviate: boolean, symbol?: string) {
99+
if (symbol === '$' && value > MAX_USD_VALUE) {
100+
console.warn(`USD value is too large: ${value}`)
101+
return `?`
102+
}
103+
return formatter(abbreviate ? abbreviateNumber(value) : value)
104+
}
105+
97106
const MetricValue = ({
98107
value,
99108
formatter,
@@ -114,7 +123,10 @@ const MetricValue = ({
114123
)}
115124

116125
<Typography variant={fontVariant} color="textPrimary">
117-
{formatter(abbreviate ? abbreviateNumber(value) : value)}
126+
{useMemo(
127+
() => runFormatter(value, formatter, abbreviate, unit?.symbol),
128+
[formatter, abbreviate, value, unit?.symbol],
129+
)}
118130
</Typography>
119131

120132
{abbreviate && (

packages/ui/src/utils/utilsConstants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export const CURVE_ASSETS_URL = `${CURVE_CDN_URL}/curve-assets`
44
export const CURVE_LOGO_URL = `${CURVE_ASSETS_URL}/branding/logo.png`
55
export const NOT_FOUND_IMAGE_URL = `${CURVE_ASSETS_URL}/branding/four-oh-llama.jpg`
66

7+
// Sometimes API returns overflowed USD values. Don't show them!
8+
export const MAX_USD_VALUE = 100_000_000_000_000 // $ 100T 🤑
9+
710
export const getImageBaseUrl = (blockchainId: string) =>
811
`${CURVE_ASSETS_URL}/images/assets${blockchainId == 'ethereum' ? '' : `-${blockchainId}`}/`
912

packages/ui/src/utils/utilsFormat.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { detect, fromUrl, fromNavigator } from '@lingui/detect-locale'
22
import BigNumber from 'bignumber.js'
33
import isUndefined from 'lodash/isUndefined'
44
import isNaN from 'lodash/isNaN'
5+
import { MAX_USD_VALUE } from './utilsConstants'
56

67
BigNumber.config({ EXPONENTIAL_AT: 20, ROUNDING_MODE: BigNumber.ROUND_HALF_UP })
78
export const BN = BigNumber
@@ -140,6 +141,10 @@ export function formatNumber(val: number | string | undefined | null, options?:
140141
}
141142

142143
function _formatNumber(val: string | number, options: NumberFormatOptions) {
144+
if (options.currency === 'USD' && Number(val) > MAX_USD_VALUE) {
145+
console.warn(`USD value is too large: ${val}`)
146+
return `?`
147+
}
143148
return new Intl.NumberFormat(localeDetected, options).format(
144149
options.style === 'percent' ? Number(val) / 100 : Number(val),
145150
)

0 commit comments

Comments
 (0)