Skip to content

Commit

Permalink
fix: fix large amount display (#25464)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
The goal of this PR is to fix the way we display large token amout
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25464?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to wallet page
2. Import a token with large amount
3. check the way it's displayed

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->
![Screenshot 2024-06-21 at 15 30
22](https://github.com/MetaMask/metamask-extension/assets/26223211/2d332ce7-8a6e-45b7-a367-d4214d125bca)

### **After**

<!-- [screenshots/recordings] -->
![Screenshot 2024-06-21 at 15 29
09](https://github.com/MetaMask/metamask-extension/assets/26223211/1a90e5b7-6eb6-4060-9704-dc0ec3716f0f)


## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
salimtb authored Jun 24, 2024
1 parent a445529 commit 64b8db4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ exports[`Token Cell should match snapshot 1`] = `
class="mm-box mm-text mm-text--body-md mm-text--text-align-end mm-box--color-text-alternative"
data-testid="multichain-token-list-item-value"
>
5.000
5
TEST
</p>
Expand Down
8 changes: 7 additions & 1 deletion ui/components/app/token-cell/token-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -17,14 +18,19 @@ 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: 1,
}).format(string.toString());

const isOriginalTokenSymbol = useIsOriginalTokenSymbol(address, symbol);

return (
<TokenListItem
onClick={onClick ? () => onClick(address) : undefined}
tokenSymbol={symbol}
tokenImage={tokenImage}
primary={`${string || 0}`}
primary={`${primary || 0}`}
secondary={isOriginalTokenSymbol ? formattedFiat : null}
title={title}
isOriginalTokenSymbol={isOriginalTokenSymbol}
Expand Down
19 changes: 19 additions & 0 deletions ui/components/app/token-cell/token-cell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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(
<TokenCell {...propsLargeAmount} />,
mockStore,
);

const amountElement = getByTestId('multichain-token-list-item-value');

expect(amountElement).toBeInTheDocument();
expect(amountElement.textContent).toBe('5,000,000 TEST');
});
});

0 comments on commit 64b8db4

Please sign in to comment.