-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix: number is formatted wrong when a dot is a grouping separator #6428
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6428 +/- ##
==========================================
- Coverage 89.12% 89.11% -0.01%
==========================================
Files 735 735
Lines 31854 31856 +2
Branches 6051 6053 +2
==========================================
- Hits 28391 28390 -1
+ Misses 3416 3271 -145
- Partials 47 195 +148
... and 66 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
if (!Number.isNaN(+value)) { | ||
return value.endsWith(groupingSeparator) ? `${+value}` : value | ||
} |
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.
nit: I'm not a big fan of the +value
coercion trick as it can be confusing to read. I recommend we use BigNumber
for number parsing as it's the most predictable and supports arbitrary long numbers with no precision loss.
I think it could be simplified to this:
if (!Number.isNaN(+value)) { | |
return value.endsWith(groupingSeparator) ? `${+value}` : value | |
} | |
const numericValue = new BigNumber(value); | |
if (!numericValue.isNaN()) { | |
return numericValue.toFixed() | |
} |
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.
@jeanregisser I'll check if that's gonna be a 1 to 1 alternative and if so - will create another PR with it!
…6472) ### Description This PR again tries to fix an ongoing issue with formatting number for TokenEnterAmount component when number format in phone settings is set to `1.234,5678`. The issue was introduced by [previous attempt](#6428) to fix wrong formatting for Swap flow specifically. Previously, the issue was due to unformatting function only expecting numbers that are formatted according to the phone's settings. This caused an issue when on the Swap flow we set the value of "To" textfield with `replaceAmount` function using the value from the quote API response which was a JS-compatible number. This format differed for the users that had format set in settings to `1.234,5678` and caused the actual issue. But this introduced another issue with the wrong formatting for when the numbers that exceed `1000`. In order to fix this, the condition for whether there's a need to skip the formatting was moved to actual function that is used when replacing the value with the quote API response. I've also added some explanatory comments to some functions for better clarity on what's each function intention is. ### Test plan Edited e2e tests for Send to test proper formatting of big amounts while using `typeText` function which simulates actual typing instead of `replaceText` (which is more of a paste). This change doesn't revert the previous fix: https://github.com/user-attachments/assets/a5b913eb-f47c-4a5d-9fcf-1c704376c177 ### Related issues - Relates to [this PR](#6428) - Relates to the bug mentioned [here](https://valora-app.slack.com/archives/C04B61SJ6DS/p1738341507462059) ### Backwards compatibility Yes ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [x] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)
Description
When phone number format settings are set to "1.234.567,89" – the number formatting is all over the place. The issue was an
unformatNumberForProcessing
function which was only expecting numbers that were formatted according to the phone's number format settings while SwapScreenV2 was using numbers sent by a prepare transaction quote which are formatted as a regular JS number ("1234567.89").This PR fixes this issue.
Test plan
Related issues
N/A
Backwards compatibility
Yes
Network scalability
If a new NetworkId and/or Network are added in the future, the changes in this PR will: