diff --git a/packages/canonical-bridge-widget/src/core/constants/index.ts b/packages/canonical-bridge-widget/src/core/constants/index.ts index b5e85a41..1126c096 100644 --- a/packages/canonical-bridge-widget/src/core/constants/index.ts +++ b/packages/canonical-bridge-widget/src/core/constants/index.ts @@ -52,6 +52,4 @@ export const EVM_NATIVE_TOKEN_ADDRESS = '0x0000000000000000000000000000000000000 export const SOLANA_NATIVE_TOKEN_ADDRESS = '11111111111111111111111111111111'; -export const NON_EVM_CHAIN_ID_MAP = { - tron: 728126428, -}; +export const TRON_CHAIN_ID = 728126428; diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts index 7a81dbd2..bdb89067 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/meson/MesonAdapter.ts @@ -3,7 +3,7 @@ import { BridgeType } from '@bnb-chain/canonical-bridge-sdk'; import { BaseAdapter, ITransferTokenPair } from '@/modules/aggregator/shared/BaseAdapter'; import { IMesonChain, IMesonToken } from '@/modules/aggregator/adapters/meson/types'; import { isNativeToken } from '@/core/utils/address'; -import { NON_EVM_CHAIN_ID_MAP } from '@/core/constants'; +import { TRON_CHAIN_ID } from '@/core/constants'; // const SUPPORTED_CHAIN_IDS = [56, 97, 3448148188, 728126428]; // const SUPPORTED_TOKENS = ['USDT', 'USDC']; @@ -15,8 +15,8 @@ export class MesonAdapter extends BaseAdapter { - const hasChainConfig = this.includedChains.includes(Number(chain.chainId)); - const isExcludedChain = this.excludedChains.includes(Number(chain.chainId)); + const hasChainConfig = this.includedChains.includes(this.getChainId(chain)); + const isExcludedChain = this.excludedChains.includes(this.getChainId(chain)); const hasToken = chain.tokens?.length > 0; // const isSupported = SUPPORTED_CHAIN_IDS.includes(Number(chain.chainId)); // TODO @@ -25,8 +25,7 @@ export class MesonAdapter extends BaseAdapter(); filteredChains.forEach((chain) => { - const chainId = - chain.chainId === 'tron' ? NON_EVM_CHAIN_ID_MAP['tron'] : Number(chain.chainId); + const chainId = this.getChainId(chain); if (!!Number(chainId)) { chainMap.set(chainId, chain); } @@ -43,7 +42,7 @@ export class MesonAdapter extends BaseAdapter>(); chains.forEach((chain) => { - const chainId = chain.chainId === 'tron' ? 728126428 : Number(chain.chainId); + const chainId = this.getChainId(chain); const filteredTokens = chain.tokens.filter((token, tokenIndex) => { const tokenAddress = token.addr ?? '0x0000000000000000000000000000000000000000'; @@ -93,19 +92,23 @@ export class MesonAdapter extends BaseAdapter { this.chains.forEach((toChain) => { if (fromChain?.chainId !== toChain?.chainId) { - const fromTokens = this.tokenMap.get(Number(fromChain.chainId)) ?? []; + const fromChainId = this.getChainId(fromChain); + const toChainId = this.getChainId(toChain); + + const fromTokens = this.tokenMap.get(fromChainId) ?? []; const transferableTokenMap = new Map>(); + fromTokens.forEach((fromToken) => { const toToken = this.getToToken({ - fromChainId: Number(fromChain.chainId), - toChainId: Number(toChain.chainId), + fromChainId, + toChainId, fromTokenSymbol: fromToken.symbol?.toUpperCase(), }); if (toToken) { const tokenPair: ITransferTokenPair = { - fromChainId: Number(fromChain.chainId), - toChainId: Number(toChain.chainId), + fromChainId, + toChainId, fromToken, toToken, fromTokenAddress: fromToken.addr, @@ -116,15 +119,13 @@ export class MesonAdapter extends BaseAdapter 0) { - if (!transferMap.has(Number(fromChain.chainId))) { + if (!transferMap.has(fromChainId)) { transferMap.set( - Number(fromChain.chainId), + fromChainId, new Map>>(), ); } - transferMap - .get(Number(fromChain.chainId)) - ?.set(Number(toChain.chainId), transferableTokenMap); + transferMap.get(fromChainId)?.set(toChainId, transferableTokenMap); } } }); @@ -134,7 +135,7 @@ export class MesonAdapter extends BaseAdapter