fix(widget): stop formatInputAmount flipping a negative exponent - #871
Open
kriss39 wants to merge 1 commit into
Open
fix(widget): stop formatInputAmount flipping a negative exponent#871kriss39 wants to merge 1 commit into
kriss39 wants to merge 1 commit into
Conversation
The leading-zero cleanup stripped the minus with an unanchored alternation, `/^0+|-/`. With no `g` flag the engine skips past `^0+` when the value does not start with a zero and removes the first `-` it finds anywhere, which for an exponential value is the one in the exponent. `1e-1` normalized to `1e1` and `1e-7` to `1e7`. Only values whose whole string lands in the integer part are affected, so `2.5e-8` survived while `1e-1` did not, and the corruption appeared on blur rather than while typing. Anchor the sign strip to the start and expand exponential notation into plain decimal digits. The expansion shifts the point textually so no precision is lost, and it makes the value usable: parseUnits rejects every exponential string, `1e1` included, so leaving the value in that form only traded a wrong amount for a failing route request.
🦋 Changeset detectedLatest commit: 483a605 The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The leading-zero cleanup stripped the minus with an unanchored alternation,
/^0+|-/. With nogflag the engine skips past^0+when the value does not start with a zero and removes the first-it finds anywhere, which for an exponential value is the one in the exponent.1e-1normalized to1e1and1e-7to1e7.Only values whose whole string lands in the integer part are affected, so
2.5e-8survived while1e-1did not, and the corruption appeared on blur rather than while typing.Anchor the sign strip to the start and expand exponential notation into plain decimal digits. The expansion shifts the point textually so no precision is lost, and it makes the value usable: parseUnits rejects every exponential string,
1e1included, so leaving the value in that form only traded a wrong amount for a failing route request.Which Linear task is linked to this PR?
Why was it implemented this way?
Explain the reasoning behind the implementation. Were there alternative approaches? Why was this solution chosen?
Visual showcase (Screenshots or Videos)
If applicable, attach screenshots, GIFs, or videos to showcase the functionality, UI changes, or bug fixes.
Checklist before requesting a review