@@ -4,7 +4,7 @@ import { NetworkName } from 'networks/types';
44import ObservableStore from 'obs-store' ;
55import Browser from 'webextension-polyfill' ;
66
7- import { defaultAssetTickers , stablecoinAssetIds } from '../assets/constants' ;
7+ import { defaultAssetTickers } from '../assets/constants' ;
88import { ExtensionStorage , StorageLocalState } from '../storage/storage' ;
99import { NetworkController } from './network' ;
1010import { RemoteConfigController } from './remoteConfig' ;
@@ -30,12 +30,8 @@ const SUSPICIOUS_LIST_URL =
3030const SUSPICIOUS_PERIOD_IN_MINUTES = 60 ;
3131const MAX_AGE = 60 * 60 * 1000 ;
3232
33- const MARKETDATA_URL = 'https://marketdata.wavesplatform.com/' ;
34- const MARKETDATA_USD_ASSET_ID = 'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p' ;
35- const MARKETDATA_PERIOD_IN_MINUTES = 10 ;
36-
37- const STATIC_SERVICE_URL = 'https://api.keeper-wallet.app' ;
38- const SWAPSERVICE_URL = 'https://swap-api.keeper-wallet.app' ;
33+ const DATA_SERVICE_URL = 'https://api.keeper-wallet.app' ;
34+ const SWAP_SERVICE_URL = 'https://swap-api.keeper-wallet.app' ;
3935
4036const INFO_PERIOD_IN_MINUTES = 60 ;
4137const SWAPPABLE_ASSETS_UPDATE_PERIOD_IN_MINUTES = 240 ;
@@ -123,19 +119,12 @@ export class AssetInfoController {
123119 this . updateSuspiciousAssets ( ) ;
124120 }
125121
126- if ( Object . keys ( initState . usdPrices ) . length === 0 ) {
127- this . updateUsdPrices ( ) ;
128- }
129-
130122 this . updateInfo ( ) ;
131123 this . updateSwappableAssetIdsByVendor ( ) ;
132124
133125 Browser . alarms . create ( 'updateSuspiciousAssets' , {
134126 periodInMinutes : SUSPICIOUS_PERIOD_IN_MINUTES ,
135127 } ) ;
136- Browser . alarms . create ( 'updateUsdPrices' , {
137- periodInMinutes : MARKETDATA_PERIOD_IN_MINUTES ,
138- } ) ;
139128 Browser . alarms . create ( 'updateInfo' , {
140129 periodInMinutes : INFO_PERIOD_IN_MINUTES ,
141130 } ) ;
@@ -148,9 +137,6 @@ export class AssetInfoController {
148137 case 'updateSuspiciousAssets' :
149138 this . updateSuspiciousAssets ( ) ;
150139 break ;
151- case 'updateUsdPrices' :
152- this . updateUsdPrices ( ) ;
153- break ;
154140 case 'updateInfo' :
155141 this . updateInfo ( ) ;
156142 break ;
@@ -392,49 +378,39 @@ export class AssetInfoController {
392378 }
393379 }
394380
395- async updateUsdPrices ( ) {
396- const { usdPrices } = this . store . getState ( ) ;
381+ async updateUsdPricesByAssetIds ( assetIds : string [ ] ) {
397382 const network = this . getNetwork ( ) ;
398383
399- if ( ! usdPrices || network === NetworkName . Mainnet ) {
400- const resp = await fetch ( new URL ( '/api/tickers' , MARKETDATA_URL ) ) ;
384+ if ( assetIds . length === 0 || network !== NetworkName . Mainnet ) {
385+ return ;
386+ }
401387
402- if ( resp . ok ) {
403- const tickers = ( await resp . json ( ) ) as Array < {
404- '24h_close' : string ;
405- amountAssetID : string ;
406- priceAssetID : string ;
407- } > ;
388+ const { usdPrices } = this . store . getState ( ) ;
408389
409- // eslint-disable-next-line @typescript-eslint/no-shadow
410- const usdPrices = tickers . reduce < Record < string , string > > (
411- ( acc , ticker ) => {
412- if (
413- ! stablecoinAssetIds . has ( ticker . amountAssetID ) &&
414- ticker . priceAssetID === MARKETDATA_USD_ASSET_ID
415- ) {
416- acc [ ticker . amountAssetID ] = ticker [ '24h_close' ] ;
417- }
390+ const response = await fetch ( new URL ( '/api/v1/rates' , DATA_SERVICE_URL ) , {
391+ method : 'POST' ,
392+ body : JSON . stringify ( { ids : assetIds } ) ,
393+ } ) ;
418394
419- return acc ;
420- } ,
421- { }
422- ) ;
395+ if ( ! response . ok ) {
396+ throw response ;
397+ }
423398
424- stablecoinAssetIds . forEach ( ticker => {
425- usdPrices [ ticker ] = '1' ;
426- } ) ;
399+ const updatedUsdPrices : Record < string , string > = await response . json ( ) ;
427400
428- this . store . updateState ( { usdPrices } ) ;
429- }
430- }
401+ this . store . updateState ( {
402+ usdPrices : {
403+ ...usdPrices ,
404+ ...updatedUsdPrices ,
405+ } ,
406+ } ) ;
431407 }
432408
433409 async updateInfo ( ) {
434410 const network = this . getNetwork ( ) ;
435411
436412 if ( network === NetworkName . Mainnet ) {
437- const resp = await fetch ( new URL ( '/api/v1/assets' , STATIC_SERVICE_URL ) ) ;
413+ const resp = await fetch ( new URL ( '/api/v1/assets' , DATA_SERVICE_URL ) ) ;
438414
439415 if ( resp . ok ) {
440416 const assets = ( await resp . json ( ) ) as Array < {
@@ -463,7 +439,7 @@ export class AssetInfoController {
463439 }
464440
465441 async updateSwappableAssetIdsByVendor ( ) {
466- const resp = await fetch ( new URL ( '/assets' , SWAPSERVICE_URL ) ) ;
442+ const resp = await fetch ( new URL ( '/assets' , SWAP_SERVICE_URL ) ) ;
467443 if ( resp . ok ) {
468444 const swappableAssetIdsByVendor = ( await resp . json ( ) ) as Record <
469445 string ,
0 commit comments