Skip to content

fix(widget): stop formatInputAmount flipping a negative exponent - #871

Open
kriss39 wants to merge 1 commit into
lifinance:mainfrom
kriss39:fix/format-input-amount-exponent
Open

fix(widget): stop formatInputAmount flipping a negative exponent#871
kriss39 wants to merge 1 commit into
lifinance:mainfrom
kriss39:fix/format-input-amount-exponent

Conversation

@kriss39

@kriss39 kriss39 commented Sep 10, 2026

Copy link
Copy Markdown

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.

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

  • I have performed a self-review and testing of my code.
  • This pull request is focused and addresses a single problem.
  • If this PR modifies the Widget API or adds new features that require documentation, I have updated the documentation in the public-docs repository.

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-bot

changeset-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 483a605

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@lifi/widget Patch
@lifi/widget-checkout Patch
connectkit Patch
deposit-flow Patch
dynamic Patch
nextjs Patch
nextjs15 Patch
nft-checkout Patch
nuxt-app Patch
privy-ethers-example Patch
privy Patch
rainbowkit Patch
react-router Patch
remix Patch
reown Patch
svelte Patch
tanstack-router-example Patch
vite-project Patch
vue Patch
zustand-widget-config Patch

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

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.

1 participant