1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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>
This commit is contained in:
Dan J Miller 2020-10-09 14:44:10 -02:30 committed by GitHub
parent 4505ab5f2b
commit 5fd4657588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -164,13 +164,9 @@ export default class SwapsController {
} }
} }
const topAggIdData = await this._findTopQuoteAggId(newQuotes) let topAggIdData
let { topAggId } = topAggIdData let topAggId
const { isBest } = topAggIdData let isBest
if (isBest) {
newQuotes[topAggId].isBestQuote = true
}
// We can reduce time on the loading screen by only doing this after the // We can reduce time on the loading screen by only doing this after the
// loading screen and best quote have rendered. // loading screen and best quote have rendered.
@ -181,15 +177,20 @@ export default class SwapsController {
this.setSwapsErrorKey(QUOTES_NOT_AVAILABLE_ERROR) this.setSwapsErrorKey(QUOTES_NOT_AVAILABLE_ERROR)
} else { } else {
const { const {
topAggId: topAggIdAfterGasEstimates, topAggId: topAggIdAfterModifications,
isBest: isBestAfterGasEstimates, isBest: isBestAfterModifications,
} = await this._findTopQuoteAggId(newQuotes) } = await this._findTopQuoteAggId(newQuotes)
topAggId = topAggIdAfterGasEstimates topAggId = topAggIdAfterModifications
if (isBestAfterGasEstimates) { isBest = isBestAfterModifications
newQuotes = mapValues(newQuotes, (quote) => ({ ...quote, isBestQuote: false }))
newQuotes[topAggId].isBestQuote = true
}
} }
} else {
topAggIdData = await this._findTopQuoteAggId(newQuotes)
topAggId = topAggIdData.topAggId
isBest = topAggIdData.isBest
}
if (isBest) {
newQuotes[topAggId].isBestQuote = true
} }
const { swapsState } = this.store.getState() const { swapsState } = this.store.getState()