Commit 60acc689 authored by Jack Short's avatar Jack Short Committed by GitHub

chore: updating numberFormat for other currencies and languages (#7239)

* adding currency settings option

* moving menu item to shared component

* adding supported currencies

* currency menu items

* currency url params

* currency selector e2e tests

* fixing tests

* currency icons

* removing eslint

* removing another eslint disable

* renaming to local currency

* more name changes

* design updates

* adding currencies

* changing formatter rules to formatter options

* renaming file

* fixing lint

* custom currency symbol in number formatting

* refactoring input to number formatter

* locale selection

* updating all format numbers with currency and locale

* updating portfolio

* better formatting symbols

* removing adding locale and currency

* upgrading constants to be translatable

* refactoring

* adding tests

* updating comment

* removing 0 from hardcoded input and comment
parent cd520a9e
...@@ -279,16 +279,20 @@ export default function AuthenticatedHeader({ account, openSettings }: { account ...@@ -279,16 +279,20 @@ export default function AuthenticatedHeader({ account, openSettings }: { account
{totalBalance !== undefined ? ( {totalBalance !== undefined ? (
<FadeInColumn gap="xs"> <FadeInColumn gap="xs">
<ThemedText.HeadlineLarge fontWeight={535} data-testid="portfolio-total-balance"> <ThemedText.HeadlineLarge fontWeight={535} data-testid="portfolio-total-balance">
{formatNumber(totalBalance, NumberType.PortfolioBalance)} {formatNumber({
input: totalBalance,
type: NumberType.PortfolioBalance,
})}
</ThemedText.HeadlineLarge> </ThemedText.HeadlineLarge>
<AutoRow marginBottom="20px"> <AutoRow marginBottom="20px">
{absoluteChange !== 0 && percentChange && ( {absoluteChange !== 0 && percentChange && (
<> <>
<PortfolioArrow change={absoluteChange as number} /> <PortfolioArrow change={absoluteChange as number} />
<ThemedText.BodySecondary> <ThemedText.BodySecondary>
{`${formatNumber(Math.abs(absoluteChange as number), NumberType.PortfolioBalance)} (${formatDelta( {`${formatNumber({
percentChange input: Math.abs(absoluteChange as number),
)})`} type: NumberType.PortfolioBalance,
})} (${formatDelta(percentChange)})`}
</ThemedText.BodySecondary> </ThemedText.BodySecondary>
</> </>
)} )}
......
...@@ -167,18 +167,21 @@ function PositionListItem({ positionInfo }: { positionInfo: PositionInfo }) { ...@@ -167,18 +167,21 @@ function PositionListItem({ positionInfo }: { positionInfo: PositionInfo }) {
placement="left" placement="left"
text={ text={
<div style={{ padding: '4px 0px' }}> <div style={{ padding: '4px 0px' }}>
<ThemedText.BodySmall>{`${formatNumber( <ThemedText.BodySmall>{`${formatNumber({
liquidityValue, input: liquidityValue,
NumberType.PortfolioBalance type: NumberType.PortfolioBalance,
)} (liquidity) + ${formatNumber( })} (liquidity) + ${formatNumber({
feeValue, input: feeValue,
NumberType.PortfolioBalance type: NumberType.PortfolioBalance,
)} (fees)`}</ThemedText.BodySmall> })} (fees)`}</ThemedText.BodySmall>
</div> </div>
} }
> >
<ThemedText.SubHeader> <ThemedText.SubHeader>
{formatNumber((liquidityValue ?? 0) + (feeValue ?? 0), NumberType.PortfolioBalance)} {formatNumber({
input: (liquidityValue ?? 0) + (feeValue ?? 0),
type: NumberType.PortfolioBalance,
})}
</ThemedText.SubHeader> </ThemedText.SubHeader>
</MouseoverTooltip> </MouseoverTooltip>
......
...@@ -101,7 +101,7 @@ function TokenRow({ token, quantity, denominatedValue, tokenProjectMarket }: Tok ...@@ -101,7 +101,7 @@ function TokenRow({ token, quantity, denominatedValue, tokenProjectMarket }: Tok
title={<TokenNameText>{token?.name}</TokenNameText>} title={<TokenNameText>{token?.name}</TokenNameText>}
descriptor={ descriptor={
<TokenBalanceText> <TokenBalanceText>
{formatNumber(quantity, NumberType.TokenNonTx)} {token?.symbol} {formatNumber({ input: quantity, type: NumberType.TokenNonTx })} {token?.symbol}
</TokenBalanceText> </TokenBalanceText>
} }
onClick={navigateToTokenDetails} onClick={navigateToTokenDetails}
...@@ -109,7 +109,10 @@ function TokenRow({ token, quantity, denominatedValue, tokenProjectMarket }: Tok ...@@ -109,7 +109,10 @@ function TokenRow({ token, quantity, denominatedValue, tokenProjectMarket }: Tok
denominatedValue && ( denominatedValue && (
<> <>
<ThemedText.SubHeader> <ThemedText.SubHeader>
{formatNumber(denominatedValue?.value, NumberType.PortfolioBalance)} {formatNumber({
input: denominatedValue?.value,
type: NumberType.PortfolioBalance,
})}
</ThemedText.SubHeader> </ThemedText.SubHeader>
<Row justify="flex-end"> <Row justify="flex-end">
<PortfolioArrow change={percentChange} size={20} strokeWidth={1.75} /> <PortfolioArrow change={percentChange} size={20} strokeWidth={1.75} />
......
...@@ -39,7 +39,10 @@ export function FiatValue({ ...@@ -39,7 +39,10 @@ export function FiatValue({
<Row gap="sm"> <Row gap="sm">
<ThemedText.BodySmall color="neutral2"> <ThemedText.BodySmall color="neutral2">
{fiatValue.data ? ( {fiatValue.data ? (
formatNumber(fiatValue.data, NumberType.FiatTokenPrice) formatNumber({
input: fiatValue.data,
type: NumberType.FiatTokenPrice,
})
) : ( ) : (
<MouseoverTooltip text={<Trans>Not enough liquidity to show accurate USD value.</Trans>}>-</MouseoverTooltip> <MouseoverTooltip text={<Trans>Not enough liquidity to show accurate USD value.</Trans>}>-</MouseoverTooltip>
)} )}
......
...@@ -62,7 +62,12 @@ function Stat({ ...@@ -62,7 +62,12 @@ function Stat({
return ( return (
<StatWrapper data-cy={`${dataCy}`}> <StatWrapper data-cy={`${dataCy}`}>
<MouseoverTooltip text={description}>{title}</MouseoverTooltip> <MouseoverTooltip text={description}>{title}</MouseoverTooltip>
<StatPrice>{formatNumber(value, NumberType.FiatTokenStats)}</StatPrice> <StatPrice>
{formatNumber({
input: value,
type: NumberType.FiatTokenStats,
})}
</StatPrice>
</StatWrapper> </StatWrapper>
) )
} }
......
...@@ -503,11 +503,19 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT ...@@ -503,11 +503,19 @@ export const LoadedRow = forwardRef((props: LoadedRowProps, ref: ForwardedRef<HT
} }
tvl={ tvl={
<ClickableContent> <ClickableContent>
{formatNumber(token.market?.totalValueLocked?.value, NumberType.FiatTokenStats)} {formatNumber({
input: token.market?.totalValueLocked?.value,
type: NumberType.FiatTokenStats,
})}
</ClickableContent> </ClickableContent>
} }
volume={ volume={
<ClickableContent>{formatNumber(token.market?.volume?.value, NumberType.FiatTokenStats)}</ClickableContent> <ClickableContent>
{formatNumber({
input: token.market?.volume?.value,
type: NumberType.FiatTokenStats,
})}
</ClickableContent>
} }
sparkLine={ sparkLine={
<SparkLine> <SparkLine>
......
...@@ -73,10 +73,10 @@ export function AdvancedSwapDetails({ trade, allowedSlippage, syncing = false }: ...@@ -73,10 +73,10 @@ export function AdvancedSwapDetails({ trade, allowedSlippage, syncing = false }:
> >
<TextWithLoadingPlaceholder syncing={syncing} width={50}> <TextWithLoadingPlaceholder syncing={syncing} width={50}>
<ThemedText.BodySmall> <ThemedText.BodySmall>
{`${trade.totalGasUseEstimateUSD ? '~' : ''}${formatNumber( {`${trade.totalGasUseEstimateUSD ? '~' : ''}${formatNumber({
trade.totalGasUseEstimateUSD, input: trade.totalGasUseEstimateUSD,
NumberType.FiatGasPrice type: NumberType.FiatGasPrice,
)}`} })}`}
</ThemedText.BodySmall> </ThemedText.BodySmall>
</TextWithLoadingPlaceholder> </TextWithLoadingPlaceholder>
</MouseoverTooltip> </MouseoverTooltip>
......
...@@ -39,7 +39,11 @@ const GasCostItem = ({ ...@@ -39,7 +39,11 @@ const GasCostItem = ({
<Row justify="space-between"> <Row justify="space-between">
<ThemedText.SubHeaderSmall>{title}</ThemedText.SubHeaderSmall> <ThemedText.SubHeaderSmall>{title}</ThemedText.SubHeaderSmall>
<ThemedText.SubHeaderSmall color="neutral1"> <ThemedText.SubHeaderSmall color="neutral1">
{itemValue ?? formatNumber(amount, NumberType.FiatGasPrice)} {itemValue ??
formatNumber({
input: amount,
type: NumberType.FiatGasPrice,
})}
</ThemedText.SubHeaderSmall> </ThemedText.SubHeaderSmall>
</Row> </Row>
) )
......
...@@ -47,10 +47,20 @@ export default function GasEstimateTooltip({ trade, loading }: { trade?: Interfa ...@@ -47,10 +47,20 @@ export default function GasEstimateTooltip({ trade, loading }: { trade?: Interfa
{isUniswapXTrade(trade) ? <UniswapXRouterIcon testId="gas-estimate-uniswapx-icon" /> : <StyledGasIcon />} {isUniswapXTrade(trade) ? <UniswapXRouterIcon testId="gas-estimate-uniswapx-icon" /> : <StyledGasIcon />}
<ThemedText.BodySmall color="neutral2"> <ThemedText.BodySmall color="neutral2">
<Row gap="xs"> <Row gap="xs">
<div>{formatNumber(trade.totalGasUseEstimateUSD, NumberType.FiatGasPrice)}</div> <div>
{formatNumber({
input: trade.totalGasUseEstimateUSD,
type: NumberType.FiatGasPrice,
})}
</div>
{isUniswapXTrade(trade) && ( {isUniswapXTrade(trade) && (
<div> <div>
<s>{formatNumber(trade.classicGasUseEstimateUSD, NumberType.FiatGasPrice)}</s> <s>
{formatNumber({
input: trade.classicGasUseEstimateUSD,
type: NumberType.FiatGasPrice,
})}
</s>
</div> </div>
)} )}
</Row> </Row>
......
...@@ -109,7 +109,12 @@ export default function SwapModalFooter({ ...@@ -109,7 +109,12 @@ export default function SwapModalFooter({
</Label> </Label>
</MouseoverTooltip> </MouseoverTooltip>
<MouseoverTooltip placement="right" size={TooltipSize.Small} text={<GasBreakdownTooltip trade={trade} />}> <MouseoverTooltip placement="right" size={TooltipSize.Small} text={<GasBreakdownTooltip trade={trade} />}>
<DetailRowValue>{formatNumber(trade.totalGasUseEstimateUSD, NumberType.FiatGasPrice)}</DetailRowValue> <DetailRowValue>
{formatNumber({
input: trade.totalGasUseEstimateUSD,
type: NumberType.FiatGasPrice,
})}
</DetailRowValue>
</MouseoverTooltip> </MouseoverTooltip>
</Row> </Row>
</ThemedText.BodySmall> </ThemedText.BodySmall>
......
...@@ -59,7 +59,10 @@ export function SwapModalHeaderAmount({ tooltipText, label, amount, usdAmount, f ...@@ -59,7 +59,10 @@ export function SwapModalHeaderAmount({ tooltipText, label, amount, usdAmount, f
</ResponsiveHeadline> </ResponsiveHeadline>
{usdAmount && ( {usdAmount && (
<ThemedText.BodySmall color="neutral2"> <ThemedText.BodySmall color="neutral2">
{formatNumber(usdAmount, NumberType.FiatTokenQuantity)} {formatNumber({
input: usdAmount,
type: NumberType.FiatTokenQuantity,
})}
</ThemedText.BodySmall> </ThemedText.BodySmall>
)} )}
</Column> </Column>
......
...@@ -58,7 +58,14 @@ export default function TradePrice({ price }: TradePriceProps) { ...@@ -58,7 +58,14 @@ export default function TradePrice({ price }: TradePriceProps) {
<ThemedText.BodySmall>{text}</ThemedText.BodySmall>{' '} <ThemedText.BodySmall>{text}</ThemedText.BodySmall>{' '}
{usdPrice && ( {usdPrice && (
<ThemedText.BodySmall color="neutral2"> <ThemedText.BodySmall color="neutral2">
<Trans>({formatNumber(usdPrice, NumberType.FiatTokenPrice)})</Trans> <Trans>
(
{formatNumber({
input: usdPrice,
type: NumberType.FiatTokenPrice,
})}
)
</Trans>
</ThemedText.BodySmall> </ThemedText.BodySmall>
)} )}
</StyledPriceContainer> </StyledPriceContainer>
......
...@@ -46,6 +46,31 @@ export type SupportedLocalCurrency = (typeof SUPPORTED_LOCAL_CURRENCIES)[number] ...@@ -46,6 +46,31 @@ export type SupportedLocalCurrency = (typeof SUPPORTED_LOCAL_CURRENCIES)[number]
export const DEFAULT_LOCAL_CURRENCY: SupportedLocalCurrency = 'USD' export const DEFAULT_LOCAL_CURRENCY: SupportedLocalCurrency = 'USD'
// some currencies need to be forced to use the narrow symbol and others need to be forced to use symbol
// for example: when CAD is set to narrowSymbol it is displayed as $ which offers no differentiation from USD
// but when set to symbol it is displayed as CA$ which is correct
// On the other hand when TBH is set to symbol it is displayed as THB, but when set to narrowSymbol it is ฿ which is correct
export const LOCAL_CURRENCY_SYMBOL_DISPLAY_TYPE: Record<SupportedLocalCurrency, 'narrowSymbol' | 'symbol'> = {
USD: 'narrowSymbol',
EUR: 'narrowSymbol',
RUB: 'narrowSymbol',
INR: 'narrowSymbol',
GBP: 'narrowSymbol',
JPY: 'narrowSymbol',
VND: 'narrowSymbol',
SGD: 'symbol',
BRL: 'symbol',
HKD: 'symbol',
CAD: 'symbol',
IDR: 'narrowSymbol',
TRY: 'narrowSymbol',
NGN: 'narrowSymbol',
UAH: 'narrowSymbol',
PKR: 'narrowSymbol',
AUD: 'symbol',
THB: 'narrowSymbol',
}
export function getLocalCurrencyIcon(localCurrency: SupportedLocalCurrency, size = 20): ReactNode { export function getLocalCurrencyIcon(localCurrency: SupportedLocalCurrency, size = 20): ReactNode {
switch (localCurrency) { switch (localCurrency) {
case 'USD': case 'USD':
......
This diff is collapsed.
This diff is collapsed.
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