From 477bdeaf9cd4a53ba4cc69784f5b6d4718b3655b Mon Sep 17 00:00:00 2001 From: thal0x Date: Wed, 8 Nov 2023 12:41:31 -0600 Subject: [PATCH 1/2] Add more descriptive errors for routes --- src/components/SwapWidget/SwapWidget.tsx | 6 ++-- src/components/SwapWidget/useSwapWidget.ts | 36 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/components/SwapWidget/SwapWidget.tsx b/src/components/SwapWidget/SwapWidget.tsx index d6f8c8dc..20520f3d 100644 --- a/src/components/SwapWidget/SwapWidget.tsx +++ b/src/components/SwapWidget/SwapWidget.tsx @@ -41,7 +41,7 @@ export const SwapWidget: FC = () => { onSourceAssetChange, onDestinationChainChange, onDestinationAssetChange, - noRouteFound, + routeError, } = useSwapWidget(); const { @@ -165,9 +165,9 @@ export const SwapWidget: FC = () => { numberOfTransactions={numberOfTransactions} /> )} - {noRouteFound && ( + {routeError !== "" && (
-

No route found

+

{routeError}

)} {destinationChain?.chainID === "dydx-mainnet-1" ? ( diff --git a/src/components/SwapWidget/useSwapWidget.ts b/src/components/SwapWidget/useSwapWidget.ts index b733d190..5ed94057 100644 --- a/src/components/SwapWidget/useSwapWidget.ts +++ b/src/components/SwapWidget/useSwapWidget.ts @@ -38,6 +38,7 @@ export function useSwapWidget() { data: routeResponse, fetchStatus: routeFetchStatus, isError: routeQueryIsError, + error: routeQueryError, } = useRoute( amountInWei, formValues.sourceAsset?.denom, @@ -47,6 +48,40 @@ export function useSwapWidget() { true, ); + // if (routeQueryError) { + // // get error message + // // @ts-expect-error TODO: fix this + // console.log(routeQueryError.message); + // } + + const errorMessage = useMemo(() => { + if (!routeQueryError) { + return ""; + } + + if (routeQueryError instanceof Error) { + if ( + routeQueryError.message.includes( + "no swap route found after axelar fee of", + ) + ) { + return "Amount is too low to cover Axelar fees"; + } + + if ( + routeQueryError.message.includes( + "evm native destination tokens are currently not supported", + ) + ) { + return "EVM native destination tokens are currently not supported"; + } + + return "Route not found"; + } + + return String(routeQueryError); + }, [routeQueryError]); + const numberOfTransactions = useMemo(() => { if (!routeResponse) { return 0; @@ -140,6 +175,7 @@ export function useSwapWidget() { onDestinationChainChange, onDestinationAssetChange, noRouteFound: routeQueryIsError, + routeError: errorMessage, }; } From 576180bfb86c97ce12fbe408a57dfd1be2ecd46e Mon Sep 17 00:00:00 2001 From: thal0x Date: Wed, 8 Nov 2023 12:43:38 -0600 Subject: [PATCH 2/2] remove dead code --- src/components/SwapWidget/useSwapWidget.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/components/SwapWidget/useSwapWidget.ts b/src/components/SwapWidget/useSwapWidget.ts index 5ed94057..07d8b75c 100644 --- a/src/components/SwapWidget/useSwapWidget.ts +++ b/src/components/SwapWidget/useSwapWidget.ts @@ -48,12 +48,6 @@ export function useSwapWidget() { true, ); - // if (routeQueryError) { - // // get error message - // // @ts-expect-error TODO: fix this - // console.log(routeQueryError.message); - // } - const errorMessage = useMemo(() => { if (!routeQueryError) { return "";