Skip to content

Commit 0dad6cb

Browse files
feat: code optimisation for erc20
Ticket: WIN-7914
1 parent 667008e commit 0dad6cb

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

modules/bitgo/src/v2/coinFactory.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,14 @@ export function getCoinConstructor(coinName: string): CoinConstructor | undefine
903903
}
904904
}
905905

906+
const ethLikeChainToTestnetMap: Record<string, string> = {};
906907
export function getTokenConstructor(tokenConfig: TokenConfig): CoinConstructor | undefined {
908+
if (tokenConfig.coin in ethLikeChainToTestnetMap) {
909+
return EthLikeErc20Token.createTokenConstructor(tokenConfig as EthLikeTokenConfig, {
910+
Mainnet: tokenConfig.coin,
911+
Testnet: ethLikeChainToTestnetMap[tokenConfig.coin],
912+
});
913+
}
907914
switch (tokenConfig.coin) {
908915
case 'eth':
909916
case 'hteth':

modules/statics/src/tokenConfig.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,25 @@ const getFormattedXdcTokens = (customCoinMap = coins) =>
805805
return acc;
806806
}, []);
807807

808+
function getEthLikeTokenConfig(coin: EthLikeERC20Token): EthLikeTokenConfig {
809+
return {
810+
type: coin.name,
811+
coin: coin.network.type === NetworkType.MAINNET ? coin.name : 't'.concat(coin.name),
812+
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
813+
name: coin.fullName,
814+
tokenContractAddress: coin.contractAddress.toString().toLowerCase(),
815+
decimalPlaces: coin.decimalPlaces,
816+
};
817+
}
818+
819+
export const getFormattedEthLikeTokenConfig = (customCoinMap = coins) =>
820+
customCoinMap.reduce((acc: EthLikeTokenConfig[], coin) => {
821+
if (coin instanceof EthLikeERC20Token) {
822+
acc.push(getEthLikeTokenConfig(coin));
823+
}
824+
return acc;
825+
}, []);
826+
808827
function getFlowTokenConfig(coin: EthLikeERC20Token): EthLikeTokenConfig {
809828
return {
810829
type: coin.name,

0 commit comments

Comments
 (0)