|
|
|
@ -26,6 +26,7 @@ import { |
|
|
|
|
GasFeeController, |
|
|
|
|
TokenListController, |
|
|
|
|
TokensController, |
|
|
|
|
TokenRatesController, |
|
|
|
|
} from '@metamask/controllers'; |
|
|
|
|
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction'; |
|
|
|
|
import { |
|
|
|
@ -66,7 +67,6 @@ import TransactionController from './controllers/transactions'; |
|
|
|
|
import DetectTokensController from './controllers/detect-tokens'; |
|
|
|
|
import SwapsController from './controllers/swaps'; |
|
|
|
|
import { PermissionsController } from './controllers/permissions'; |
|
|
|
|
import TokenRatesController from './controllers/token-rates'; |
|
|
|
|
import { NOTIFICATION_NAMES } from './controllers/permissions/enums'; |
|
|
|
|
import getRestrictedMethods from './controllers/permissions/restrictedMethods'; |
|
|
|
|
import nodeify from './lib/nodeify'; |
|
|
|
@ -282,12 +282,26 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
initState.NotificationController, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// token exchange rate tracker
|
|
|
|
|
this.tokenRatesController = new TokenRatesController({ |
|
|
|
|
tokensController: this.tokensController, |
|
|
|
|
getNativeCurrency: () => { |
|
|
|
|
const { ticker } = this.networkController.getProviderConfig(); |
|
|
|
|
return ticker ?? 'ETH'; |
|
|
|
|
}, |
|
|
|
|
onTokensStateChange: (listener) => |
|
|
|
|
this.tokensController.subscribe(listener), |
|
|
|
|
onCurrencyRateStateChange: (listener) => |
|
|
|
|
this.controllerMessenger.subscribe( |
|
|
|
|
`${this.currencyRateController.name}:stateChange`, |
|
|
|
|
listener, |
|
|
|
|
), |
|
|
|
|
onNetworkStateChange: (cb) => |
|
|
|
|
this.networkController.store.subscribe((networkState) => { |
|
|
|
|
const modifiedNetworkState = { |
|
|
|
|
...networkState, |
|
|
|
|
provider: { |
|
|
|
|
...networkState.provider, |
|
|
|
|
chainId: hexToDecimal(networkState.provider.chainId), |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
return cb(modifiedNetworkState); |
|
|
|
|
}), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.ensController = new EnsController({ |
|
|
|
@ -328,13 +342,11 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
if (activeControllerConnections > 0) { |
|
|
|
|
this.accountTracker.start(); |
|
|
|
|
this.incomingTransactionsController.start(); |
|
|
|
|
this.tokenRatesController.start(); |
|
|
|
|
this.currencyRateController.start(); |
|
|
|
|
this.tokenListController.start(); |
|
|
|
|
} else { |
|
|
|
|
this.accountTracker.stop(); |
|
|
|
|
this.incomingTransactionsController.stop(); |
|
|
|
|
this.tokenRatesController.stop(); |
|
|
|
|
this.currencyRateController.stop(); |
|
|
|
|
this.tokenListController.stop(); |
|
|
|
|
} |
|
|
|
@ -525,7 +537,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
getProviderConfig: this.networkController.getProviderConfig.bind( |
|
|
|
|
this.networkController, |
|
|
|
|
), |
|
|
|
|
tokenRatesStore: this.tokenRatesController.store, |
|
|
|
|
tokenRatesStore: this.tokenRatesController.state, |
|
|
|
|
getCurrentChainId: this.networkController.getCurrentChainId.bind( |
|
|
|
|
this.networkController, |
|
|
|
|
), |
|
|
|
@ -581,7 +593,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
AccountTracker: this.accountTracker.store, |
|
|
|
|
TxController: this.txController.memStore, |
|
|
|
|
CachedBalancesController: this.cachedBalancesController.store, |
|
|
|
|
TokenRatesController: this.tokenRatesController.store, |
|
|
|
|
TokenRatesController: this.tokenRatesController, |
|
|
|
|
MessageManager: this.messageManager.memStore, |
|
|
|
|
PersonalMessageManager: this.personalMessageManager.memStore, |
|
|
|
|
DecryptMessageManager: this.decryptMessageManager.memStore, |
|
|
|
|