From be91a7bd4318b89777c04cf309a6ecc5b129b185 Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Tue, 8 Oct 2024 16:49:13 +0200 Subject: [PATCH] chore: add not enough gas error to generic error (#1150) * chore: add not enough gas error to generic error * chore: ignore error --- lib/shared/components/errors/GenericError.tsx | 12 ++++++++++++ lib/shared/utils/error-filters.ts | 12 +++++++++++- lib/shared/utils/query-errors.ts | 8 +++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/shared/components/errors/GenericError.tsx b/lib/shared/components/errors/GenericError.tsx index 6072ac94c..6a8bb2468 100644 --- a/lib/shared/components/errors/GenericError.tsx +++ b/lib/shared/components/errors/GenericError.tsx @@ -3,6 +3,7 @@ import { AlertProps, Text } from '@chakra-ui/react' import { ErrorAlert } from './ErrorAlert' import { + isNotEnoughGasError, isPausedError, isTooManyRequestsError, isUserRejectedError, @@ -55,6 +56,17 @@ export function GenericError({ error: _error, customErrorName, ...rest }: Props) ) } + if (isNotEnoughGasError(_error)) { + return ( + + + It looks like you don't have enough gas to complete this transaction. If you believe + this is a mistake, please report it in{' '} + our discord. + + + ) + } const errorMessage = error?.shortMessage || error.message if (errorMessage === 'RPC Request failed.' || errorMessage === 'An unknown RPC error occurred.') { diff --git a/lib/shared/utils/error-filters.ts b/lib/shared/utils/error-filters.ts index 6811ff2c1..8cdcf1daf 100644 --- a/lib/shared/utils/error-filters.ts +++ b/lib/shared/utils/error-filters.ts @@ -21,11 +21,21 @@ export function isViemHttpFetchError(error?: Error | null): boolean { - others */ export function isTooManyRequestsError(error?: Error | null): boolean { - console.log(error?.message) if (!error) return false return error.message.startsWith('HTTP request failed.') && error.message.includes('Status: 429') } +export function isNotEnoughGasError(error?: Error | null): boolean { + if (!error) return false + return isNotEnoughGasErrorMessage(error.message) +} + +export function isNotEnoughGasErrorMessage(errorMessage: string): boolean { + return errorMessage.startsWith( + 'The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account.' + ) +} + export function isPausedError(error?: Error | null): boolean { if (!error) return false return isPausedErrorMessage(error.message) diff --git a/lib/shared/utils/query-errors.ts b/lib/shared/utils/query-errors.ts index 82a163f1f..03f9289c8 100644 --- a/lib/shared/utils/query-errors.ts +++ b/lib/shared/utils/query-errors.ts @@ -6,7 +6,11 @@ import { Exception as SentryException, } from '@sentry/types' import { SentryError, ensureError } from './errors' -import { isPausedErrorMessage, isUserRejectedError } from './error-filters' +import { + isNotEnoughGasErrorMessage, + isPausedErrorMessage, + isUserRejectedError, +} from './error-filters' import { AddLiquidityParams, stringifyHumanAmountsIn, @@ -245,6 +249,8 @@ export function shouldIgnoreException(sentryException: SentryException) { export function shouldIgnore(message: string, stackTrace = ''): boolean { if (isUserRejectedError(new Error(message))) return true + if (isNotEnoughGasErrorMessage(message)) return true + /* Thrown from useWalletClient() when loading a pool page from scratch. It looks like is is caused by the useWalletClient call in AddTokenToWalletButton but it does not affect it's behavior.