Stop calling _findTopQuoteAggId twice in _findTopQuoteAggId (#9530)

* Stop calling _findTopQuoteAggId twice in _findTopQuoteAggId

* Update app/scripts/controllers/swaps.js

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
feature/default_network_editable
Dan J Miller 4 years ago committed by GitHub
parent 4505ab5f2b
commit 5fd4657588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      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()

Loading…
Cancel
Save