Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 0 token balance in send flow #28136

Merged
merged 1 commit into from
Oct 29, 2024
Merged

fix: 0 token balance in send flow #28136

merged 1 commit into from
Oct 29, 2024

Conversation

bergeron
Copy link
Contributor

@bergeron bergeron commented Oct 28, 2024

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

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

image

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

Open in GitHub Codespaces

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

Before

After

Pre-merge author checklist

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.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@bergeron bergeron marked this pull request as ready for review October 28, 2024 20:20
@bergeron bergeron requested a review from a team as a code owner October 28, 2024 20:20
@bergeron bergeron changed the title fix 0 token balance fix: 0 token balance in send flow Oct 28, 2024
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe parseInt(details.decimals) >= 0. I'm not sure when this can be something unexpected. The number check was introduced to replace a truthiness check, which did not work for 0 decimal tokens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did verify this PR still works for 0 decimal tokens

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also be false when balance === 0 - should change the details.balance to typeof details.balance, or is it typed well enough that we know that details.balance is never a number representation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont really know. Trying to make minimal changes when hotfixing things. The decimal check is the only bit that changed recently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its true that balance is a string in every place i can reproduce though

@metamaskbot
Copy link
Collaborator

Builds ready [40d7d3f]
Page Load Metrics (2081 ± 74 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint18882481209014871
domContentLoaded18472459203614670
load18852534208115374
domInteractive2494542010
backgroundConnect1178472411
firstReactRender502161064220
getState794312914
initialActions00000
loadScripts13671890151713263
setupStore13103422612
uiStartup207028992357238114
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: -5 Bytes (-0.00%)

@danjm danjm added this pull request to the merge queue Oct 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 29, 2024
@danjm danjm added this pull request to the merge queue Oct 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 29, 2024
@danjm danjm merged commit 1fd9510 into develop Oct 29, 2024
89 of 92 checks passed
@danjm danjm deleted the brian/null-token-balance branch October 29, 2024 13:45
@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2024
@metamaskbot metamaskbot added the release-12.7.0 Issue or pull request that will be included in release 12.7.0 label Oct 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.7.0 Issue or pull request that will be included in release 12.7.0 team-assets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Unable send any token after update Metamask to 12.5.0
5 participants