Skip to content

Commit

Permalink
Merge pull request #90 from skip-mev/descriptive-route-errors
Browse files Browse the repository at this point in the history
Add more descriptive errors for routes
  • Loading branch information
thal0x authored Nov 8, 2023
2 parents 8c85cde + 576180b commit 67edff7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/SwapWidget/SwapWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const SwapWidget: FC = () => {
onSourceAssetChange,
onDestinationChainChange,
onDestinationAssetChange,
noRouteFound,
routeError,
} = useSwapWidget();

const {
Expand Down Expand Up @@ -165,9 +165,9 @@ export const SwapWidget: FC = () => {
numberOfTransactions={numberOfTransactions}
/>
)}
{noRouteFound && (
{routeError !== "" && (
<div className="bg-red-50 text-red-500 font-medium uppercase text-xs p-3 rounded-md flex items-center w-full text-left">
<p className="flex-1">No route found</p>
<p className="flex-1">{routeError}</p>
</div>
)}
{destinationChain?.chainID === "dydx-mainnet-1" ? (
Expand Down
30 changes: 30 additions & 0 deletions src/components/SwapWidget/useSwapWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function useSwapWidget() {
data: routeResponse,
fetchStatus: routeFetchStatus,
isError: routeQueryIsError,
error: routeQueryError,
} = useRoute(
amountInWei,
formValues.sourceAsset?.denom,
Expand All @@ -47,6 +48,34 @@ export function useSwapWidget() {
true,
);

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;
Expand Down Expand Up @@ -140,6 +169,7 @@ export function useSwapWidget() {
onDestinationChainChange,
onDestinationAssetChange,
noRouteFound: routeQueryIsError,
routeError: errorMessage,
};
}

Expand Down

0 comments on commit 67edff7

Please sign in to comment.