Skip to content

Commit

Permalink
fix (cherry-pick): 0 token balance in send flow (#28136) (#28151)
Browse files Browse the repository at this point in the history
Cherry-picks #28136
(1fd9510). Original PR description:

## **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.


<!--
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**

<!--
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/28151?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **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.

Co-authored-by: Brian Bergeron <brian.e.bergeron@gmail.com>
  • Loading branch information
danjm and bergeron authored Oct 29, 2024
1 parent 40febb6 commit d7108ed
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 @@ -2669,7 +2669,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 d7108ed

Please sign in to comment.