Commit 14f01905 authored by lynn's avatar lynn Committed by GitHub

fix: price formatting spot check fixes (#4850)

fix price formatting
parent 23eb31e6
...@@ -22,6 +22,7 @@ import { ...@@ -22,6 +22,7 @@ import {
monthYearDayFormatter, monthYearDayFormatter,
weekFormatter, weekFormatter,
} from 'utils/formatChartTimes' } from 'utils/formatChartTimes'
import { formatDollar } from 'utils/formatDollarAmt'
import { MEDIUM_MEDIA_BREAKPOINT } from '../constants' import { MEDIUM_MEDIA_BREAKPOINT } from '../constants'
import { DISPLAYS, ORDERED_TIMES } from '../TokenTable/TimeSelector' import { DISPLAYS, ORDERED_TIMES } from '../TokenTable/TimeSelector'
...@@ -270,7 +271,7 @@ export function PriceChart({ width, height, prices }: PriceChartProps) { ...@@ -270,7 +271,7 @@ export function PriceChart({ width, height, prices }: PriceChartProps) {
return ( return (
<> <>
<ChartHeader> <ChartHeader>
<TokenPrice>${displayPrice.value < 0.000001 ? '<0.000001' : displayPrice.value.toFixed(6)}</TokenPrice> <TokenPrice>{formatDollar(displayPrice.value, true)}</TokenPrice>
<DeltaContainer> <DeltaContainer>
{formattedDelta} {formattedDelta}
<ArrowCell>{arrow}</ArrowCell> <ArrowCell>{arrow}</ArrowCell>
......
...@@ -39,8 +39,14 @@ describe('formatDollar for a price', () => { ...@@ -39,8 +39,14 @@ describe('formatDollar for a price', () => {
it('num >= 0.1 && num < 1.05', () => { it('num >= 0.1 && num < 1.05', () => {
expect(formatDollar(0.812831, true)).toEqual('$0.813') expect(formatDollar(0.812831, true)).toEqual('$0.813')
}) })
it('number is greater than 1 million', () => {
expect(formatDollar(11192312.408, true)).toEqual('$1.12e+7')
})
it('number in the thousands', () => {
expect(formatDollar(1234.408, true)).toEqual('$1,234.41')
})
it('number is greater than 1.05', () => { it('number is greater than 1.05', () => {
expect(formatDollar(102312.408, true)).toEqual('$102312.41') expect(formatDollar(102312.408, true)).toEqual('$102,312.41')
}) })
}) })
......
/* Copied from Uniswap/v-3: https://github.com/Uniswap/v3-info/blob/master/src/utils/numbers.ts */ /* Copied from Uniswap/v-3: https://github.com/Uniswap/v3-info/blob/master/src/utils/numbers.ts */
import { Currency, CurrencyAmount } from '@uniswap/sdk-core' import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
import { DEFAULT_LOCALE } from 'constants/locales'
import numbro from 'numbro' import numbro from 'numbro'
// Convert [CurrencyAmount] to number with necessary precision for price formatting. // Convert [CurrencyAmount] to number with necessary precision for price formatting.
...@@ -19,14 +20,14 @@ export const formatDollar = (num: number | undefined | null, isPrice = false, di ...@@ -19,14 +20,14 @@ export const formatDollar = (num: number | undefined | null, isPrice = false, di
if (num < 0.000001) { if (num < 0.000001) {
return `$${num.toExponential(2)}` return `$${num.toExponential(2)}`
} }
if (num >= 0.000001 && num < 0.1) { if ((num >= 0.000001 && num < 0.1) || num > 1000000) {
return `$${Number(num).toPrecision(3)}` return `$${Number(num).toPrecision(3)}`
} }
if (num >= 0.1 && num < 1.05) { if (num >= 0.1 && num < 1.05) {
return `$${num.toFixed(3)}` return `$${num.toFixed(3)}`
} }
// if number is greater than 1.05: // if number is greater than 1.05:
return `$${num.toFixed(2)}` return `$${Number(num.toFixed(2)).toLocaleString(DEFAULT_LOCALE)}`
} }
// For volume dollar amounts, like market cap, total value locked, etc. // For volume dollar amounts, like market cap, total value locked, etc.
else { else {
......
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