Skip to content

fix(send): use live token balance and preserve precision on Max#2098

Merged
MusabShakeel576 merged 1 commit into
masterfrom
claude/inspiring-hamilton-ZvZYP-master
May 26, 2026
Merged

fix(send): use live token balance and preserve precision on Max#2098
MusabShakeel576 merged 1 commit into
masterfrom
claude/inspiring-hamilton-ZvZYP-master

Conversation

@MusabShakeel576
Copy link
Copy Markdown
Contributor

Cherry-pick of ecbc1f9 from qa (#2097) to master.

Summary

  • Drop wagmi's useBalance in SendForm and source balance from useWalletTokens — the same query the token picker uses (5s polling + SSE-invalidated). After a previous send the picker showed the fresh balance but SendForm showed wagmi's stale cache (QueryClient default staleTime is 5 minutes and the safe-account send flow doesn't go through useTransactionAwait to invalidate it).
  • Build the Max-button amount with formatUnits(BigInt(balance), decimals) instead of balanceAmount.toString() on a JS Number. For balances whose low-order wei round up when squeezed into a float64 (e.g. 999999999999999999n"1"1000000000000000000n, 1 wei above the actual balance), parseUnits later produced a transfer amount above the on-chain balance and the transfer reverted — while Send stayed enabled because the Zod check was a JS-Number compare.
  • Validate amount <= balance in wei via parseUnits so the Send button can't enable for amounts that round above the balance after parseUnits rounding. Also drop the .transform(val => Number(val)) step so the precision-perfect amount string isn't laundered through a Number before reaching useSend.

Test plan

  • Token picker and send screen show the same balance for a token immediately after a previous send (no stale wagmi cache).
  • Tapping Max on a token with sub-display-precision wei produces an amount that the smart-account send completes successfully (no insufficient-balance revert).
  • Entering an amount above the balance keeps the Review button disabled and shows the "Available balance is …" error.
  • Entering 0 or empty keeps Review disabled.

Generated by Claude Code

The send form pulled balance from wagmi's useBalance, which has a 5-minute
default staleTime in the app's QueryClient and isn't invalidated by the
safe-account send flow (useSend doesn't go through useTransactionAwait).
After a previous send, the token picker — fed by useWalletTokens (5s
polling + SSE-invalidated) — showed the fresh balance, but selecting a
token brought the user back to a SendForm displaying wagmi's stale cache.

Drop wagmi's useBalance and source the balance from useWalletTokens
instead, looking up the live token by contractAddress + chainId. The
picker and the send screen now read from the same query.

Max button also lost precision: it did `balanceAmount.toString()` where
balanceAmount was Number(formatUnits(wei, decimals)). For balances whose
low-order wei round up when squeezed into a float64, parseUnits later
produced a BigInt above the actual on-chain balance and the transfer
reverted — while Send stayed enabled because the Zod check was a JS-Number
compare. Build the max string from the wei BigInt via formatUnits so it
round-trips through parseUnits exactly, and validate amount <= balance in
wei so the button can't enable for amounts that exceed the balance after
rounding.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
solid-app Ignored Ignored May 26, 2026 1:15pm
solid-app-staging Ignored Ignored May 26, 2026 1:15pm

Request Review

@MusabShakeel576 MusabShakeel576 merged commit 5b20397 into master May 26, 2026
4 of 5 checks passed
@MusabShakeel576 MusabShakeel576 deleted the claude/inspiring-hamilton-ZvZYP-master branch May 26, 2026 13:22
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