Skip to content

Commit

Permalink
feat: stop refetching network fees after hop execution (#8570)
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre authored Jan 14, 2025
1 parent 788dc5b commit e171e21
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit e171e21

Please sign in to comment.