fix: match PendingModalContent number formatting w/ SwapModalHeader (#7053)
* fix: match PendingModalContent number formatting w/ SwapModalHeader * fix: typo * fix: remove argument
This commit is contained in:
parent
29e46455c1
commit
bb2677ab1b
@ -1,10 +1,10 @@
|
|||||||
import { formatCurrencyAmount, NumberType } from '@uniswap/conedison/format'
|
|
||||||
import CurrencyLogo from 'components/Logo/CurrencyLogo'
|
import CurrencyLogo from 'components/Logo/CurrencyLogo'
|
||||||
import Row from 'components/Row'
|
import Row from 'components/Row'
|
||||||
import { ArrowRight } from 'react-feather'
|
import { ArrowRight } from 'react-feather'
|
||||||
import { InterfaceTrade } from 'state/routing/types'
|
import { InterfaceTrade } from 'state/routing/types'
|
||||||
import { useTheme } from 'styled-components/macro'
|
import { useTheme } from 'styled-components/macro'
|
||||||
import { ThemedText } from 'theme'
|
import { ThemedText } from 'theme'
|
||||||
|
import { formatReviewSwapCurrencyAmount } from 'utils/formatNumbers'
|
||||||
|
|
||||||
export function TradeSummary({ trade }: { trade: Pick<InterfaceTrade, 'inputAmount' | 'outputAmount'> }) {
|
export function TradeSummary({ trade }: { trade: Pick<InterfaceTrade, 'inputAmount' | 'outputAmount'> }) {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
@ -12,12 +12,12 @@ export function TradeSummary({ trade }: { trade: Pick<InterfaceTrade, 'inputAmou
|
|||||||
<Row gap="sm" justify="center" align="center">
|
<Row gap="sm" justify="center" align="center">
|
||||||
<CurrencyLogo currency={trade.inputAmount.currency} size="16px" />
|
<CurrencyLogo currency={trade.inputAmount.currency} size="16px" />
|
||||||
<ThemedText.LabelSmall color="textPrimary">
|
<ThemedText.LabelSmall color="textPrimary">
|
||||||
{formatCurrencyAmount(trade.inputAmount, NumberType.SwapTradeAmount)} {trade.inputAmount.currency.symbol}
|
{formatReviewSwapCurrencyAmount(trade.inputAmount)} {trade.inputAmount.currency.symbol}
|
||||||
</ThemedText.LabelSmall>
|
</ThemedText.LabelSmall>
|
||||||
<ArrowRight color={theme.textPrimary} size="12px" />
|
<ArrowRight color={theme.textPrimary} size="12px" />
|
||||||
<CurrencyLogo currency={trade.outputAmount.currency} size="16px" />
|
<CurrencyLogo currency={trade.outputAmount.currency} size="16px" />
|
||||||
<ThemedText.LabelSmall color="textPrimary">
|
<ThemedText.LabelSmall color="textPrimary">
|
||||||
{formatCurrencyAmount(trade.outputAmount, NumberType.SwapTradeAmount)} {trade.outputAmount.currency.symbol}
|
{formatReviewSwapCurrencyAmount(trade.outputAmount)} {trade.outputAmount.currency.symbol}
|
||||||
</ThemedText.LabelSmall>
|
</ThemedText.LabelSmall>
|
||||||
</Row>
|
</Row>
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { formatCurrencyAmount, formatNumber, NumberType } from '@uniswap/conedison/format'
|
import { formatNumber, NumberType } from '@uniswap/conedison/format'
|
||||||
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
|
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
|
||||||
import Column from 'components/Column'
|
import Column from 'components/Column'
|
||||||
import CurrencyLogo from 'components/Logo/CurrencyLogo'
|
import CurrencyLogo from 'components/Logo/CurrencyLogo'
|
||||||
@ -10,8 +10,7 @@ import { TextProps } from 'rebass'
|
|||||||
import { Field } from 'state/swap/actions'
|
import { Field } from 'state/swap/actions'
|
||||||
import styled from 'styled-components/macro'
|
import styled from 'styled-components/macro'
|
||||||
import { BREAKPOINTS, ThemedText } from 'theme'
|
import { BREAKPOINTS, ThemedText } from 'theme'
|
||||||
|
import { formatReviewSwapCurrencyAmount } from 'utils/formatNumbers'
|
||||||
const MAX_AMOUNT_STR_LENGTH = 9
|
|
||||||
|
|
||||||
export const Label = styled(ThemedText.BodySmall)<{ cursor?: string }>`
|
export const Label = styled(ThemedText.BodySmall)<{ cursor?: string }>`
|
||||||
cursor: ${({ cursor }) => cursor};
|
cursor: ${({ cursor }) => cursor};
|
||||||
@ -46,11 +45,6 @@ interface AmountProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function SwapModalHeaderAmount({ tooltipText, label, amount, usdAmount, field, currency }: AmountProps) {
|
export function SwapModalHeaderAmount({ tooltipText, label, amount, usdAmount, field, currency }: AmountProps) {
|
||||||
let formattedAmount = formatCurrencyAmount(amount, NumberType.TokenTx)
|
|
||||||
if (formattedAmount.length > MAX_AMOUNT_STR_LENGTH) {
|
|
||||||
formattedAmount = formatCurrencyAmount(amount, NumberType.SwapTradeAmount)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row align="center" justify="space-between" gap="md">
|
<Row align="center" justify="space-between" gap="md">
|
||||||
<Column gap="xs">
|
<Column gap="xs">
|
||||||
@ -61,7 +55,7 @@ export function SwapModalHeaderAmount({ tooltipText, label, amount, usdAmount, f
|
|||||||
</ThemedText.BodySecondary>
|
</ThemedText.BodySecondary>
|
||||||
<Column gap="xs">
|
<Column gap="xs">
|
||||||
<ResponsiveHeadline data-testid={`${field}-amount`}>
|
<ResponsiveHeadline data-testid={`${field}-amount`}>
|
||||||
{formattedAmount} {currency?.symbol}
|
{formatReviewSwapCurrencyAmount(amount)} {currency?.symbol}
|
||||||
</ResponsiveHeadline>
|
</ResponsiveHeadline>
|
||||||
{usdAmount && (
|
{usdAmount && (
|
||||||
<ThemedText.BodySmall color="textTertiary">
|
<ThemedText.BodySmall color="textTertiary">
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { CurrencyAmount, Price } from '@uniswap/sdk-core'
|
import { CurrencyAmount, Price } from '@uniswap/sdk-core'
|
||||||
import { renBTC, USDC_MAINNET } from 'constants/tokens'
|
import { renBTC, USDC_MAINNET } from 'constants/tokens'
|
||||||
|
|
||||||
import { currencyAmountToPreciseFloat, formatTransactionAmount, priceToPreciseFloat } from './formatNumbers'
|
import {
|
||||||
|
currencyAmountToPreciseFloat,
|
||||||
|
formatReviewSwapCurrencyAmount,
|
||||||
|
formatTransactionAmount,
|
||||||
|
priceToPreciseFloat,
|
||||||
|
} from './formatNumbers'
|
||||||
|
|
||||||
describe('currencyAmountToPreciseFloat', () => {
|
describe('currencyAmountToPreciseFloat', () => {
|
||||||
it('small number', () => {
|
it('small number', () => {
|
||||||
@ -87,3 +92,14 @@ describe('formatTransactionAmount', () => {
|
|||||||
expect(formatTransactionAmount(1234567890123456.789)).toEqual('1.234568e+15')
|
expect(formatTransactionAmount(1234567890123456.789)).toEqual('1.234568e+15')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('formatReviewSwapCurrencyAmount', () => {
|
||||||
|
it('should use TokenTx formatting under a default length', () => {
|
||||||
|
const currencyAmount = CurrencyAmount.fromRawAmount(USDC_MAINNET, '2000000000') // 2,000 USDC
|
||||||
|
expect(formatReviewSwapCurrencyAmount(currencyAmount)).toBe('2,000')
|
||||||
|
})
|
||||||
|
it('should use SwapTradeAmount formatting over the default length', () => {
|
||||||
|
const currencyAmount = CurrencyAmount.fromRawAmount(USDC_MAINNET, '2000000000000') // 2,000,000 USDC
|
||||||
|
expect(formatReviewSwapCurrencyAmount(currencyAmount)).toBe('2000000')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/* 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 { formatCurrencyAmount, NumberType } from '@uniswap/conedison/format'
|
||||||
import { Currency, CurrencyAmount, Price } from '@uniswap/sdk-core'
|
import { Currency, CurrencyAmount, Price } from '@uniswap/sdk-core'
|
||||||
import { DEFAULT_LOCALE } from 'constants/locales'
|
import { DEFAULT_LOCALE } from 'constants/locales'
|
||||||
|
|
||||||
@ -59,3 +60,13 @@ export const formatTransactionAmount = (num: number | undefined | null, maxDigit
|
|||||||
}
|
}
|
||||||
return `${Number(num.toFixed(2)).toLocaleString(DEFAULT_LOCALE, { minimumFractionDigits: 2 })}`
|
return `${Number(num.toFixed(2)).toLocaleString(DEFAULT_LOCALE, { minimumFractionDigits: 2 })}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_AMOUNT_STR_LENGTH = 9
|
||||||
|
|
||||||
|
export function formatReviewSwapCurrencyAmount(amount: CurrencyAmount<Currency>): string {
|
||||||
|
let formattedAmount = formatCurrencyAmount(amount, NumberType.TokenTx)
|
||||||
|
if (formattedAmount.length > MAX_AMOUNT_STR_LENGTH) {
|
||||||
|
formattedAmount = formatCurrencyAmount(amount, NumberType.SwapTradeAmount)
|
||||||
|
}
|
||||||
|
return formattedAmount
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user