Skip to content

Commit

Permalink
fix quote loading state when wallet disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed Jun 3, 2024
1 parent efc859f commit 6b84367
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions packages/web/components/swap-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(
swapState.isQuoteLoading ||
swapState.isLoadingNetworkFee;

console.log(swapState.isLoadingNetworkFee, swapState.isQuoteLoading);

let buttonText: string;
if (swapState.error) {
buttonText = t(...tError(swapState.error));
Expand Down Expand Up @@ -985,8 +987,7 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(
loadingText={buttonText}
onClick={sendSwapTx}
>
{account?.walletStatus === WalletStatus.Connected ||
isSwapToolLoading ? (
{account?.walletStatus === WalletStatus.Connected ? (
buttonText
) : (
<h6 className="flex items-center gap-3">
Expand Down
17 changes: 11 additions & 6 deletions packages/web/hooks/use-swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ export function useSwap(
featureFlags.swapToolSimulateFee &&
!Boolean(precedentError) &&
!isQuoteLoading &&
Boolean(quote);
Boolean(quote) &&
Boolean(account?.address);
const {
data: networkFee,
error: networkFeeError,
Expand Down Expand Up @@ -783,9 +784,14 @@ function useSwapAmountInput({
gasAmount: gasAmount,
});

const balanceQuoteQueryEnabled =
!!inAmountInput.balance &&
!inAmountInput.balance?.toDec().isZero() &&
Boolean(swapAssets.fromAsset) &&
Boolean(swapAssets.toAsset);
const {
data: quoteForCurrentBalance,
isLoading: isQuoteForCurrentBalanceLoading,
isLoading: isQuoteForCurrentBalanceLoading_,
error: quoteForCurrentBalanceError,
} = useQueryRouterBestQuote(
{
Expand All @@ -795,11 +801,10 @@ function useSwapAmountInput({
forcePoolId: forceSwapInPoolId,
maxSlippage,
},
!!inAmountInput.balance &&
!inAmountInput.balance?.toDec().isZero() &&
Boolean(swapAssets.fromAsset) &&
Boolean(swapAssets.toAsset)
balanceQuoteQueryEnabled
);
const isQuoteForCurrentBalanceLoading =
isQuoteForCurrentBalanceLoading_ && balanceQuoteQueryEnabled;

const networkQueryEnabled =
featureFlags.swapToolSimulateFee &&
Expand Down

0 comments on commit 6b84367

Please sign in to comment.