From 9ee38d6180b6cbb7f233eba31dba1a2fc753c372 Mon Sep 17 00:00:00 2001 From: Sairam kola Date: Mon, 6 May 2024 16:00:21 +0530 Subject: [PATCH 1/2] Add custom error messages --- components/transactions/TxItem.tsx | 4 ++-- utils/formatting/errors.utils.ts | 35 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/components/transactions/TxItem.tsx b/components/transactions/TxItem.tsx index a31e7cbc..dc6651f0 100644 --- a/components/transactions/TxItem.tsx +++ b/components/transactions/TxItem.tsx @@ -5,8 +5,8 @@ import Container from "../container/container"; import Spacer from "../layout/spacer"; import { dateToMomentsAgo, - formatError, formatSecondsToMinutes, + parseError, } from "@/utils/formatting"; import StatusIcon from "../icon/statusIcon"; import { useQuery } from "react-query"; @@ -120,7 +120,7 @@ const TxItem = (props: TxItemProps) => { )} {props.tx.error && ( - {formatError(props.tx.error)} + {parseError(props.tx)} )} diff --git a/utils/formatting/errors.utils.ts b/utils/formatting/errors.utils.ts index 45d60aa6..960e9057 100644 --- a/utils/formatting/errors.utils.ts +++ b/utils/formatting/errors.utils.ts @@ -1,3 +1,8 @@ +import { TransactionWithStatus } from "@/transactions/interfaces"; +import { + CantoFETxType +} from "@/transactions/interfaces"; + /** * @notice Formats an error message to be more readable * @param {string} errorMsg Error message to format @@ -8,3 +13,33 @@ export function formatError(errorMsg: string): string { const split = errorMsg.split(":"); return "Error:" + split[split.length - 1]; } + + +export function parseError(tx: TransactionWithStatus): string { + const error = tx.error ?? "" + switch (tx.tx.feTxType) { + case CantoFETxType.ADD_LIQUIDITY_CANTO_DEX: + case CantoFETxType.REMOVE_LIQUIDITY_CANTO_DEX: + if((/BaseV1Router: INSUFFICIENT_(A|B)_AMOUNT/).test(error)){ + return "Error: Insufficient slippage"; + } + if((/BaseV1Router: EXPIRED/).test(error)){ + return "Error: Insufficient deadline"; + } + break; + case CantoFETxType.ADD_CONC_LIQUIDITY_AMBIENT: + case CantoFETxType.REMOVE_CONC_LIQUIDITY_AMBIENT: + if((/execution reverted: J/).test(error)){ + return "Error: Cannot remove liquidity, try after sometime"; + } + if((/execution reverted: RC/).test(error)){ + return "Error: Price not in given execution range"; + } + break; + default: + if((/not available/).test(error)){ + return "Error: Timeout"; + } + } + return formatError(error); +} From b5f35e2868ec823edddf0dba073116bf3dc917ea Mon Sep 17 00:00:00 2001 From: Sairam kola Date: Mon, 6 May 2024 22:13:00 +0530 Subject: [PATCH 2/2] update retry --- utils/cosmos/accountMeta.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cosmos/accountMeta.utils.ts b/utils/cosmos/accountMeta.utils.ts index 452dfc69..737ffcb9 100644 --- a/utils/cosmos/accountMeta.utils.ts +++ b/utils/cosmos/accountMeta.utils.ts @@ -29,7 +29,7 @@ export async function getCantoAccountMetaData( const { data, error } = await tryFetchWithRetry( `${cantoNetwork.restEndpoint}/cosmos/auth/v1beta1/accounts/${cantoAddress}`, - 5 + 2 ); if (error) throw error;