From 1a51278b6698b175ed4e3f71d07dc640bd3a1857 Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Wed, 4 Jun 2025 17:44:08 -0400 Subject: [PATCH] fix: display no routes found message --- .../src/hooks/useAmountValidation.ts | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/wormhole-connect/src/hooks/useAmountValidation.ts b/wormhole-connect/src/hooks/useAmountValidation.ts index f7bb9e538..c9b83e323 100644 --- a/wormhole-connect/src/hooks/useAmountValidation.ts +++ b/wormhole-connect/src/hooks/useAmountValidation.ts @@ -25,27 +25,30 @@ export const useAmountValidation = (props: Props): HookReturn => { // Min amount available const minAmount = useMemo( () => - Object.values(props.quotes).reduce((minAmount, quoteResult) => { - if (quoteResult?.success) { - return minAmount; - } - - if (!isMinAmountError(quoteResult?.error)) { - return minAmount; - } - - if (!minAmount) { - return quoteResult.error.min; - } - - const minAmountNum = BigInt(quoteResult.error.min.amount); - const existingMin = BigInt(minAmount.amount); - if (minAmountNum < existingMin) { - return quoteResult.error.min; - } else { - return minAmount; - } - }, undefined as sdkAmount.Amount | undefined), + Object.values(props.quotes).reduce( + (minAmount, quoteResult) => { + if (quoteResult?.success) { + return minAmount; + } + + if (!isMinAmountError(quoteResult?.error)) { + return minAmount; + } + + if (!minAmount) { + return quoteResult.error.min; + } + + const minAmountNum = BigInt(quoteResult.error.min.amount); + const existingMin = BigInt(minAmount.amount); + if (minAmountNum < existingMin) { + return quoteResult.error.min; + } else { + return minAmount; + } + }, + undefined as sdkAmount.Amount | undefined, + ), [props.quotes], ); @@ -59,8 +62,12 @@ export const useAmountValidation = (props: Props): HookReturn => { }); }, [props.routes, props.quotes]); + const noRoutes = useMemo(() => { + return props.routes.length === 0; + }, [props.routes]); + // Don't show errors when no amount is set or it's loading - if (!amount || props.disabled) { + if (!amount || props.disabled || props.isLoading) { return {}; } @@ -73,6 +80,12 @@ export const useAmountValidation = (props: Props): HookReturn => { } } + if (noRoutes) { + return { + error: 'No routes found for this transaction.', + }; + } + if (allRoutesFailed) { if (minAmount) { const formattedAmount = sdkAmount.display(minAmount);