Repository navigation
fix(ui): treat an empty amount as zero when building quote parameters - #1159
Open
devknight-ink wants to merge 1 commit into
Open
devknight-ink wants to merge 1 commit into
devknight-ink wants to merge 1 commit into
Conversation
Contributor
|
@devknight-ink is attempting to deploy a commit to the Uneven Labs Team on Vercel. A member of the Team first needs to authorize it. |
[Medium impact] The PR appears safe to merge.
|
This branch has not been deployed
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.
Problem
SwapWidgetRenderer,DepositAddressModalRendererandOnrampModalbuild their quote parameters eagerly on every render and call viem'sparseUnits()on the raw (debounced) amount input. That value is''on first mount (when nodefaultAmountis set), after the user clears the field, and after every completed swap (setAmountInputValue('')).viem ≤ 2.55.2 returned
0nforparseUnits(''). From viem 2.55.4 (utils/unit/Value.ts,from()), any value without a digit —'','.','-'— throwsValue.InvalidDecimalNumberError. Nothing catches it in the render path, so React unmounts the whole tree:The repo's own lockfile resolves viem 2.52.2, which is why the demo does not show it. Integrators on a current viem (
>=2.26.0is the declared peer range) see the widget crash on load or immediately after a swap.Reproduction: mount
<SwapWidget />with viem 2.57.x installed, delete the0in the amount field (or complete a swap).Fix
parseUnitsOrZero(value, decimals)toutils/numbers.ts: returns0nwhen the trimmed value consists only of-/./nothing (empty or mid-edit input), otherwise defers toparseUnits, so genuinely malformed input still throws as before.Verification
pnpm run typecheck(packages/ui),eslinton the changed files andscripts/lint-changesets.mjspass.parseUnitsparseUnitsOrZero'','.','-',undefined0n'0.','0.01','12.5',5'abc','1e3'Changeset included (patch,
@relayprotocol/relay-kit-ui).