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

Token amount sent displays 0 when input contains no decimals #21338

Merged
merged 1 commit into from
Oct 13, 2023

Conversation

salimtb
Copy link
Contributor

@salimtb salimtb commented Oct 12, 2023

Description

Description

Problem: After sending a token with an amount that doesn’t include decimals (ie 3, 5, 2), the transaction history displays the actual amount sent as 0. If the amount sent has a decimal (ie. 3.1, 0.2), this bug does not exist.

Expected Behavior: The amount I send should be reflected in the transaction history.

the problem is related to the fact that in Javascript , the boolean expression of 0 return false

Manual testing steps

1 - GIVEN I am on the "Activity" page
2 - AFTER I send a token with a decimal amount
3 - WHEN I view the previous transaction
4 - THEN I see the correct token amount sent

Before

sending-erc20-0decimals.mp4

After

Screen.Recording.2023-09-04.at.17.35.17.mov

Related issues

_Fixes #18139

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained:
    • What problem this PR is solving.
    • How this problem was solved.
    • How reviewers can test my changes.
  • I’ve indicated what issue this PR is linked to: Fixes #???
  • I’ve included tests if applicable.
  • I’ve documented any added code.
  • I’ve applied the right labels on the PR (see labeling guidelines).
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

@salimtb salimtb added the team-extension-ux DEPRECATED: please use "team-wallet-ux" label instead label Oct 12, 2023
@salimtb salimtb requested a review from a team as a code owner October 12, 2023 09:01
@github-actions
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.

@@ -43,7 +43,8 @@ export function useTokenDisplayValue(
// and a token object has been provided
token &&
// and the provided token object contains a defined decimal value we need to calculate amount
token.decimals &&
token.decimals !== null &&
token.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.

the problem is related to the fact that in Javascript , the boolean expression of 0 return false.

@metamaskbot
Copy link
Collaborator

Builds ready [4dd1249]
Page Load Metrics (966 ± 380 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint80149103189
domContentLoaded66143952411
load771946966792380
domInteractive66143952411
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 31 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (5deed0e) 68.68% compared to head (4dd1249) 68.69%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #21338   +/-   ##
========================================
  Coverage    68.68%   68.69%           
========================================
  Files         1019     1019           
  Lines        40878    40879    +1     
  Branches     10917    10918    +1     
========================================
+ Hits         28077    28078    +1     
  Misses       12801    12801           
Files Coverage Δ
ui/hooks/useTokenDisplayValue.js 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@salimtb salimtb merged commit 9d1bd43 into develop Oct 13, 2023
13 checks passed
@salimtb salimtb deleted the MMASSETS-1-fix-decimals-0-display branch October 13, 2023 15:12
@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2023
@metamaskbot metamaskbot added the release-11.5.0 Issue or pull request that will be included in release 11.5.0 label Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.5.0 Issue or pull request that will be included in release 11.5.0 team-extension-ux DEPRECATED: please use "team-wallet-ux" label instead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Sending an ERC20 with 0 decimals displays 0 tokens sent, despite sending the chosen amount
4 participants