From 5fd46575882f859795a0e5faa1799176acde6998 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 9 Oct 2020 14:44:10 -0230 Subject: [PATCH] Stop calling _findTopQuoteAggId twice in _findTopQuoteAggId (#9530) * Stop calling _findTopQuoteAggId twice in _findTopQuoteAggId * Update app/scripts/controllers/swaps.js Co-authored-by: Mark Stacey Co-authored-by: Mark Stacey --- app/scripts/controllers/swaps.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/scripts/controllers/swaps.js b/app/scripts/controllers/swaps.js index 95764d5f9..91a025cff 100644 --- a/app/scripts/controllers/swaps.js +++ b/app/scripts/controllers/swaps.js @@ -164,13 +164,9 @@ export default class SwapsController { } } - const topAggIdData = await this._findTopQuoteAggId(newQuotes) - let { topAggId } = topAggIdData - const { isBest } = topAggIdData - - if (isBest) { - newQuotes[topAggId].isBestQuote = true - } + let topAggIdData + let topAggId + let isBest // We can reduce time on the loading screen by only doing this after the // loading screen and best quote have rendered. @@ -181,15 +177,20 @@ export default class SwapsController { this.setSwapsErrorKey(QUOTES_NOT_AVAILABLE_ERROR) } else { const { - topAggId: topAggIdAfterGasEstimates, - isBest: isBestAfterGasEstimates, + topAggId: topAggIdAfterModifications, + isBest: isBestAfterModifications, } = await this._findTopQuoteAggId(newQuotes) - topAggId = topAggIdAfterGasEstimates - if (isBestAfterGasEstimates) { - newQuotes = mapValues(newQuotes, (quote) => ({ ...quote, isBestQuote: false })) - newQuotes[topAggId].isBestQuote = true - } + topAggId = topAggIdAfterModifications + isBest = isBestAfterModifications } + } else { + topAggIdData = await this._findTopQuoteAggId(newQuotes) + topAggId = topAggIdData.topAggId + isBest = topAggIdData.isBest + } + + if (isBest) { + newQuotes[topAggId].isBestQuote = true } const { swapsState } = this.store.getState()