diff --git a/packages/web/components/swap-tool/index.tsx b/packages/web/components/swap-tool/index.tsx index a67f57d083..db80c70b49 100644 --- a/packages/web/components/swap-tool/index.tsx +++ b/packages/web/components/swap-tool/index.tsx @@ -240,8 +240,10 @@ export const SwapTool: FunctionComponent = 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 ( diff --git a/packages/web/hooks/use-estimate-tx-fees.ts b/packages/web/hooks/use-estimate-tx-fees.ts index e7a24cb5f5..8a39d894b9 100644 --- a/packages/web/hooks/use-estimate-tx-fees.ts +++ b/packages/web/hooks/use-estimate-tx-fees.ts @@ -6,6 +6,7 @@ import { AccountStoreWallet, CosmosAccount, CosmwasmAccount, + InsufficientBalanceForFeeError, OsmosisAccount, SignOptions, } from "@osmosis-labs/stores"; @@ -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"; @@ -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({ max: 50 });