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

[Bug]: cannot send tokens with decimals > 20 #14481

Closed
think-in-universe opened this issue Apr 20, 2022 · 2 comments · Fixed by #21147
Closed

[Bug]: cannot send tokens with decimals > 20 #14481

think-in-universe opened this issue Apr 20, 2022 · 2 comments · Fixed by #21147
Assignees
Labels
area-customNetworks area-transactions release-11.4.0 Issue or pull request that will be included in release 11.4.0 team-assets type-enhancement

Comments

@think-in-universe
Copy link

think-in-universe commented Apr 20, 2022

Describe the bug

Problem

When I'm trying to transfer $NEAR (also called WNEAR) in Aurora mainnet network, I cannot input the amount in the Send page in MetaMask. No matter what number I input, the value on the Send page will be 0. So I cannot transfer any $NEAR token in Aurora network with MetaMask.

image

Analysis

The the issue is that when converting the value in the below function, the rate will become 0, and make the returned convertedValue to be 0 always.

if (invertConversionRate) {
rate = new BigNumber(1.0).div(conversionRate);
}
convertedValue = convertedValue.times(rate);

The root cause is, in LINE 118, conversionRate is 1e24 because $NEAR's decimals is 24, but the default DECIMAL_PLACES of BigNumber is 20, as stated here https://mikemcl.github.io/bignumber.js/#decimal-places

Default value: 20
The maximum number of decimal places of the results of operations involving division, i.e. division, square root and base conversion operations, and power operations with negative exponents.

As a result, any number smaller than 1e-20 will become 0. That's why any input for $NEAR amount will become 0.

A quick fix is to specify a large enough DECIMAL_PLACES in BigNumber.

BigNumber.config({ DECIMAL_PLACES: 32 })

Reference

Steps to reproduce

We can reproduce the issue on Aurora testnet:

  1. Create a NEAR testnet account on: https://wallet.testnet.near.org/
  2. Transfer some $NEAR from your NEAR account to Aurora account with Rainbow Bridge: https://testnet.rainbowbridge.app/ (you will need to connect to both NEAR and Aurora accounts, and then you can start the transfer)
  3. Try to transfer your $NEAR on Aurora to another account in MetaMask

Error messages or log output

No

Version

10.12.4

Build type

No response

Browser

Chrome

Operating system

MacOS

Hardware wallet

No response

Additional context

Besides $NEAR, this should also happen to other tokens on Aurora with decimals = 24

@jatubio
Copy link

jatubio commented Jun 11, 2022

I have the same problem. Is it solved?

@bschorchit bschorchit removed the bug label Jun 13, 2022
@dbale-altoros
Copy link

I also have the same problem when using metamask with this token
0xE39A5100B5B5b9985c5338B873eE2B10D5C36A7a on GOERLI
And also with this one
0x265C681aA55E8483e04788902e9190bd03a7f443 on MUMBAI

Is there any fix ?

@salimtb salimtb self-assigned this Oct 2, 2023
@salimtb salimtb linked a pull request Oct 2, 2023 that will close this issue
14 tasks
salimtb added a commit that referenced this issue Oct 11, 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**


https://github.com/MetaMask/metamask-extension/assets/26223211/b96d65b8-2373-49ee-ab11-ee737187d08d

### **After**


https://github.com/MetaMask/metamask-extension/assets/26223211/afef0d44-b6a0-4b24-9880-084cd7ffa7d3

## **Related issues**

_Fixes #14481

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained:
  - [x] What problem this PR is solving.
  - [x] How this problem was solved.
  - [x] How reviewers can test my changes.
- [x] I’ve indicated what issue this PR is linked to: Fixes #???
- [x] I’ve included tests if applicable.
- [ ] I’ve documented any added code.
- [x] 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)).
- [x] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] 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.
@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
k-g-j pushed a commit that referenced this issue Nov 1, 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**


https://github.com/MetaMask/metamask-extension/assets/26223211/b96d65b8-2373-49ee-ab11-ee737187d08d

### **After**


https://github.com/MetaMask/metamask-extension/assets/26223211/afef0d44-b6a0-4b24-9880-084cd7ffa7d3

## **Related issues**

_Fixes #14481

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained:
  - [x] What problem this PR is solving.
  - [x] How this problem was solved.
  - [x] How reviewers can test my changes.
- [x] I’ve indicated what issue this PR is linked to: Fixes #???
- [x] I’ve included tests if applicable.
- [ ] I’ve documented any added code.
- [x] 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)).
- [x] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-customNetworks area-transactions release-11.4.0 Issue or pull request that will be included in release 11.4.0 team-assets type-enhancement
Projects
None yet
7 participants