Skip to content

refactor(wallet): migrate to strict parseTokenAmount + drop dup currency util (S2, #611)#383

Merged
KruGoL merged 1 commit into
mainfrom
feat/currency-strict-migration
Jun 18, 2026
Merged

refactor(wallet): migrate to strict parseTokenAmount + drop dup currency util (S2, #611)#383
KruGoL merged 1 commit into
mainfrom
feat/currency-strict-migration

Conversation

@KruGoL

@KruGoL KruGoL commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

What

Migrates the Sphere wallet to the strict amount parser shipped in sphere-sdk@0.10.3 (parseTokenAmount / safeParseTokenAmount), and removes a duplicate currency util. Part of #611 — track S2.

sphere-sdk@0.10.3 removed the lenient toSmallestUnit (silent 0n / truncation). This PR bumps the SDK pin and migrates every call site.

Changes

  • Pin @unicitylabs/sphere-sdk 0.10.20.10.3.
  • Submit / build-amount → parseTokenAmount (throws on invalid; caught by the existing try/catch as a clean error):
    • SendModal (handleSend), SendPaymentRequestModal (handleSend), SwapModal (handleSwap), useTopUp.
  • Live / keystroke / render → safeParseTokenAmount (null = not a valid amount → button disabled / no proceed; no crash, no silent 0n):
    • SendModal (handleDetailsNext validation + the render-time insufficient-balance check), SendPaymentRequestModal (validation).
  • Deleted src/components/wallet/L3/utils/currency.ts — a dead duplicate of the SDK helpers (CurrencyUtils, unused) plus a lossy parseFloat/Math.pow AmountFormatUtils.formatDisplayAmount (its single consumer, PaymentRequestModal, now uses the SDK's bigint-safe formatAmount).

Verification

  • tsc -b → clean (exit 0). It caught one real bug during migration — useTopUp passed a number to the now string-only parser; fixed with String(human).
  • eslint → clean.

Notes

…ount; drop dup currency util

Adopts sphere-sdk 0.10.3 (parseTokenAmount/safeParseTokenAmount; lenient toSmallestUnit removed).

- Bump @unicitylabs/sphere-sdk 0.10.2 -> 0.10.3.
- Submit/build paths -> parseTokenAmount (throws on invalid; caught as a clean error):
  SendModal (handleSend), SendPaymentRequestModal (handleSend), SwapModal (handleSwap), useTopUp.
- Live/keystroke/render paths -> safeParseTokenAmount (null = not a valid amount; no crash,
  no silent 0n): SendModal (validate + insufficient-balance), SendPaymentRequestModal (validate).
- Delete duplicate src/components/wallet/L3/utils/currency.ts (dead CurrencyUtils copy + lossy
  parseFloat-based AmountFormatUtils.formatDisplayAmount); PaymentRequestModal now uses SDK formatAmount.

Part of #611 (track S2).
@KruGoL KruGoL merged commit d0f950b into main Jun 18, 2026
7 checks passed
@KruGoL KruGoL deleted the feat/currency-strict-migration branch June 18, 2026 23:55
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.

2 participants