Skip to content

Commit

Permalink
feat: stopping point
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Nov 5, 2024
1 parent 3f226ad commit 17d75df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -127,6 +129,9 @@ export const useGetTradeQuotes = () => {
const activeTradeIdRef = useRef<string | undefined>()
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)

Check failure on line 133 in src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx

View workflow job for this annotation

GitHub Actions / Call / Static

'confirmedTradeExecution' is assigned a value but never used

Check failure on line 133 in src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx

View workflow job for this annotation

GitHub Actions / Call / Static

'confirmedTradeExecution' is assigned a value but never used
const confirmedTradeExecutionRef = useRef<TradeExecutionMetadata | undefined>()

Check failure on line 134 in src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx

View workflow job for this annotation

GitHub Actions / Call / Static

'confirmedTradeExecutionRef' is assigned a value but never used

Check failure on line 134 in src/components/MultiHopTrade/hooks/useGetTradeQuotes/useGetTradeQuotes.tsx

View workflow job for this annotation

GitHub Actions / Call / Static

'confirmedTradeExecutionRef' is assigned a value but never used

useEffect(
() => {
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/state/slices/tradeQuoteSlice/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/state/slices/tradeQuoteSlice/tradeQuoteSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<TradeQuote['id']>) => {
state.tradeExecution[action.payload].state = TradeExecutionState.Previewing
},
Expand Down

0 comments on commit 17d75df

Please sign in to comment.