Skip to content

Commit

Permalink
fix: 0 token balance in send flow (#28136)
Browse files Browse the repository at this point in the history
## **Description**

Fixes an issue where token balance showed as 0 during send flow. This
occurred when clicking the token in the token list, then clicking the
send button from the token details page.

When going send first and then picking a token, picking `decimals` was a
number:


![image](https://github.com/user-attachments/assets/95d32a68-1076-4050-b129-187672694794)

But when going token first and then clicking send , `decimals` was a
string and skipped calculating the balance.


![image](https://github.com/user-attachments/assets/99a8fcd4-bd29-4969-b98d-6639d50553ff)


`calcTokenAmount` seems to work with either string or number, so
changing logic from
#27083 which
introduced the number check


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

## **Related issues**

Fixes: #28112

## **Manual testing steps**

1. Click on an erc20 token on the token list
2. Click the send button on the token details page
3. Choose a destination account
4. The balance under the asset picker should be accurate

## **Screenshots/Recordings**

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

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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
bergeron authored Oct 29, 2024
1 parent 6eae9bc commit 1fd9510
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -2670,7 +2670,7 @@ export function updateSendAsset(

if (details.standard === TokenStandard.ERC20) {
asset.balance =
details.balance && typeof details.decimals === 'number'
details.balance && details.decimals !== undefined
? addHexPrefix(
calcTokenAmount(details.balance, details.decimals).toString(16),
)
Expand Down

0 comments on commit 1fd9510

Please sign in to comment.