Skip to content

Commit 958a916

Browse files
committed
backend/eth: return ErrInsufficientFunds if gas estimation failed
Similar to 7a25ac8. EtherScan returns this error during when estimating the gas if there are not enough funds to pay for the transaction. This is likely a change in behavior in Etherscan, as the check below `// Check that the entered value and the estimated fee are not greater than the balance.` used to work. We keep that code in case we move away from Etherscan or Etherscan changes the behavior and returns a gas anyway. This is not a robust check as it compares strings, but it is the best we can do for now.
1 parent 2799e57 commit 958a916

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

backend/coins/eth/account.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/coin"
3232
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/eth/db"
3333
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/eth/erc20"
34+
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/eth/etherscan"
3435
ethtypes "github.com/digitalbitbox/bitbox-wallet-app/backend/coins/eth/types"
3536
"github.com/digitalbitbox/bitbox-wallet-app/backend/signing"
3637
"github.com/digitalbitbox/bitbox-wallet-app/util/errp"
@@ -514,6 +515,9 @@ func (account *Account) newTx(args *accounts.TxProposalArgs) (*TxProposal, error
514515
}
515516
gasLimit, err := account.coin.client.EstimateGas(context.TODO(), message)
516517
if err != nil {
518+
if strings.Contains(err.Error(), etherscan.ERC20GasErr) {
519+
return nil, errp.WithStack(errors.ErrInsufficientFunds)
520+
}
517521
account.log.WithError(err).Error("Could not estimate the gas limit.")
518522
return nil, errp.WithStack(errors.TxValidationError(err.Error()))
519523
}

0 commit comments

Comments
 (0)