Skip to content

fix(ui): treat an empty amount as zero when building quote parameters - #1159

Open
devknight-ink wants to merge 1 commit into
relayprotocol:mainfrom
devknight-ink:fix/ui-empty-amount-as-zero
Open

devknight-ink wants to merge 1 commit into
relayprotocol:mainfrom
devknight-ink:fix/ui-empty-amount-as-zero

Conversation

@devknight-ink

Copy link
Copy Markdown

Problem

SwapWidgetRenderer, DepositAddressModalRenderer and OnrampModal build their quote parameters eagerly on every render and call viem's parseUnits() on the raw (debounced) amount input. That value is '' on first mount (when no defaultAmount is set), after the user clears the field, and after every completed swap (setAmountInputValue('')).

viem ≤ 2.55.2 returned 0n for parseUnits(''). From viem 2.55.4 (utils/unit/Value.ts, from()), any value without a digit — '', '.', '-' — throws Value.InvalidDecimalNumberError. Nothing catches it in the render path, so React unmounts the whole tree:

Value.InvalidDecimalNumberError: Value '' is not a valid decimal number

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.0 is 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 the 0 in the amount field (or complete a swap).

Fix

  • Add parseUnitsOrZero(value, decimals) to utils/numbers.ts: returns 0n when the trimmed value consists only of -/./nothing (empty or mid-edit input), otherwise defers to parseUnits, so genuinely malformed input still throws as before.
  • Use it at the three quote-parameter call sites. The quote hooks were already disabled for a zero amount, so request behaviour is unchanged.

Verification

  • pnpm run typecheck (packages/ui), eslint on the changed files and scripts/lint-changesets.mjs pass.
  • Behaviour matrix against viem 2.57.10:
input parseUnits parseUnitsOrZero
'', '.', '-', undefined throws 0n
'0.', '0.01', '12.5', 5 ok same result
'abc', '1e3' throws still throws

Changeset included (patch, @relayprotocol/relay-kit-ui).

@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown
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.

@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The PR adds parseUnitsOrZero and uses it when building swap, deposit-address, and onramp quotes.

  • Quote amounts treat empty input as zero across three widget flows.

No actionable issues were found. Review checks were static; no runtime tests were run.

Reviews (1) · Last reviewed commit: "fix(ui): treat an empty amount as zero w..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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