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 TokenAmountV2.fromNumber for decimals < 8 #629

Merged
merged 5 commits into from
May 16, 2024

Conversation

dskloetd
Copy link
Collaborator

Motivation

When creating a TokenAmountV2 from a number, we first convert it to a string with 8 decimals.
When the number has more decimals, they are just truncated. But number input components in gix-components don't allow more than 8 decimals.
But when the token allows fewer than 8 decimals, this results in an error.
The happened to be one of the few combinations without a unit test but will be needed for ckUSDC.

Changes

When converting the number to a string with a fixed number of decimals, instead of always using 8 decimals, use the minimum of 8 and the number of decimals the token allows.

Tests

  1. Added a unit test.
  2. Tested in NNS dapp that this error no longer appears:
image

Todos

  • Add entry to changelog (if necessary).

@dskloetd dskloetd enabled auto-merge (squash) May 16, 2024 13:39
Copy link
Contributor

size-limit report 📦

Path Size
@dfinity/ckbtc 7.24 KB (0%)
@dfinity/cketh 2.94 KB (0%)
@dfinity/cmc 1.29 KB (0%)
@dfinity/ledger-icrc 3.6 KB (0%)
@dfinity/ledger-icp 14.73 KB (0%)
@dfinity/nns 34.58 KB (0%)
@dfinity/nns-proto 140.98 KB (0%)
@dfinity/sns 15.72 KB (0%)
@dfinity/utils 4.47 KB (+0.27% 🔺)
@dfinity/ic-management 2.58 KB (0%)

Copy link
Contributor

@mstrasinskis mstrasinskis left a comment

Choose a reason for hiding this comment

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

Thank you!

@dskloetd dskloetd merged commit 86a58da into main May 16, 2024
11 checks passed
@dskloetd dskloetd deleted the kloet/decimals-from-number branch May 16, 2024 13:47
@dskloetd dskloetd mentioned this pull request May 16, 2024
1 task
github-merge-queue bot pushed a commit to dfinity/nns-dapp that referenced this pull request May 16, 2024
# Motivation

Pull in the fix for tokens with <8 decimals (for ckUSDC) from
dfinity/ic-js#629

# Changes

Ran `npm run upgrade:next`.

# Tests

not tested

# Todos

- [ ] Add entry to changelog (if necessary).
not necessary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants