mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix parallel calls for quotes in swaps (#12484)
This commit is contained in:
parent
b5e601bc87
commit
e85248aaf5
@ -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 },
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ const EMPTY_INIT_STATE = {
|
||||
swapsQuoteRefreshTime: 60000,
|
||||
swapsQuotePrefetchingRefreshTime: 60000,
|
||||
swapsUserFeeLevel: '',
|
||||
isFetchingQuotes: false,
|
||||
saveFetchedQuotes: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user