@@ -140,14 +140,23 @@ async function loadExchangeRateCache(): Promise<ExchangeRateCacheFile> {
140140 const { cryptoPairs, fiatPairs, rates } = asExchangeRateCacheFile ( json )
141141
142142 // Keep un-expired asset pairs:
143+ const cryptoPairsMap = new Map < string , CryptoFiatPair > ( )
143144 for ( const pair of cryptoPairs ) {
144145 if ( pair . expiration < now ) continue
145- out . cryptoPairs . push ( pair )
146+ const tokenIdStr =
147+ pair . asset . tokenId != null ? `_${ pair . asset . tokenId } ` : ''
148+ const key = `${ pair . asset . pluginId } ${ tokenIdStr } _${ pair . targetFiat } `
149+ cryptoPairsMap . set ( key , { ...pair , isoDate : undefined } )
146150 }
151+ out . cryptoPairs = Array . from ( cryptoPairsMap . values ( ) )
152+
153+ const fiatPairsMap = new Map < string , FiatFiatPair > ( )
147154 for ( const pair of fiatPairs ) {
148155 if ( pair . expiration < now ) continue
149- out . fiatPairs . push ( pair )
156+ const key = `${ pair . fiatCode } _${ pair . targetFiat } `
157+ fiatPairsMap . set ( key , { ...pair , isoDate : undefined } )
150158 }
159+ out . fiatPairs = Array . from ( fiatPairsMap . values ( ) )
151160
152161 // Keep un-expired rates:
153162 for ( const [ pluginId , tokenObj ] of Object . entries ( rates . crypto ) ) {
@@ -415,22 +424,23 @@ async function fetchExchangeRates(
415424 for ( const [ pluginId , tokenObj ] of Object . entries ( rates . crypto ) ) {
416425 for ( const [ tokenId , rateObj ] of Object . entries ( tokenObj ) ) {
417426 for ( const targetFiat of Object . keys ( rateObj ) ) {
427+ const edgeTokenId = tokenId === '' ? null : tokenId
418428 const cryptoPairIndex = cryptoPairCache . findIndex (
419429 pair =>
420430 pair . asset . pluginId === pluginId &&
421- pair . asset . tokenId === tokenId &&
431+ pair . asset . tokenId === edgeTokenId &&
422432 pair . targetFiat === targetFiat
423433 )
424434 if ( cryptoPairIndex === - 1 ) {
425435 cryptoPairCache . push ( {
426- asset : { pluginId, tokenId } ,
436+ asset : { pluginId, tokenId : edgeTokenId } ,
427437 targetFiat,
428438 isoDate : undefined ,
429439 expiration : pairCacheExpiration
430440 } )
431441 } else {
432442 cryptoPairCache [ cryptoPairIndex ] = {
433- asset : { pluginId, tokenId } ,
443+ asset : { pluginId, tokenId : edgeTokenId } ,
434444 targetFiat,
435445 isoDate : undefined ,
436446 expiration : pairCacheExpiration
0 commit comments