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

feat: stop refetching network fees after hop execution #8570

Merged
merged 2 commits into from
Jan 14, 2025
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
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