Skip to content

fix(frontend): say what an EVM transaction failed on instead of quoting the node - #14003

Draft
AntonioVentilii wants to merge 1 commit into
av/eth-max-send-fresh-balancefrom
av/eth-send-balance-changed-error
Draft

fix(frontend): say what an EVM transaction failed on instead of quoting the node#14003
AntonioVentilii wants to merge 1 commit into
av/eth-max-send-fresh-balancefrom
av/eth-send-balance-changed-error

Conversation

@AntonioVentilii

Copy link
Copy Markdown
Collaborator

Motivation

Stacked on #14002. The two PRs below it stop a Max send from reserving more than the account holds. This one is about what the user is told when a transaction fails on the balance anyway, from a race those two do not cover or from a genuine shortfall.

Today they get the node's own text: could not coalesce error (error={ "code": -32000, "message": "gas required exceeds allowance (17277)" }, payload={...}, code=UNKNOWN_ERROR, version=6.17.0).

That message reads as a gas limit problem and is not one. 17277 is (balance - value) / maxFeePerGas, the gas the balance left over can still buy, so what the node is saying is that the balance is short. It sent the staging report straight to the fee logic, which had nothing to do with it. A user reading it has no way to know the thing to check is the amount.

Changes

  • New eth-error.utils.ts, mirroring the existing sol-error.utils.ts: maps an error raised while broadcasting to a message the user can act on, and returns undefined for anything it cannot explain so callers keep their own generic message.
  • Recognises both ways a node reports a balance it cannot pay from, insufficient funds ... and gas required exceeds allowance (N), at any depth of the cause / error / info chain a provider wraps them in, plus ethers' own INSUFFICIENT_FUNDS code. The allowance phrase is matched whole, since an ERC-20 revert says "transfer amount exceeds allowance" about an approval, which is a different failure with a different fix.
  • A recognised cause is shown on its own, with the RPC text sent to the console rather than appended to the message. An unexplained failure keeps the detail on screen, it being the only thing there is to report.
  • Applied wherever an EVM transaction is broadcast: send, NFT send, convert, swap, and the AI assistant send review.

New copy: "Your balance is not sufficient to cover this transaction and its network fee. It may have changed since it was last displayed, so please check the amount and try again."

Tests

  • New eth-error.utils.spec.ts: the exact staging error, an insufficient-funds error nested under info, ethers' own code, a cause chain, and the ERC-20 approval revert that must not borrow this message.
  • EthSendTokenWizard.spec.ts: a rejected broadcast shows the explanation without the node text appended.
  • npm run format, npm run lint -- --max-warnings 0, npm run check, npm run check:tests and npm run test (18799 tests) all pass.

…ng the node

A balance too small to cover a transaction reached the user as the node's
own text: "could not coalesce error (error={ code: -32000, message: gas
required exceeds allowance (17277) } ...)". It reads as a gas limit
problem and is not. The number is the gas the balance left over can still
buy, so the message says the balance is short, and the fix is to check
the amount rather than the fee.

Map that family of errors to a message that says so, and attach the node
text only when we have no explanation of our own. A recognised cause
still reaches the console for whoever has to diagnose it.
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.

1 participant