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: send tokens with decimals > 20 #21147

Merged
merged 7 commits into from
Oct 11, 2023
Merged

fix: send tokens with decimals > 20 #21147

merged 7 commits into from
Oct 11, 2023

Conversation

salimtb
Copy link
Contributor

@salimtb salimtb commented Oct 2, 2023

Description

Now MetaMask cannot send tokens with decimals larger than 20, this fix allows MetaMask to send tokens with tokens whose decimals <= 32.
the solution was to config bigNumber and set decimals to 36

Manual testing steps

1 - Import token with decimals > 20
2 - Try to send an amount of this token using the send button

Screenshots/Recordings

Before

before.mov

After

fix.mov

Related issues

_Fixes #14481

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 2, 2023
@salimtb salimtb requested a review from a team as a code owner October 2, 2023 13:09
@salimtb salimtb self-assigned this Oct 2, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

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.

@salimtb salimtb changed the title WIP - fix: send tokens with decimals > 20 DRAFT - fix: send tokens with decimals > 20 Oct 2, 2023
@salimtb salimtb linked an issue Oct 2, 2023 that may be closed by this pull request
@salimtb
Copy link
Contributor Author

salimtb commented Oct 2, 2023

I have read the CLA Document and I hereby sign the CLA

@codecov
Copy link

codecov bot commented Oct 2, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (a4e2610) 68.64% compared to head (e429962) 68.64%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #21147   +/-   ##
========================================
  Coverage    68.64%   68.64%           
========================================
  Files         1017     1017           
  Lines        40797    40799    +2     
  Branches     10893    10893           
========================================
+ Hits         28004    28006    +2     
  Misses       12793    12793           
Files Coverage Δ
shared/modules/Numeric.ts 93.29% <100.00%> (+0.08%) ⬆️

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

@metamaskbot
Copy link
Collaborator

Builds ready [6bb3947]
Page Load Metrics (1371 ± 310 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint86128104136
domContentLoaded7912798136
load9519871371646310
domInteractive7912798136
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

@salimtb salimtb changed the title DRAFT - fix: send tokens with decimals > 20 fix: send tokens with decimals > 20 Oct 2, 2023
@@ -733,14 +733,14 @@ describe('SwapsController', function () {
gasEstimateWithRefund: '0xb8cae',
savings: {
fee: '-0.061067',
metaMaskFee: '0.5050505050505050505',
metaMaskFee: '0.5050505050505050505050505050505',
Copy link
Contributor Author

@salimtb salimtb Oct 2, 2023

Choose a reason for hiding this comment

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

the swap-controller uses the Numiric module in the fetchAndSetQuotes function, which is why we get more digits here ( that's why the swap-controller was impacted ).
I wanted to know if I should introduce the decimal as a parameter of the Numeric module and create separated instances with specific config for each one in order to exclude the impact on the swap controller, and for that I want your opinion and suggestions first.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dan437 you are probably best to answer that one.

Copy link
Contributor

@legobeat legobeat Oct 3, 2023

Choose a reason for hiding this comment

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

I think this will affect all global usage of bignumber.js across the package, regardless of if through Numeric or not? May be missing something but don't see how one would parameterize or instantiate the module in a meaningful way..?

(This currently does not affect bignumber.js usage by dependencies, since they use different resolutions of the package. But if/when that dedupes through a bump of bignumber.js, they would then also be affected)

https://github.com/MetaMask/metamask-extension/pull/21147/files#diff-eff8f155372904667dee1ed92ee9bff47fd02c6e7ad6354ff150bf77d392b8d0R9

https://github.com/MikeMcl/bignumber.js/blob/e545d41b2f43874399101ac7ee5098093ac96b6b/bignumber.js#L2714

If you instantiate a new BigNumber constructor and exclusively use that inside Numeric, it should be possible to contain it, though, and an optional parameter could be added to the Numeric class constructor.

Copy link
Contributor

Choose a reason for hiding this comment

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

On the flip side, is it actually desired to have fewer decimal places in other places? Seems more reasonable that in cases where lower precision should be displayed, that this should be taken care of in the UI (e.g. as parameter to toString() when rendering)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @legobeat ,
thnx for your answer.
it's already computed in the UI in order to get lower precision.
i posted my comment here to mention that this will affect other module ( like swap-controller ) and the only way to avoid it is to use another bigNumber instance et use it exclusively in the Numeric package like you said.

but a question come to my mind , is that bad to have more precision ? i think a global change in the bigNumber module can be a good solution but i wanted to have other suggestions first.

Copy link
Contributor

@legobeat legobeat Oct 3, 2023

Choose a reason for hiding this comment

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

Lifting this to draft for now. @salimtb Feel free to undraft when there is a conclusion on what the preferred approach here is and the PR has been updated accordingly, if required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@legobeat i removed the draft , the conclusion was to add more precision and put max decimals to 36 ( we have the same limit in the core compoment )

@bergeron bergeron requested a review from jpuri October 2, 2023 16:09
@bergeron
Copy link
Contributor

bergeron commented Oct 2, 2023

Adding @jpuri who had a concern with this previous attempt: #14482 (comment)

@legobeat legobeat marked this pull request as draft October 3, 2023 13:14
@metamaskbot
Copy link
Collaborator

Builds ready [3bb9360]
Page Load Metrics (792 ± 370 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint88164101168
domContentLoaded7115693199
load831778792771370
domInteractive7115693199
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

@bergeron

This comment was marked as resolved.

@salimtb salimtb marked this pull request as ready for review October 5, 2023 08:53
@metamaskbot
Copy link
Collaborator

Builds ready [85bb3da]
Page Load Metrics (716 ± 394 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint891951182512
domContentLoaded771951082814
load902082716820394
domInteractive771951082814
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [85bb3da]
Page Load Metrics (716 ± 394 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint891951182512
domContentLoaded771951082814
load902082716820394
domInteractive771951082814
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [85bb3da]
Page Load Metrics (945 ± 371 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint85156101178
domContentLoaded7014996199
load791899945772371
domInteractive7014996189
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

@legobeat legobeat requested a review from brad-decker October 7, 2023 04:13
@metamaskbot
Copy link
Collaborator

Builds ready [b3f9718]
Page Load Metrics (956 ± 376 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint8012996136
domContentLoaded6512489126
load761933956783376
domInteractive6512489126
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [e429962]
Page Load Metrics (1081 ± 351 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint8413099136
domContentLoaded7312593147
load8317941081730351
domInteractive7312593147
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

@salimtb salimtb merged commit b649e43 into develop Oct 11, 2023
@salimtb salimtb deleted the MMASSETS-42 branch October 11, 2023 07:56
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2023
@metamaskbot metamaskbot added the release-11.4.0 Issue or pull request that will be included in release 11.4.0 label Oct 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.4.0 Issue or pull request that will be included in release 11.4.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]: cannot send tokens with decimals > 20
6 participants