diff --git a/src/pages/gd/Swap/SwapCore/mentoReserve.tsx b/src/pages/gd/Swap/SwapCore/mentoReserve.tsx index e0feb1017..8aa02849a 100644 --- a/src/pages/gd/Swap/SwapCore/mentoReserve.tsx +++ b/src/pages/gd/Swap/SwapCore/mentoReserve.tsx @@ -32,6 +32,9 @@ import useSendAnalyticsData from 'hooks/useSendAnalyticsData' import { useReserveToken } from 'hooks/useReserveToken' import { decodeTransactionErrorReason } from 'utils/transactionErrors' +const NONCE_METHOD_REGEX = /method\s*=\s*"nonce\(\)"/i +const CALL_EXCEPTION_REGEX = /call_exception/i + const MentoSwap = memo(() => { const CUSD = useReserveToken() const { i18n } = useLingui() @@ -112,13 +115,24 @@ const MentoSwap = memo(() => { const sendData = useSendAnalyticsData() useEffect(() => { - if (swap?.state?.status === 'Exception') { + const isSwapPreflightNonceException = Boolean( + swap?.state?.errorMessage && + CALL_EXCEPTION_REGEX.test(swap.state.errorMessage) && + NONCE_METHOD_REGEX.test(swap.state.errorMessage) + ) + const isApprovePreflightNonceException = Boolean( + approve?.state?.errorMessage && + CALL_EXCEPTION_REGEX.test(approve.state.errorMessage) && + NONCE_METHOD_REGEX.test(approve.state.errorMessage) + ) + + if (swap?.state?.status === 'Exception' && !isSwapPreflightNonceException) { setError({ message: i18n._(t`Swap transaction failed, please try again.`), reason: decodeTransactionErrorReason(swap.state.errorMessage), }) } - if (approve?.state?.status === 'Exception') { + if (approve?.state?.status === 'Exception' && !isApprovePreflightNonceException) { setError({ message: i18n._(t`Approve transaction failed, please try again.`), reason: decodeTransactionErrorReason(approve.state.errorMessage),