fix: count the network fee in the confirm-screen balance check (closes #154)
All checks were successful
check / check (push) Successful in 35s

The Send button was enabled whenever the amount alone fit the balance, so
a max-value ETH send passed the confirmation screen and failed at
broadcast, after the user had committed to it.

The arithmetic moves into src/shared/txValidation.js as a pure function
over 18-decimal fixed point: native ETH now requires amount + fee <=
balance, and an ERC-20 transfer requires the ETH balance to cover the fee
on top of the token check, reported as its own error. Validation re-runs
when the async estimate resolves; Send stays disabled while the estimate
is pending and when it fails, so an unknown fee is never treated as zero.
The fee messages are static elements that already reserve their space, so
nothing moves when the estimate lands.

The fee reserved is the one the node will actually require. The send pins
no fee fields, so ethers broadcasts a type-2 transaction and the node
validates it against value + gasLimit * maxFeePerGas; gating on gasPrice
would under-reserve by roughly gasLimit * baseFee and let through exactly
the broadcast failure this change exists to prevent. feeReserveWei()
derives that reserve, falling back to gasPrice only where no type-2
pricing exists, and the fee shown on screen is the same figure so the
displayed number and the gate can never contradict each other.

validateTransfer() fails closed: a feeWei that is not a non-negative
bigint under FEE_KNOWN, and any unrecognised feeStatus, block exactly as
FEE_UNAVAILABLE does rather than counting as a fee of zero.
This commit is contained in:
clawbot
2026-08-11 12:19:52 +00:00
parent cf5f582be9
commit ce81596100
7 changed files with 606 additions and 49 deletions

View File

@@ -44,6 +44,11 @@ undefined identifiers, which is how
# Completed Steps
- 2026-08-11: Network fee counted in the confirmation-screen balance check for
both ETH and ERC-20 sends, reserving what the node actually charges a type-2
transaction, with the arithmetic in a pure, unit-tested
`src/shared/txValidation.js`
([#154](https://git.eeqj.de/sneak/AutistMask/issues/154)).
- 2026-08-11: Three `README.md` claims corrected against the code — blocklist
attribution, token-display rule, navigation model
([#213](https://git.eeqj.de/sneak/AutistMask/issues/213)).