fix(frontend): say what an EVM transaction failed on instead of quoting the node - #14003
Draft
AntonioVentilii wants to merge 1 commit into
Draft
fix(frontend): say what an EVM transaction failed on instead of quoting the node#14003AntonioVentilii wants to merge 1 commit into
AntonioVentilii wants to merge 1 commit into
Conversation
…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.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.
17277is(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
eth-error.utils.ts, mirroring the existingsol-error.utils.ts: maps an error raised while broadcasting to a message the user can act on, and returnsundefinedfor anything it cannot explain so callers keep their own generic message.insufficient funds ...andgas required exceeds allowance (N), at any depth of thecause/error/infochain a provider wraps them in, plus ethers' ownINSUFFICIENT_FUNDScode. 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.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
eth-error.utils.spec.ts: the exact staging error, an insufficient-funds error nested underinfo, ethers' own code, acausechain, 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:testsandnpm run test(18799 tests) all pass.