Skip to content

Commit 9a4cd1e

Browse files
committed
Checks for Polygon 'insufficient funds' error as well
1 parent 36096b8 commit 9a4cd1e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/errors/utils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import { EthereumRpcError } from 'eth-rpc-errors'
22

33
export function handleError(e: EthereumRpcError<unknown>): void {
4-
const msg = e.message
4+
// tries to parse Internal JSON RPC error, see https://eips.ethereum.org/EIPS/eip-1474#error-codes
5+
if (e.code === -32603) {
6+
e = e.data as EthereumRpcError<unknown>
7+
}
8+
9+
const msg = e.message || 'Something went wrong.'
510
// checks if the user has metamask installed
611
if (msg.includes('missing provider') || msg.includes('No provider found')) {
712
throw new Error(
813
'Please install the MetaMask extension. If you are on mobile, open your MetaMask app and browse to this page.'
914
)
1015
}
1116

12-
// ideally we would check for the error code here, but the same error code (-32000)
13-
// is used for more than one error type.
17+
// ideally we would check for the error code here, but the same error code: -32000 (Bad Input)
18+
// is used for more than one error type
1419
if (msg.includes('err: insufficient funds for gas * price + value')) {
15-
throw new Error('You do not have enough balance.')
20+
throw new Error('Your wallet does not have enough balance.')
1621
}
1722

18-
throw Error(e.message)
23+
throw Error(msg)
1924
}

0 commit comments

Comments
 (0)