Skip to content

Commit

Permalink
♻️ Refactor swap button to show insuficient liquidity on empty agrega…
Browse files Browse the repository at this point in the history
…tor distributions
  • Loading branch information
MattPoblete committed Oct 9, 2024
1 parent 4efc5e6 commit 3ed55a5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/hooks/useSwapMainButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3ed55a5

Please sign in to comment.