mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Simplify _findTopQuoteAggId call in fetchAndSetQuotes (#9542)
This commit is contained in:
parent
5fd4657588
commit
d35db87447
@ -164,33 +164,23 @@ export default class SwapsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let topAggIdData
|
let topAggId = null
|
||||||
let topAggId
|
|
||||||
let isBest
|
|
||||||
|
|
||||||
// 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.
|
||||||
if (!approvalRequired && !fetchParams?.balanceError) {
|
if (!approvalRequired && !fetchParams?.balanceError) {
|
||||||
newQuotes = await this.getAllQuotesWithGasEstimates(newQuotes)
|
newQuotes = await this.getAllQuotesWithGasEstimates(newQuotes)
|
||||||
|
|
||||||
if (Object.values(newQuotes).length === 0) {
|
|
||||||
this.setSwapsErrorKey(QUOTES_NOT_AVAILABLE_ERROR)
|
|
||||||
} else {
|
|
||||||
const {
|
|
||||||
topAggId: topAggIdAfterModifications,
|
|
||||||
isBest: isBestAfterModifications,
|
|
||||||
} = await this._findTopQuoteAggId(newQuotes)
|
|
||||||
topAggId = topAggIdAfterModifications
|
|
||||||
isBest = isBestAfterModifications
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
topAggIdData = await this._findTopQuoteAggId(newQuotes)
|
|
||||||
topAggId = topAggIdData.topAggId
|
|
||||||
isBest = topAggIdData.isBest
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBest) {
|
if (Object.values(newQuotes).length === 0) {
|
||||||
newQuotes[topAggId].isBestQuote = true
|
this.setSwapsErrorKey(QUOTES_NOT_AVAILABLE_ERROR)
|
||||||
|
} else {
|
||||||
|
const topAggData = await this._findTopQuoteAggId(newQuotes)
|
||||||
|
|
||||||
|
if (topAggData.topAggId) {
|
||||||
|
topAggId = topAggData.topAggId
|
||||||
|
newQuotes[topAggId].isBestQuote = topAggData.isBest
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { swapsState } = this.store.getState()
|
const { swapsState } = this.store.getState()
|
||||||
|
@ -404,7 +404,7 @@ describe('SwapsController', function () {
|
|||||||
assert.strictEqual(newQuotes[topAggId].isBestQuote, true)
|
assert.strictEqual(newQuotes[topAggId].isBestQuote, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not set isBestQuote if no conversion rate exists for destination token', async function () {
|
it('does not mark as best quote if no conversion rate exists for destination token', async function () {
|
||||||
fetchTradesInfoStub.resolves(MOCK_QUOTES)
|
fetchTradesInfoStub.resolves(MOCK_QUOTES)
|
||||||
|
|
||||||
// Make it so approval is not required
|
// Make it so approval is not required
|
||||||
@ -420,7 +420,7 @@ describe('SwapsController', function () {
|
|||||||
MOCK_FETCH_METADATA,
|
MOCK_FETCH_METADATA,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.strictEqual(newQuotes[topAggId].isBestQuote, undefined)
|
assert.strictEqual(newQuotes[topAggId].isBestQuote, false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user