diff --git a/src/core/account/account-api.ts b/src/core/account/account-api.ts index 720184102..17c7c7989 100644 --- a/src/core/account/account-api.ts +++ b/src/core/account/account-api.ts @@ -626,6 +626,7 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount { opts?: EdgeSwapRequestOptions ): Promise { const [quote, ...rest] = await fetchSwapQuotes( + const [bestQuote, ...otherQuotes] = await fetchSwapQuotes( ai, accountId, request, @@ -633,12 +634,12 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount { ) // Close unused quotes: - for (const quote of rest) quote.close().catch(() => undefined) + for (const otherQuote of otherQuotes) + otherQuote.close().catch(() => undefined) // Return the front quote: - if (quote == null) throw new Error('No swap providers enabled') - return quote - }, + if (bestQuote == null) throw new Error('No swap providers enabled') + return bestQuote async fetchSwapQuotes( request: EdgeSwapRequest,