fix: count the network fee in the confirm-screen balance check (closes #154)
All checks were successful
check / check (push) Successful in 26s
All checks were successful
check / check (push) Successful in 26s
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. The reserve is read when the screen opens and the broadcast derives its own, so a base fee that roughly doubles while the user is at the password field can still outrun it: this turns a deterministic failure on every max-value send into a rare one, not into none. The fee line shows both numbers rather than one - what the transfer is expected to cost, and below it the larger amount reserved until it confirms. Quoting only the reserve overstates the typical mainnet cost by roughly double on every send; quoting only the estimate contradicts the gate. The second line holds its space from the first paint. validateTransfer() fails closed: a feeWei that is not a non-negative bigint under FEE_KNOWN, any unrecognised feeStatus, and a negative amount all block, rather than counting as a fee of zero or as an amount that passes every comparison trivially.
This commit is contained in:
@@ -269,7 +269,10 @@ The confirmation screen shows:
|
||||
- **From and To addresses** with identicons and Etherscan links
|
||||
- **Amount** with USD estimate
|
||||
- **Your current balance** with USD estimate
|
||||
- **Estimated network fee** in ETH with USD estimate
|
||||
- **Network fee** — what the transfer is expected to cost, in ETH with a USD
|
||||
estimate, and below it the larger amount reserved until it confirms. The
|
||||
reserve is what the network requires up front and what the balance check gates
|
||||
on; the refund of the difference is why the two differ
|
||||
- **Warnings** if the recipient is a contract, a burn address, one of your own
|
||||
addresses, on the bundled scam-address list, or labelled as a phisher on
|
||||
Etherscan
|
||||
|
||||
Reference in New Issue
Block a user