Skip to content

Commit

Permalink
show more specific error
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed May 30, 2024
1 parent a913744 commit c0fb283
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/web/components/swap-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(
swapState.isLoadingNetworkFee;

let buttonText: string;
if (swapState.error) {
buttonText = t(...tError(swapState.error));
if (swapState.error || swapState.estimateTxError) {
buttonText = t(
...tError(swapState?.error ?? swapState.estimateTxError ?? undefined)
);
} else if (showPriceImpactWarning) {
buttonText = t("swap.buttonError");
} else if (
Expand Down
16 changes: 15 additions & 1 deletion packages/web/hooks/use-estimate-tx-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AccountStoreWallet,
CosmosAccount,
CosmwasmAccount,
InsufficientBalanceForFeeError,
OsmosisAccount,
SignOptions,
} from "@osmosis-labs/stores";
Expand All @@ -14,6 +15,7 @@ import { isNil } from "@osmosis-labs/utils";
import { useQuery } from "@tanstack/react-query";
import cachified, { CacheEntry } from "cachified";
import { LRUCache } from "lru-cache";
import { useMemo } from "react";

import { useStore } from "~/stores";
import { api } from "~/utils/trpc";
Expand Down Expand Up @@ -115,7 +117,19 @@ export function useEstimateTxFees({
typeof wallet?.address === "string",
});

return queryResult;
const specificError = useMemo(() => {
if (
queryResult.error instanceof Error &&
queryResult.error.message.includes(
"No fee tokens found with sufficient balance on account"
)
) {
return new InsufficientBalanceForFeeError(queryResult.error.message);
}
return queryResult.error;
}, [queryResult.error]);

return { ...queryResult, error: specificError };
}

const getAssetCache = new LRUCache<string, CacheEntry>({ max: 50 });
Expand Down

0 comments on commit c0fb283

Please sign in to comment.