Skip to content

Commit 702be7b

Browse files
authored
do not use any liquidity guards for repay and fix approval requirement window refocus or swap input change (#2772)
1 parent d39f8ce commit 702be7b

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

src/components/transactions/Swap/errors/shared/SupplyCapBlockingGuard.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import { valueToBigNumber } from '@aave/math-utils';
22
import { SxProps } from '@mui/material';
33
import { Dispatch, useEffect } from 'react';
44

5-
import { ActionsBlockedReason, ProtocolSwapState, SwapError, SwapState } from '../../types';
5+
import {
6+
ActionsBlockedReason,
7+
ProtocolSwapState,
8+
SwapError,
9+
SwapState,
10+
SwapType,
11+
} from '../../types';
612
import { isProtocolSwapState } from '../../types/state.types';
713
import { SupplyCapBlockingError } from './SupplyCapBlockingError';
814

915
export const hasSupplyCapBlocking = (state: SwapState) => {
10-
if (!isProtocolSwapState(state)) return false;
16+
if (!isProtocolSwapState(state) || state.swapType === SwapType.RepayWithCollateral) return false;
1117
const reserve = state.isInvertedSwap
1218
? state.sourceReserve?.reserve
1319
: state.destinationReserve?.reserve;

src/components/transactions/Swap/errors/shared/ZeroLTVBlockingGuard.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import { SxProps } from '@mui/material';
22
import React, { Dispatch, useEffect } from 'react';
33
import { useZeroLTVBlockingWithdraw } from 'src/hooks/useZeroLTVBlockingWithdraw';
44

5-
import { ActionsBlockedReason, SwapError, SwapState } from '../../types';
5+
import { ActionsBlockedReason, SwapError, SwapState, SwapType } from '../../types';
66
import { ZeroLTVBlockingError } from './ZeroLTVBlockingError';
77

88
export const hasZeroLTVBlocking = (state: SwapState, blockingAssets: string[]) => {
9-
return blockingAssets.length > 0 && !blockingAssets.includes(state.sourceToken.symbol);
9+
return (
10+
blockingAssets.length > 0 &&
11+
!blockingAssets.includes(state.sourceToken.symbol) &&
12+
state.swapType !== SwapType.RepayWithCollateral
13+
);
1014
};
1115

1216
export const ZeroLTVBlockingGuard = ({

src/components/transactions/Swap/hooks/useSwapQuote.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,15 @@ const useMultiProviderSwapQuoteQuery = ({
433433
!state.mainTxState.txHash && // Don't fetch quotes once transaction is sent
434434
!state.mainTxState.loading && // Don't fetch quotes while transaction is processing
435435
!approvalTxState?.loading && // Don't fetch quotes while approval is processing
436+
!approvalTxState?.success && // Don't fetch quotes while approval is successful
437+
!state.quoteRefreshPaused && // Respect paused refresh state (e.g. after approval or manual edits)
436438
provider !== SwapProvider.NONE &&
437439
!state.isWrongNetwork
438440
);
439441
})(),
440442
retry: 0,
441443
throwOnError: false,
444+
refetchOnWindowFocus: false,
442445
refetchInterval: (() => {
443446
const isInsufficientBalance = hasInsufficientBalance(state);
444447
const isFlashloanDisabled = hasFlashLoanDisabled(state);

src/components/transactions/Swap/inputs/SwapInputs.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BigNumberValue, valueToBigNumber } from '@aave/math-utils';
22
import { WRAPPED_NATIVE_CURRENCIES } from '@cowprotocol/cow-sdk';
33
import { useQueryClient } from '@tanstack/react-query';
44
import { Dispatch, useEffect, useMemo } from 'react';
5+
import { useModalContext } from 'src/hooks/useModal';
56
import { useRootStore } from 'src/store/root';
67
import { queryKeysFactory } from 'src/ui-config/queries';
78

@@ -54,6 +55,7 @@ export const SwapInputs = ({
5455
setState: Dispatch<Partial<SwapState>>;
5556
trackingHandlers: TrackAnalyticsHandlers;
5657
}) => {
58+
const { setApprovalTxState, approvalTxState } = useModalContext();
5759
const resetErrorsAndWarnings = () => {
5860
setState({
5961
error: undefined,
@@ -65,6 +67,14 @@ export const SwapInputs = ({
6567

6668
const handleInputChange = (value: string) => {
6769
resetErrorsAndWarnings();
70+
// Changing amounts invalidates any prior approval
71+
if (approvalTxState?.txHash || approvalTxState?.success || approvalTxState?.loading) {
72+
setApprovalTxState({
73+
txHash: undefined,
74+
loading: false,
75+
success: false,
76+
});
77+
}
6878

6979
// Calculate USD per token unit if possible
7080
const usdPerToken = state.swapRate?.srcTokenPriceUsd;
@@ -122,6 +132,14 @@ export const SwapInputs = ({
122132

123133
const computeUSD = (amt: string) =>
124134
usdPerToken ? valueToBigNumber(amt).multipliedBy(usdPerToken).toString(10) : '';
135+
// Changing amounts invalidates any prior approval
136+
if (approvalTxState?.txHash || approvalTxState?.success || approvalTxState?.loading) {
137+
setApprovalTxState({
138+
txHash: undefined,
139+
loading: false,
140+
success: false,
141+
});
142+
}
125143

126144
if (state.swapRate) {
127145
// Block quote refreshs if user is changing the output amount after getting quotes

0 commit comments

Comments
 (0)