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(connext): avoid scientific notation for amount #1905

Merged
merged 1 commit into from
Sep 18, 2020

Conversation

sangaman
Copy link
Collaborator

This changes the way we convert numbers to strings when building requests to send to the Connext client by using toLocaleString instead of toString to avoid representing large numbers with scientific notation.

This should help with issues we've faced using toknes that deal with larger quantities like DAI.

An example of how toLocaleString compares with toString as well as bigint:

const x = 1725000000000000000000; // 1725 DAI in wei units
const bigX = 1725000000000000000000n;

console.log(x.toString());                                          // 1.725e+21
console.log(x.toLocaleString('fullwide', { useGrouping: false }));  // 1725000000000000000000
console.log(bigX.toString());                                       // 1725000000000000000000

const y = x + 1;
console.log(y.toLocaleString('fullwide', { useGrouping: false }));  // 1725000000000000000000
// but we will never be making payments with wei-level precision, xud only uses up to 8 digits to right of decimal point
// the approach above gives us up to 16 digits of precision, which is on the order of 100 million + 8 decimal places of precision

This changes the way we convert numbers to strings when building
requests to send to the Connext client by using `toLocaleString` instead
of `toString` to avoid representing large numbers with scientific
notation.
@sangaman sangaman added bug Something isn't working connext labels Sep 17, 2020
@sangaman sangaman requested a review from a user September 17, 2020 17:13
@sangaman sangaman self-assigned this Sep 17, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@raladev raladev self-requested a review September 18, 2020 11:08
@raladev raladev merged commit cc1e689 into master Sep 18, 2020
@ghost ghost deleted the fix/connext-scientific-notation branch September 18, 2020 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working connext
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants