Skip to content

Commit

Permalink
Add custom error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sairamplex committed May 6, 2024
1 parent 847fc4c commit 9ee38d6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/transactions/TxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -120,7 +120,7 @@ const TxItem = (props: TxItemProps) => {
)}
{props.tx.error && (
<Text size="sm" style={{ color: "var(--extra-failure-color,red)" }}>
{formatError(props.tx.error)}
{parseError(props.tx)}
</Text>
)}
</div>
Expand Down
35 changes: 35 additions & 0 deletions utils/formatting/errors.utils.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}

0 comments on commit 9ee38d6

Please sign in to comment.