diff --git a/src/components/MultiHopTrade/components/MultiHopTradeConfirm/hooks/useTradeNetworkFeeCryptoBaseUnit.tsx b/src/components/MultiHopTrade/components/MultiHopTradeConfirm/hooks/useTradeNetworkFeeCryptoBaseUnit.tsx index edc0f6a569e..8eba3341e1f 100644 --- a/src/components/MultiHopTrade/components/MultiHopTradeConfirm/hooks/useTradeNetworkFeeCryptoBaseUnit.tsx +++ b/src/components/MultiHopTrade/components/MultiHopTradeConfirm/hooks/useTradeNetworkFeeCryptoBaseUnit.tsx @@ -21,9 +21,11 @@ import { selectActiveQuote, selectActiveSwapperName, selectConfirmedTradeExecution, + selectHopExecutionMetadata, selectHopSellAccountId, selectTradeSlippagePercentageDecimal, } from 'state/slices/tradeQuoteSlice/selectors' +import { HopExecutionState, TransactionExecutionState } from 'state/slices/tradeQuoteSlice/types' import { useAppSelector } from 'state/store' export const useTradeNetworkFeeCryptoBaseUnit = ({ @@ -60,6 +62,24 @@ export const useTradeNetworkFeeCryptoBaseUnit = ({ const hop = useMemo(() => getHopByIndex(tradeQuote, hopIndex), [tradeQuote, hopIndex]) const swapper = useMemo(() => (swapperName ? swappers[swapperName] : undefined), [swapperName]) + const activeTrade = useAppSelector(selectActiveQuote) + const activeTradeId = activeTrade?.id + + const hopExecutionMetadataFilter = useMemo(() => { + if (!activeTradeId) return undefined + + return { + tradeId: activeTradeId, + hopIndex, + } + }, [activeTradeId, hopIndex]) + + const hopExecutionMetadata = useAppSelector(state => + hopExecutionMetadataFilter + ? selectHopExecutionMetadata(state, hopExecutionMetadataFilter) + : undefined, + ) + const quoteNetworkFeesCryptoBaseUnitQuery = useQuery({ queryKey: ['quoteNetworkFeesCryptoBaseUnit', tradeQuote], refetchInterval: 15_000, @@ -72,7 +92,10 @@ export const useTradeNetworkFeeCryptoBaseUnit = ({ sellAssetAccountId && swapper && hop && - isExecutableTradeQuote(tradeQuote) + isExecutableTradeQuote(tradeQuote) && + // Stop fetching once the Tx is executed for this step + hopExecutionMetadata?.state === HopExecutionState.AwaitingSwap && + hopExecutionMetadata?.swap?.state === TransactionExecutionState.AwaitingConfirmation ? async () => { const { accountType, bip44Params } = accountMetadata const accountNumber = bip44Params.accountNumber