File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ export class CurrencyManager<TMeta = unknown> implements CurrencyTypes.ICurrency
2020 private readonly legacyTokens : CurrencyTypes . LegacyTokenMap ;
2121 private readonly conversionPairs : CurrencyTypes . AggregatorsMap ;
2222
23+ private readonly knownCurrenciesById : Map < string , CurrencyTypes . CurrencyDefinition < TMeta > > ;
24+
2325 private static defaultInstance : CurrencyManager ;
2426
2527 /**
@@ -41,6 +43,10 @@ export class CurrencyManager<TMeta = unknown> implements CurrencyTypes.ICurrency
4143 }
4244 this . knownCurrencies . push ( currency ) ;
4345 }
46+
47+ this . knownCurrenciesById = new Map (
48+ this . knownCurrencies . map ( ( knownCurrency ) => [ knownCurrency . id , knownCurrency ] ) ,
49+ ) ;
4450 this . legacyTokens = legacyTokens || CurrencyManager . getDefaultLegacyTokens ( ) ;
4551 this . conversionPairs = conversionPairs || CurrencyManager . getDefaultConversionPairs ( ) ;
4652 }
@@ -84,7 +90,7 @@ export class CurrencyManager<TMeta = unknown> implements CurrencyTypes.ICurrency
8490 * Gets a supported currency from its CurrencyTypes.CurrencyDefinition id
8591 */
8692 fromId ( id : string ) : CurrencyTypes . CurrencyDefinition < TMeta > | undefined {
87- return this . knownCurrencies . find ( ( knownCurrency ) => knownCurrency . id === id ) ;
93+ return this . knownCurrenciesById . get ( id ) ;
8894 }
8995
9096 /**
Original file line number Diff line number Diff line change @@ -153,6 +153,13 @@ describe('CurrencyManager', () => {
153153 } ) ;
154154
155155 describe ( 'Accessing currencies' , ( ) => {
156+ it ( 'access a common token by its id' , ( ) => {
157+ expect ( currencyManager . fromId ( 'USDC-multichain-moonbeam' ) ) . toMatchObject ( {
158+ symbol : 'USDC-multichain' ,
159+ decimals : 6 ,
160+ } ) ;
161+ } ) ;
162+
156163 it ( 'access a common token by its symbol' , ( ) => {
157164 expect ( currencyManager . from ( 'DAI' ) ) . toMatchObject ( {
158165 symbol : 'DAI' ,
You can’t perform that action at this time.
0 commit comments