Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteenkamp89 committed Jan 10, 2025
1 parent 3c0a5ed commit f693a2a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion scripts/chain-configs/lens-sepolia/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/assets/chain-logos/lens-sepolia.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/constants/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const orderedEnabledChainIds = [
CHAIN_IDs.POLYGON_AMOY,
CHAIN_IDs.BLAST_SEPOLIA,
CHAIN_IDs.LISK_SEPOLIA,
CHAIN_IDs.LENS_SEPOLIA,
];

export const chainInfoList: ChainInfoList = orderedEnabledChainIds.map(
Expand Down
6 changes: 2 additions & 4 deletions src/views/Bridge/components/ChainSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
shortenAddress,
} from "utils";

import { getAllChains } from "../utils";
import { useBalanceBySymbolPerChain, useConnection } from "hooks";
import { useMemo } from "react";
import { BigNumber } from "ethers";
import { getSupportedChains } from "../utils";

type Props = {
selectedRoute: Route;
Expand All @@ -25,8 +25,6 @@ type Props = {
onSelectChain: (chainId: number) => void;
};

const allChains = getAllChains();

export function ChainSelector({
selectedRoute,
fromOrTo,
Expand All @@ -36,8 +34,8 @@ export function ChainSelector({
const isFrom = fromOrTo === "from";
const { fromChain, toChain, fromTokenSymbol, toTokenSymbol } = selectedRoute;
const selectedChain = getChainInfo(isFrom ? fromChain : toChain);

const tokenInfo = getToken(isFrom ? fromTokenSymbol : toTokenSymbol);
const allChains = getSupportedChains(fromOrTo);

const { account, isConnected } = useConnection();
const { balances } = useBalanceBySymbolPerChain({
Expand Down
57 changes: 40 additions & 17 deletions src/views/Bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,23 +351,46 @@ export function getAvailableOutputTokens(
);
}

export function getAllChains() {
return enabledRoutes
.map((route) => getChainInfo(route.fromChain))
.filter(
(chain, index, self) =>
index ===
self.findIndex((fromChain) => fromChain.chainId === chain.chainId)
)
.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
export const ChainType = {
FROM: "from",
TO: "to",
ALL: "all",
} as const;

export type ChainTypeT = (typeof ChainType)[keyof typeof ChainType];

export function getSupportedChains(chainType: ChainTypeT = ChainType.ALL) {
let chainIds: number[] = [];

switch (chainType) {
case ChainType.FROM:
chainIds = enabledRoutes.map((route) => route.fromChain);
break;
case ChainType.TO:
chainIds = enabledRoutes.map((route) => route.toChain);
break;
case ChainType.ALL:
default:
chainIds = enabledRoutes.flatMap((route) => [
route.fromChain,
route.toChain,
]);
break;
}

const uniqueChainIds = Array.from(new Set(chainIds));

const uniqueChains = uniqueChainIds.map((chainId) => getChainInfo(chainId));

return uniqueChains.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
}

export function getRouteFromUrl(overrides?: RouteFilter) {
Expand Down

0 comments on commit f693a2a

Please sign in to comment.