Skip to content

Commit

Permalink
Merge pull request #224 from bnb-chain/feat/tokenApi1216
Browse files Browse the repository at this point in the history
fix: Fix tron does not display due to its id
  • Loading branch information
wenty22 authored Dec 27, 2024
2 parents 4fa197a + fb84eb5 commit aa764d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
4 changes: 1 addition & 3 deletions packages/canonical-bridge-widget/src/core/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -15,8 +15,8 @@ export class MesonAdapter extends BaseAdapter<IMesonChain[], IMesonChain, IMeson
const chains = this.config;

const filteredChains = chains.filter((chain) => {
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
Expand All @@ -25,8 +25,7 @@ export class MesonAdapter extends BaseAdapter<IMesonChain[], IMesonChain, IMeson

const chainMap = new Map<number, IMesonChain>();
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);
}
Expand All @@ -43,7 +42,7 @@ export class MesonAdapter extends BaseAdapter<IMesonChain[], IMesonChain, IMeson
const symbolMap = new Map<number, Map<string, IMesonToken>>();

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';
Expand Down Expand Up @@ -93,19 +92,23 @@ export class MesonAdapter extends BaseAdapter<IMesonChain[], IMesonChain, IMeson
this.chains.forEach((fromChain) => {
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<string, ITransferTokenPair<IMesonToken>>();

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<IMesonToken> = {
fromChainId: Number(fromChain.chainId),
toChainId: Number(toChain.chainId),
fromChainId,
toChainId,
fromToken,
toToken,
fromTokenAddress: fromToken.addr,
Expand All @@ -116,15 +119,13 @@ export class MesonAdapter extends BaseAdapter<IMesonChain[], IMesonChain, IMeson
});

if (transferableTokenMap.size > 0) {
if (!transferMap.has(Number(fromChain.chainId))) {
if (!transferMap.has(fromChainId)) {
transferMap.set(
Number(fromChain.chainId),
fromChainId,
new Map<number, Map<string, ITransferTokenPair<IMesonToken>>>(),
);
}
transferMap
.get(Number(fromChain.chainId))
?.set(Number(toChain.chainId), transferableTokenMap);
transferMap.get(fromChainId)?.set(toChainId, transferableTokenMap);
}
}
});
Expand All @@ -134,7 +135,7 @@ export class MesonAdapter extends BaseAdapter<IMesonChain[], IMesonChain, IMeson
}

public getChainId(chain: IMesonChain) {
return Number(chain.chainId);
return chain.chainId === 'tron' ? TRON_CHAIN_ID : Number(chain.chainId);
}

protected getChainIdAsObject(chainId: number) {
Expand Down

0 comments on commit aa764d8

Please sign in to comment.