Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor swap button #560

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading