Skip to content

Commit c8945b6

Browse files
committed
fix(statics): give precedence to statics coin map over ams map
TICKET: WIN-4944
1 parent 1dedc91 commit c8945b6

File tree

3 files changed

+61
-13
lines changed

3 files changed

+61
-13
lines changed

modules/statics/src/coins.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,28 +3190,24 @@ export function createTokenMapUsingConfigDetails(tokenConfigMap: Record<string,
31903190
'terc1155:polygontoken',
31913191
]);
31923192

3193+
// Add all the coins from statics coin map first
3194+
coins.forEach((coin, coinName) => {
3195+
BaseCoins.set(coinName, coin);
3196+
});
3197+
3198+
// add the tokens not present in the static coin map
31933199
for (const tokenConfigs of Object.values(tokenConfigMap)) {
31943200
const tokenConfig = tokenConfigs[0];
31953201
const family = tokenConfig.family;
3202+
const name = tokenConfig.name;
31963203

3197-
if (tokenConfig.isToken && !nftAndOtherTokens.has(tokenConfig.name)) {
3204+
if (!coins.has(name) && tokenConfig.isToken && !nftAndOtherTokens.has(tokenConfig.name)) {
31983205
const token = createToken(family, tokenConfig, initializerMap);
31993206
if (token) {
32003207
BaseCoins.set(token.name, token);
3201-
} else if (coins.has(tokenConfig.name)) {
3202-
BaseCoins.set(tokenConfig.name, coins.get(tokenConfig.name));
32033208
}
3204-
} else if (coins.has(tokenConfig.name)) {
3205-
BaseCoins.set(tokenConfig.name, coins.get(tokenConfig.name));
32063209
}
32073210
}
32083211

3209-
// Add keys and values from `coins` that are not already in `BaseCoins`
3210-
coins.forEach((coin, coinName) => {
3211-
if (!BaseCoins.has(coinName)) {
3212-
BaseCoins.set(coinName, coin);
3213-
}
3214-
});
3215-
32163212
return CoinMap.fromCoins(Array.from(BaseCoins.values()));
32173213
}

modules/statics/test/unit/coins.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from '../../src';
2424
import { utxo } from '../../src/utxo';
2525
import { expectedColdFeatures } from './fixtures/expectedColdFeatures';
26-
import { amsTokenConfig, amsTokenConfigWithCustomToken } from './resources/amsTokenConfig';
26+
import { amsTokenConfig, amsTokenConfigWithCustomToken, incorrectAmsTokenConfig } from './resources/amsTokenConfig';
2727

2828
interface DuplicateCoinObject {
2929
name: string;
@@ -922,6 +922,15 @@ describe('create token map using config details', () => {
922922
JSON.stringify(tokenNetwork).should.eql(JSON.stringify(staticNetwork));
923923
});
924924
});
925+
it('should give precedence to static coin map over ams coin map', () => {
926+
const tokenMap = createTokenMapUsingConfigDetails(incorrectAmsTokenConfig);
927+
const tokenName = 'thbar:usdc';
928+
const token = tokenMap.get(tokenName);
929+
token.decimalPlaces.should.eql(coins.get(tokenName).decimalPlaces);
930+
token.baseUnit.should.eql(coins.get(tokenName).baseUnit);
931+
token.decimalPlaces.should.not.eql(incorrectAmsTokenConfig[tokenName][0].decimalPlaces);
932+
token.baseUnit.should.not.eql(incorrectAmsTokenConfig[tokenName][0].baseUnit);
933+
});
925934
it('should create a coin map and get formatted tokens from it', () => {
926935
const coinMap = createTokenMapUsingConfigDetails(amsTokenConfigWithCustomToken);
927936
const formattedTokens = getFormattedTokens(coinMap);

modules/statics/test/unit/resources/amsTokenConfig.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,46 @@ export const amsTokenConfigWithCustomToken = {
654654
},
655655
],
656656
};
657+
658+
export const incorrectAmsTokenConfig = {
659+
...amsTokenConfig,
660+
'thbar:usdc': [
661+
{
662+
id: '842c2119-3071-409d-b86f-49f0b46b676e',
663+
fullName: 'Testnet Hedera USD Coin',
664+
name: 'thbar:usdc',
665+
prefix: '',
666+
suffix: 'THBAR:USDC',
667+
baseUnit: 'fakebar',
668+
kind: 'crypto',
669+
family: 'hbar',
670+
isToken: true,
671+
features: [
672+
'account-model',
673+
'requires-big-number',
674+
'valueless-transfer',
675+
'transaction-data',
676+
'custody',
677+
'custody-bitgo-trust',
678+
'custody-bitgo-mena-fze',
679+
'custody-bitgo-custody-mena-fze',
680+
'custody-bitgo-singapore',
681+
'custody-bitgo-korea',
682+
'custody-bitgo-europe-aps',
683+
'custody-bitgo-frankfurt',
684+
],
685+
decimalPlaces: 60,
686+
asset: 'usdc',
687+
network: {
688+
type: 'testnet',
689+
name: 'HederaTestnet',
690+
family: 'hbar',
691+
explorerUrl: 'https://testnet.dragonglass.me/hedera/search?q=',
692+
},
693+
primaryKeyCurve: 'ed25519',
694+
nodeAccountId: '0.0.3',
695+
tokenId: '0.0.13078',
696+
contractAddress: '0.0.13078',
697+
},
698+
],
699+
};

0 commit comments

Comments
 (0)