Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug / Continuous "Failed to fetch routes for this pair" error thrown when updating the quote for swapping (not bridging) tokens #1075

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions src/controllers/swapAndBridge/swapAndBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { isSmartAccount } from '../../libs/account/account'
import { getSwapAndBridgeBanners } from '../../libs/banners/banners'
import { TokenResult } from '../../libs/portfolio'
import { getTokenAmount } from '../../libs/portfolio/helpers'
import { getQuoteRouteSteps, sortTokenListResponse } from '../../libs/swapAndBridge/swapAndBridge'
import {
getIsBridgeTxn,
getQuoteRouteSteps,
sortTokenListResponse
} from '../../libs/swapAndBridge/swapAndBridge'
import { getSanitizedAmount } from '../../libs/transfer/amount'
import { SocketAPI } from '../../services/socket/api'
import { validateSendTransferAmount } from '../../services/validations/validate'
Expand Down Expand Up @@ -472,7 +476,8 @@ export class SwapAndBridgeController extends EventEmitter {
this.emitError({
error,
level: 'major',
message: `Unable to retrieve the list of supported receive tokens. Please reload the tab to try again.`
message:
'Unable to retrieve the list of supported receive tokens. Please reload the tab to try again.'
})
}
this.updateToTokenListStatus = 'INITIAL'
Expand Down Expand Up @@ -580,21 +585,23 @@ export class SwapAndBridgeController extends EventEmitter {
let routeToSelect
let routeToSelectSteps

const selectedRouteInQuoteRes = this.quote
? quoteResult.routes.find((r: SocketAPIRoute) => {
if (this.quote!.selectedRoute?.usedBridgeNames) {
return r?.usedBridgeNames?.[0] === this.quote!.selectedRoute.usedBridgeNames[0] // because we have only routes with unique bridges
}
if (this.quote!.selectedRoute?.usedDexName) {
return r?.usedDexName === this.quote!.selectedRoute.usedDexName
}

return false
})
: null
if (selectedRouteInQuoteRes) {
routeToSelect = selectedRouteInQuoteRes
routeToSelectSteps = getQuoteRouteSteps(selectedRouteInQuoteRes.userTxs)
const alreadySelectedRoute = quoteResult.routes.find((nextRoute) => {
if (!this.quote) return false

// Because we have only routes with unique bridges (bridging case)
const selectedRouteUsedBridge = this.quote.selectedRoute.usedBridgeNames?.[0]
if (selectedRouteUsedBridge)
return nextRoute.usedBridgeNames?.[0] === selectedRouteUsedBridge

// Assuming to have routes with unique DEXes ONLY (swapping case)
const selectedRouteUsedDex = this.quote.selectedRoute.usedDexName
if (selectedRouteUsedDex) return nextRoute.usedDexName === selectedRouteUsedDex
superKalo marked this conversation as resolved.
Show resolved Hide resolved

return false // should never happen, but just in case of bad data
})
if (alreadySelectedRoute) {
routeToSelect = alreadySelectedRoute
routeToSelectSteps = getQuoteRouteSteps(alreadySelectedRoute.userTxs)
} else {
const bestRoute =
this.routePriority === 'output'
Expand Down
2 changes: 1 addition & 1 deletion src/services/socket/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class SocketAPI {
userAddress: string
isSmartAccount: boolean
sort: 'time' | 'output'
}) {
}): Promise<SocketAPIQuote> {
const params = new URLSearchParams({
fromChainId: fromChainId.toString(),
fromTokenAddress: normalizeOutgoingSocketTokenAddress(fromTokenAddress),
Expand Down
Loading