|
|
|
@ -79,7 +79,7 @@ const initialState = { |
|
|
|
|
routeState: '', |
|
|
|
|
swapsFeatureIsLive: true, |
|
|
|
|
useNewSwapsApi: false, |
|
|
|
|
isFetchingQuotes: false, |
|
|
|
|
saveFetchedQuotes: false, |
|
|
|
|
swapsQuoteRefreshTime: FALLBACK_QUOTE_REFRESH_TIME, |
|
|
|
|
swapsQuotePrefetchingRefreshTime: FALLBACK_QUOTE_REFRESH_TIME, |
|
|
|
|
}, |
|
|
|
@ -209,7 +209,11 @@ export default class SwapsController { |
|
|
|
|
) { |
|
|
|
|
const { chainId } = fetchParamsMetaData; |
|
|
|
|
const { |
|
|
|
|
swapsState: { useNewSwapsApi, quotesPollingLimitEnabled }, |
|
|
|
|
swapsState: { |
|
|
|
|
useNewSwapsApi, |
|
|
|
|
quotesPollingLimitEnabled, |
|
|
|
|
saveFetchedQuotes, |
|
|
|
|
}, |
|
|
|
|
} = this.store.getState(); |
|
|
|
|
|
|
|
|
|
if (!fetchParams) { |
|
|
|
@ -230,7 +234,9 @@ export default class SwapsController { |
|
|
|
|
const indexOfCurrentCall = this.indexOfNewestCallInFlight + 1; |
|
|
|
|
this.indexOfNewestCallInFlight = indexOfCurrentCall; |
|
|
|
|
|
|
|
|
|
this.setIsFetchingQuotes(true); |
|
|
|
|
if (!saveFetchedQuotes) { |
|
|
|
|
this.setSaveFetchedQuotes(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let [newQuotes] = await Promise.all([ |
|
|
|
|
this._fetchTradesInfo(fetchParams, { |
|
|
|
@ -241,18 +247,17 @@ export default class SwapsController { |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
swapsState: { isFetchingQuotes }, |
|
|
|
|
swapsState: { saveFetchedQuotes: saveFetchedQuotesAfterResponse }, |
|
|
|
|
} = this.store.getState(); |
|
|
|
|
|
|
|
|
|
// If isFetchingQuotes is false, it means a user left Swaps (we cleaned the state)
|
|
|
|
|
// If saveFetchedQuotesAfterResponse is false, it means a user left Swaps (we cleaned the state)
|
|
|
|
|
// and we don't want to set any API response with quotes into state.
|
|
|
|
|
if (!isFetchingQuotes) { |
|
|
|
|
if (!saveFetchedQuotesAfterResponse) { |
|
|
|
|
return [ |
|
|
|
|
{}, // quotes
|
|
|
|
|
null, // selectedAggId
|
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
this.setIsFetchingQuotes(false); |
|
|
|
|
|
|
|
|
|
newQuotes = mapValues(newQuotes, (quote) => ({ |
|
|
|
|
...quote, |
|
|
|
@ -559,10 +564,10 @@ export default class SwapsController { |
|
|
|
|
this.store.updateState({ swapsState: { ...swapsState, routeState } }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setIsFetchingQuotes(status) { |
|
|
|
|
setSaveFetchedQuotes(status) { |
|
|
|
|
const { swapsState } = this.store.getState(); |
|
|
|
|
this.store.updateState({ |
|
|
|
|
swapsState: { ...swapsState, isFetchingQuotes: status }, |
|
|
|
|
swapsState: { ...swapsState, saveFetchedQuotes: status }, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|