From d1fc7e2b7830e36d3fb2d5b888343617ab24140e Mon Sep 17 00:00:00 2001 From: salimtb Date: Fri, 21 Jun 2024 15:23:45 +0200 Subject: [PATCH] fix: fix large amount display --- ui/components/app/token-cell/token-cell.js | 8 +++++++- .../app/token-cell/token-cell.test.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ui/components/app/token-cell/token-cell.js b/ui/components/app/token-cell/token-cell.js index 0052096254be..aea9fd5c7bc1 100644 --- a/ui/components/app/token-cell/token-cell.js +++ b/ui/components/app/token-cell/token-cell.js @@ -6,6 +6,7 @@ import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount'; import { TokenListItem } from '../../multichain'; import { isEqualCaseInsensitive } from '../../../../shared/modules/string-utils'; import { useIsOriginalTokenSymbol } from '../../../hooks/useIsOriginalTokenSymbol'; +import { getIntlLocale } from '../../../ducks/locale/locale'; export default function TokenCell({ address, image, symbol, string, onClick }) { const tokenList = useSelector(getTokenList); @@ -17,6 +18,11 @@ export default function TokenCell({ address, image, symbol, string, onClick }) { const title = tokenData?.name || symbol; const tokenImage = tokenData?.iconUrl || image; const formattedFiat = useTokenFiatAmount(address, string, symbol); + const locale = useSelector(getIntlLocale); + const primary = new Intl.NumberFormat(locale, { + minimumSignificantDigits: 4, + }).format(string.toString()); + const isOriginalTokenSymbol = useIsOriginalTokenSymbol(address, symbol); return ( @@ -24,7 +30,7 @@ export default function TokenCell({ address, image, symbol, string, onClick }) { onClick={onClick ? () => onClick(address) : undefined} tokenSymbol={symbol} tokenImage={tokenImage} - primary={`${string || 0}`} + primary={`${primary || 0}`} secondary={isOriginalTokenSymbol ? formattedFiat : null} title={title} isOriginalTokenSymbol={isOriginalTokenSymbol} diff --git a/ui/components/app/token-cell/token-cell.test.js b/ui/components/app/token-cell/token-cell.test.js index 8312000d3ed2..731361de7df6 100644 --- a/ui/components/app/token-cell/token-cell.test.js +++ b/ui/components/app/token-cell/token-cell.test.js @@ -86,6 +86,13 @@ describe('Token Cell', () => { onClick: jest.fn(), }; + const propsLargeAmount = { + address: '0xAnotherToken', + symbol: 'TEST', + string: '5000000', + currentCurrency: 'usd', + onClick: jest.fn(), + }; useSelector.mockReturnValue(MOCK_GET_TOKEN_LIST); useTokenFiatAmount.mockReturnValue('5.00'); @@ -121,4 +128,16 @@ describe('Token Cell', () => { expect(image).toBeInTheDocument(); expect(image).toHaveAttribute('src', './images/test_image.svg'); }); + + it('should render amount with the correct format', () => { + const { getByTestId } = renderWithProvider( + , + mockStore, + ); + + const amountElement = getByTestId('multichain-token-list-item-value'); + + expect(amountElement).toBeInTheDocument(); + expect(amountElement.textContent).toBe('5,000,000 TEST'); + }); });