Skip to content

Commit

Permalink
Merge pull request #560 from soroswap/fix/AggregatorSwap
Browse files Browse the repository at this point in the history
♻️ Refactor swap button
  • Loading branch information
esteblock authored Oct 22, 2024
2 parents 371b35f + 3ed55a5 commit bfce608
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 bfce608

Please sign in to comment.