fix(send): use string type for sendTokenAmount to preserve precision - #5618
Merged
Conversation
Fixes REOWN-3617: Send/Swap max amount of token throws transaction error Root cause: sendTokenAmount was typed as number, causing JavaScript floating-point precision loss (~15-16 significant digits). For tokens with 18 decimals, amounts like 1.234567890123456789 became 1.2345678901234568, causing gas estimation to fail when the slightly incorrect amount exceeded the actual balance. Changes: - Changed sendTokenAmount type from number to string in SendController - Updated onMaxClick() to pass string directly (no Number() conversion) - Updated onInputChange() to convert input to string - Added NumberUtil.bigNumber() for balance comparisons - Aligned with SwapController.sourceTokenAmount pattern Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
9 Skipped Deployments
|
|
Contributor
|
All contributors have signed the CTA ✍️ ✅ |
svenvoskamp
approved these changes
Apr 13, 2026
Contributor
Author
|
I have read the CTA Document and I hereby sign the CTA |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Fixes Send/Swap max amount of token throwing transaction errors due to JavaScript floating-point precision loss (REOWN-3617).
Technical Report
Problem
When sending the max amount of a token with 18 decimals, the transaction fails because the amount exceeds the actual on-chain balance. The sent amount differs from the intended amount due to JS number precision limits.
Root Cause Analysis
sendTokenAmount was typed as number throughout the send flow (SendController, UI components, event tracking). JavaScript numbers (IEEE 754 double-precision) can only represent ~15-16 significant digits accurately. Tokens with 18 decimals can require up to 18+ significant digits. For example, a balance of 1.123456789012345678 ETH would be truncated/rounded by JS number arithmetic, and the resulting amount could exceed the actual balance by a tiny margin — causing the transaction to revert.
The critical point was w3m-input-token's onMaxClick handler: maxValue.toFixed(20) produced the correct string, but wrapping it in Number(...) immediately lost precision before it reached SendController.
Approach & Reasoning
Changed sendTokenAmount from number to string across the entire flow:
Number() conversion only at boundaries where it's safe:
Critical EVM path preserved full precision:
Why string and not BigInt: The value needs to flow through UI input fields, Lit property bindings, and valtio state — all of which handle strings naturally. BigInt would require constant conversion at every UI boundary.
Files Changed
Verification
Test plan
🤖 Generated with Claude Code