From 17d75dfd07ca0b59ea114e83a9479d73f29a49ac Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:40:50 +0900 Subject: [PATCH] feat: stopping point --- .../hooks/useGetTradeQuotes/useGetTradeQuotes.tsx | 7 +++++++ src/state/slices/tradeQuoteSlice/selectors.ts | 9 +++++++++ src/state/slices/tradeQuoteSlice/tradeQuoteSlice.ts | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx b/src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx index a6ca2a27818..849ff2093a3 100644 --- a/src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx +++ b/src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx @@ -37,11 +37,13 @@ import { import { selectActiveQuote, selectActiveQuoteMetaOrDefault, + selectConfirmedTradeExecution, selectHopExecutionMetadata, selectIsAnyTradeQuoteLoading, selectSortedTradeQuotes, } from 'state/slices/tradeQuoteSlice/selectors' import { tradeQuoteSlice } from 'state/slices/tradeQuoteSlice/tradeQuoteSlice' +import type { TradeExecutionMetadata } from 'state/slices/tradeQuoteSlice/types' import { HopExecutionState } from 'state/slices/tradeQuoteSlice/types' import { store, useAppDispatch, useAppSelector } from 'state/store' @@ -127,6 +129,9 @@ export const useGetTradeQuotes = () => { const activeTradeIdRef = useRef() const activeQuoteMeta = useAppSelector(selectActiveQuoteMetaOrDefault) const activeQuoteMetaRef = useRef<{ swapperName: SwapperName; identifier: string } | undefined>() + // TODO(gomes): set trade execution of quote to the same as we stopped in rate to reconciliate things + const confirmedTradeExecution = useAppSelector(selectConfirmedTradeExecution) + const confirmedTradeExecutionRef = useRef() useEffect( () => { @@ -355,6 +360,8 @@ export const useGetTradeQuotes = () => { // auto-select the best quote once all quotes have arrived useEffect(() => { + // We already have an executable active trade, don't rerun this or this will run forever + if (activeTrade && isExecutableTradeQuote(activeTrade)) return const swapperName = activeQuoteMetaRef.current?.swapperName if (!swapperName) return if (!queryStateMeta?.data) return diff --git a/src/state/slices/tradeQuoteSlice/selectors.ts b/src/state/slices/tradeQuoteSlice/selectors.ts index 49a5b639729..4518421f7e3 100644 --- a/src/state/slices/tradeQuoteSlice/selectors.ts +++ b/src/state/slices/tradeQuoteSlice/selectors.ts @@ -598,6 +598,15 @@ export const selectTradeQuoteAffiliateFeeAfterDiscountUserCurrency = createSelec }, ) +export const selectConfirmedTradeExecution = createSelector( + selectTradeQuoteSlice, + selectConfirmedQuoteTradeId, + (swappers, confirmedTradeId) => { + if (!confirmedTradeId) return + return swappers.tradeExecution[confirmedTradeId] + }, +) + export const selectConfirmedTradeExecutionState = createSelector( selectTradeQuoteSlice, selectConfirmedQuoteTradeId, diff --git a/src/state/slices/tradeQuoteSlice/tradeQuoteSlice.ts b/src/state/slices/tradeQuoteSlice/tradeQuoteSlice.ts index e537d28a0ca..a5bfa3cc54c 100644 --- a/src/state/slices/tradeQuoteSlice/tradeQuoteSlice.ts +++ b/src/state/slices/tradeQuoteSlice/tradeQuoteSlice.ts @@ -6,6 +6,7 @@ import type { InterpolationOptions } from 'node-polyglot' import type { ApiQuote } from 'state/apis/swapper/types' import { initialState, initialTradeExecutionState } from './constants' +import type { TradeExecutionMetadata } from './types' import { AllowanceKey, HopExecutionState, @@ -51,6 +52,12 @@ export const tradeQuoteSlice = createSlice({ state.confirmedQuote = action.payload state.tradeExecution[action.payload.id] = initialTradeExecutionState }, + setTradeExecutionMetadata: ( + state, + action: PayloadAction<{ id: TradeQuote['id']; executionMetadata: TradeExecutionMetadata }>, + ) => { + state.tradeExecution[action.payload.id] = action.payload.executionMetadata + }, setTradeInitialized: (state, action: PayloadAction) => { state.tradeExecution[action.payload].state = TradeExecutionState.Previewing },