Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/pages/gd/Swap/SwapCore/mentoReserve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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),
Expand Down