File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,16 @@ export class CoinFactory {
4242 this . coinConstructors . set ( name , coin ) ;
4343 }
4444
45+ /**
46+ * Checks if the coin is present in both coin map and constructor map
47+ * @param name Name of coin
48+ * @returns {boolean }
49+ */
50+
51+ public hasCoin ( name : string ) : boolean {
52+ return this . coinMap . has ( name ) && this . getCoinConstructor ( name ) !== undefined ;
53+ }
54+
4555 /**
4656 * Registers a token in the coin map and the constructor map.
4757 * @param staticsCoin The static coin definition from BitGo Statics
Original file line number Diff line number Diff line change @@ -3690,6 +3690,18 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
36903690 ofc : ofcToken ,
36913691 } ;
36923692
3693+ //return the BaseCoin from default coin map if present
3694+ if ( isCoinPresentInCoinMap ( { ...token } ) ) {
3695+ if ( coins . has ( token . name ) ) {
3696+ return coins . get ( token . name ) ;
3697+ }
3698+ if ( coins . has ( token . id ) ) {
3699+ return coins . get ( token . id ) ;
3700+ }
3701+ if ( token . alias && coins . has ( token . alias ) ) {
3702+ return coins . get ( token . alias ) ;
3703+ }
3704+ }
36933705 const family = token . family ;
36943706 const initializer = initializerMap [ family ] as ( ...args : unknown [ ] ) => Readonly < BaseCoin > ;
36953707 if ( ! initializer ) {
Original file line number Diff line number Diff line change @@ -1161,5 +1161,14 @@ describe('create token map using config details', () => {
11611161 decimalPlaces : amsTokenConfig . decimalPlaces ,
11621162 tokenContractAddress : amsTokenConfig . contractAddress . toLowerCase ( ) ,
11631163 } ) ;
1164+ it ( 'should return the base coin present in default coin map' , ( ) => {
1165+ const tokenName = 'thbar:usdc' ;
1166+ const token = createToken ( incorrectAmsTokenConfig [ tokenName ] [ 0 ] ) ;
1167+ token ?. should . not . be . undefined ( ) ;
1168+ token ?. decimalPlaces . should . eql ( coins . get ( tokenName ) . decimalPlaces ) ;
1169+ token ?. baseUnit . should . eql ( coins . get ( tokenName ) . baseUnit ) ;
1170+ token ?. decimalPlaces . should . not . eql ( incorrectAmsTokenConfig [ tokenName ] [ 0 ] . decimalPlaces ) ;
1171+ token ?. baseUnit . should . not . eql ( incorrectAmsTokenConfig [ tokenName ] [ 0 ] . baseUnit ) ;
1172+ } ) ;
11641173 } ) ;
11651174} ) ;
You can’t perform that action at this time.
0 commit comments