-
Notifications
You must be signed in to change notification settings - Fork 16
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: Support converting small number to AmountTokenV2 #496
Conversation
@dskloetd I added a test that it's broken with the current implementation, but I feel it should work. I propose to support scientific notation like in TokenAmount. |
size-limit report 📦
|
I think the problem is the ic-js/packages/utils/src/parser/token.ts Line 203 in ac1bbf0
That should be |
Hm, now I'm not sure.
On the other hand, if we really want to support 18 decimals, we simply can't use the I think I prefer hard-coding |
That's a good idea, we anyway agreed to set the precision to 8 decimals. I used |
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.
Can you fix the PR title and description as well?
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.
Asking again: Can you fix the PR title and description as well?
@dskloetd ready for another review |
Are these not coming through?
|
Oops, sorry. I wasn't seeing them because they were not in any file and I looked only to the comments in the files. |
@dskloetd ready for another review |
When I look, the PR title is still "Fix: Add test that is broken". |
Sorry, again, my bad. I'm a little bit all over the place this week. |
Motivation
TokenAmountV2 can't convert small numbers such as
0.00000002
which is 2 e8s of ICP.The problem was that
fromNumber
was usingtoString
andtoString
was converting0.00000002
to the scientific notation. Which we specifically don't want to support when converting from a string.Solution, use
toFixed(8)
instead oftoString
. We already support only a precision of 8 decimals.Changes
toFixed(8)
instead oftoString
infromNumber
of TokenAmountV2.Tests
"does not support scientific notation"
to do itfromString
.fromNumber
with very small numbers.fromNumber
to check that precision is 8 decimals.Todos