-
Notifications
You must be signed in to change notification settings - Fork 230
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: formatDecimals
precision
#912
Conversation
if (inputInDecimals) { | ||
return (Number(amount) / 10 ** decimals).toString(); | ||
// If input is already in decimals, convert to readable amount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we mean by "readable" amount?
@0xAlec could you rebase from main when you have a minute? With all our tests in order, it'll help our CI pass more easily. |
src/swap/utils/formatDecimals.ts
Outdated
} | ||
if (!/^(?:0|[1-9]\d*)(?:\.\d+)?$/.test(amount)) { | ||
throw new Error( | ||
'Invalid input: amount must be a non-negative number string', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the care for the messages.
19f7bdb
to
5214fb8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So niiiice
What changed? Why?
amount
from a string to a javascript number (max 64 bits), which would lose precision for some ERC-20 denominationsBigInt
implementationNotes to reviewers
How has it been tested?
improved test coverage compared to
main
unit tested and tested locally