From 3ed55a5fa1b2069fe512fe931e0cab3ae93a4b9c Mon Sep 17 00:00:00 2001 From: Matias Poblete <86752543+MattPoblete@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:34:01 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20swap=20button?= =?UTF-8?q?=20to=20show=20insuficient=20liquidity=20on=20empty=20agregator?= =?UTF-8?q?=20distributions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useSwapMainButton.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hooks/useSwapMainButton.ts b/src/hooks/useSwapMainButton.ts index 1378672a..a269ed25 100644 --- a/src/hooks/useSwapMainButton.ts +++ b/src/hooks/useSwapMainButton.ts @@ -7,6 +7,7 @@ import { Field } from 'state/swap/actions'; import { relevantTokensType } from './useBalances'; import useGetMyBalances from './useGetMyBalances'; import useGetNativeTokenBalance from './useGetNativeTokenBalance'; +import { useAggregator } from './useAggregator'; interface Props { currencies: any; @@ -34,6 +35,7 @@ const useSwapMainButton = ({ const { isConnectWalletModalOpen, setConnectWalletModalOpen } = ConnectWalletModal; const { data } = useGetNativeTokenBalance(); const { availableNativeBalance } = useGetMyBalances(); + const { isEnabled: aggregatorEnabled } = useAggregator(); const { address } = sorobanContext; const userBalances = useGetMyBalances(); @@ -66,9 +68,14 @@ const useSwapMainButton = ({ Number(inputA) > Number(balanceA) ? currencyA?.code : undefined; const invalidAmount = Number(inputA) < 0 || Number(inputB) < 0; - - const insufficientLiquidity = !noAmountTyped && !trade; - + let insufficientLiquidity = !noAmountTyped && !trade; + if(aggregatorEnabled){ + const distribution = trade?.distribution; + if (distribution?.every((d) => d.path.length === 0)) { + insufficientLiquidity = true; + } + } + return { currencyA, currencyB,