diff --git a/src/Routes.tsx b/src/Routes.tsx index 2601c8604..4755bd8d4 100644 --- a/src/Routes.tsx +++ b/src/Routes.tsx @@ -17,6 +17,7 @@ import { generalMaintenanceMessage, stringValueInArray, getConfig, + chainEndpointToId, } from "utils"; import lazyWithRetry from "utils/lazy-with-retry"; import { ReactComponent as InfoLogo } from "assets/icons/info.svg"; @@ -187,6 +188,18 @@ const Routes: React.FC = () => { search: location.search, }} /> + {Object.entries(chainEndpointToId).map(([chainName, chainId]) => ( + } + /> + ))} + } + /> diff --git a/src/utils/constants.ts b/src/utils/constants.ts index d4394cdcd..670193481 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -229,6 +229,12 @@ export function getChainInfo(chainId: number): ChainInfo { return chainInfo; } +export const chainEndpointToId = Object.fromEntries( + chainInfoList.map((chain) => { + return [chain.name.toLowerCase().replaceAll(" ", ""), chain.chainId]; + }, []) +); + // For destination chains with no native ETH support, we will send WETH even if the receiver is an EOA export const nonEthChains = [ ChainId.POLYGON, diff --git a/src/views/Bridge/utils.ts b/src/views/Bridge/utils.ts index 1ca7e59a9..e9882089d 100644 --- a/src/views/Bridge/utils.ts +++ b/src/views/Bridge/utils.ts @@ -12,6 +12,7 @@ import { interchangeableTokensMap, nonEthChains, GetBridgeFeesResult, + chainEndpointToId, } from "utils"; import { SwapQuoteApiResponse } from "utils/serverless-api/prod/swap-quote"; @@ -146,7 +147,7 @@ const defaultRouteFilter = { }; export function getInitialRoute(filter: RouteFilter = {}) { - const routeFromQueryParams = getRouteFromQueryParams(filter); + const routeFromUrl = getRouteFromUrl(filter); const routeFromFilter = findEnabledRoute({ inputTokenSymbol: filter.inputTokenSymbol ?? @@ -161,7 +162,7 @@ export function getInitialRoute(filter: RouteFilter = {}) { ...enabledRoutes[0], type: "bridge", }; - return routeFromQueryParams ?? routeFromFilter ?? defaultRoute; + return routeFromUrl ?? routeFromFilter ?? defaultRoute; } export function findEnabledRoute( @@ -373,9 +374,12 @@ export function getAllChains() { }); } -export function getRouteFromQueryParams(overrides?: RouteFilter) { +export function getRouteFromUrl(overrides?: RouteFilter) { const params = new URLSearchParams(window.location.search); + const preferredToChainId = + chainEndpointToId[window.location.pathname.substring(1)]; + const fromChain = Number( params.get("from") ?? @@ -386,7 +390,8 @@ export function getRouteFromQueryParams(overrides?: RouteFilter) { const toChain = Number( - params.get("to") ?? + preferredToChainId ?? + params.get("to") ?? params.get("toChain") ?? params.get("destinationChainId") ?? overrides?.toChain