mirror of
https://github.com/vacp2p/linea-monorepo.git
synced 2026-01-09 20:27:58 -05:00
fix: update token list order + add Linea as default lifi destination chain (#872)
This commit is contained in:
@@ -4,7 +4,7 @@ import { useDynamicContext, useIsLoggedIn } from "@/lib/dynamic";
|
||||
import { ChainId, LiFiWidget, WidgetSkeleton, type WidgetConfig } from "@/lib/lifi";
|
||||
import { ClientOnly } from "../client-only";
|
||||
import atypTextFont from "@/assets/fonts/atypText";
|
||||
import { CHAINS_RPC_URLS } from "@/constants";
|
||||
import { CHAINS_RPC_URLS, ETH_SYMBOL } from "@/constants";
|
||||
import { config } from "@/config";
|
||||
|
||||
const widgetConfig: Partial<WidgetConfig> = {
|
||||
@@ -12,6 +12,8 @@ const widgetConfig: Partial<WidgetConfig> = {
|
||||
subvariant: "default",
|
||||
appearance: "light",
|
||||
integrator: "Linea",
|
||||
toChain: ChainId.LNA,
|
||||
toToken: ETH_SYMBOL,
|
||||
theme: {
|
||||
palette: {
|
||||
primary: {
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
export const USDC_SYMBOL = "USDC";
|
||||
export const ETH_SYMBOL = "ETH";
|
||||
export const USDT_SYMBOL = "USDT";
|
||||
|
||||
export const PRIORITY_SYMBOLS = [ETH_SYMBOL, USDC_SYMBOL, USDT_SYMBOL];
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Address } from "viem";
|
||||
import { config } from "@/config";
|
||||
import { SupportedCurrencies, defaultTokensConfig } from "@/stores";
|
||||
import { GithubTokenListToken, Token, BridgeProvider, NetworkTokens } from "@/types";
|
||||
import { USDC_SYMBOL } from "@/constants";
|
||||
import { PRIORITY_SYMBOLS, USDC_SYMBOL } from "@/constants";
|
||||
import { isUndefined } from "@/utils";
|
||||
|
||||
enum NetworkTypes {
|
||||
@@ -84,29 +84,49 @@ export async function formatToken(token: GithubTokenListToken): Promise<Token> {
|
||||
}
|
||||
|
||||
export async function getTokenConfig(): Promise<NetworkTokens> {
|
||||
const [mainnetTokens, sepoliaTokens] = await Promise.all([
|
||||
getTokens(NetworkTypes.MAINNET),
|
||||
getTokens(NetworkTypes.SEPOLIA),
|
||||
]);
|
||||
|
||||
const updatedTokensConfig = { ...defaultTokensConfig };
|
||||
|
||||
// Feature toggle, remove when feature toggle no longer needed
|
||||
const filterOutUSDCWhenCctpNotEnabled = (token: Token) => config.isCctpEnabled || token.symbol !== USDC_SYMBOL;
|
||||
|
||||
updatedTokensConfig.MAINNET = [
|
||||
...defaultTokensConfig.MAINNET,
|
||||
...(await Promise.all(mainnetTokens.map(async (token: GithubTokenListToken): Promise<Token> => formatToken(token))))
|
||||
// Feature toggle, remove .filter expression when feature toggle no longer needed
|
||||
.filter(filterOutUSDCWhenCctpNotEnabled),
|
||||
];
|
||||
// Sort the tokens to put priority tokens first
|
||||
const sortPriorityTokensFirst = (tokens: Token[]): Token[] => {
|
||||
const priority: Token[] = [];
|
||||
const rest: Token[] = [];
|
||||
|
||||
updatedTokensConfig.SEPOLIA = [
|
||||
...defaultTokensConfig.SEPOLIA,
|
||||
...(await Promise.all(sepoliaTokens.map((token: GithubTokenListToken): Promise<Token> => formatToken(token))))
|
||||
// Feature toggle, remove .filter expression when feature toggle no longer needed
|
||||
.filter(filterOutUSDCWhenCctpNotEnabled),
|
||||
];
|
||||
for (const token of tokens) {
|
||||
if (PRIORITY_SYMBOLS.includes(token.symbol)) {
|
||||
// Avoid duplicates
|
||||
if (!priority.find((t) => t.symbol === token.symbol)) {
|
||||
priority.push(token);
|
||||
}
|
||||
} else {
|
||||
rest.push(token);
|
||||
}
|
||||
}
|
||||
|
||||
return [...priority, ...rest];
|
||||
};
|
||||
|
||||
const enrichTokens = async (tokens: GithubTokenListToken[], defaultList: Token[]): Promise<Token[]> => {
|
||||
const formatted = await Promise.all(tokens.map(formatToken));
|
||||
// Feature toggle, remove .filter expression when feature toggle no longer needed
|
||||
const allTokens = [...defaultList, ...formatted.filter(filterOutUSDCWhenCctpNotEnabled)];
|
||||
return sortPriorityTokensFirst(allTokens);
|
||||
};
|
||||
|
||||
const [mainnetTokens, sepoliaTokens] = await Promise.all([
|
||||
getTokens(NetworkTypes.MAINNET),
|
||||
getTokens(NetworkTypes.SEPOLIA),
|
||||
]);
|
||||
|
||||
const [mainnet, sepolia] = await Promise.all([
|
||||
enrichTokens(mainnetTokens, defaultTokensConfig.MAINNET),
|
||||
enrichTokens(sepoliaTokens, defaultTokensConfig.SEPOLIA),
|
||||
]);
|
||||
|
||||
updatedTokensConfig.MAINNET = mainnet;
|
||||
updatedTokensConfig.SEPOLIA = sepolia;
|
||||
|
||||
return updatedTokensConfig;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user