mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
move activation logic into token rates controller (#8744)
This commit is contained in:
parent
7fcf625549
commit
456684ee7d
@ -17,11 +17,10 @@ export default class TokenRatesController {
|
|||||||
*
|
*
|
||||||
* @param {Object} [config] - Options to configure controller
|
* @param {Object} [config] - Options to configure controller
|
||||||
*/
|
*/
|
||||||
constructor ({ interval = DEFAULT_INTERVAL, currency, preferences } = {}) {
|
constructor ({ currency, preferences } = {}) {
|
||||||
this.store = new ObservableStore()
|
this.store = new ObservableStore()
|
||||||
this.currency = currency
|
this.currency = currency
|
||||||
this.preferences = preferences
|
this.preferences = preferences
|
||||||
this.interval = interval
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,19 +49,6 @@ export default class TokenRatesController {
|
|||||||
this.store.putState({ contractExchangeRates })
|
this.store.putState({ contractExchangeRates })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {Number}
|
|
||||||
*/
|
|
||||||
set interval (interval) {
|
|
||||||
this._handle && clearInterval(this._handle)
|
|
||||||
if (!interval) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this._handle = setInterval(() => {
|
|
||||||
this.updateExchangeRates()
|
|
||||||
}, interval)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
@ -85,4 +71,19 @@ export default class TokenRatesController {
|
|||||||
this._tokens = tokens
|
this._tokens = tokens
|
||||||
this.updateExchangeRates()
|
this.updateExchangeRates()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start (interval = DEFAULT_INTERVAL) {
|
||||||
|
this._handle && clearInterval(this._handle)
|
||||||
|
if (!interval) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this._handle = setInterval(() => {
|
||||||
|
this.updateExchangeRates()
|
||||||
|
}, interval)
|
||||||
|
this.updateExchangeRates()
|
||||||
|
}
|
||||||
|
|
||||||
|
stop () {
|
||||||
|
this._handle && clearInterval(this._handle)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,9 +170,11 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
if (activeControllerConnections > 0) {
|
if (activeControllerConnections > 0) {
|
||||||
this.accountTracker.start()
|
this.accountTracker.start()
|
||||||
this.incomingTransactionsController.start()
|
this.incomingTransactionsController.start()
|
||||||
|
this.tokenRatesController.start()
|
||||||
} else {
|
} else {
|
||||||
this.accountTracker.stop()
|
this.accountTracker.stop()
|
||||||
this.incomingTransactionsController.stop()
|
this.incomingTransactionsController.stop()
|
||||||
|
this.tokenRatesController.stop()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -281,10 +283,6 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
this.encryptionPublicKeyManager = new EncryptionPublicKeyManager()
|
this.encryptionPublicKeyManager = new EncryptionPublicKeyManager()
|
||||||
this.typedMessageManager = new TypedMessageManager({ networkController: this.networkController })
|
this.typedMessageManager = new TypedMessageManager({ networkController: this.networkController })
|
||||||
|
|
||||||
// ensure isClientOpenAndUnlocked is updated when memState updates
|
|
||||||
this.on('update', (memState) => {
|
|
||||||
this.isClientOpenAndUnlocked = memState.isUnlocked && this._isClientOpen
|
|
||||||
})
|
|
||||||
|
|
||||||
this.store.updateStructure({
|
this.store.updateStructure({
|
||||||
AppStateController: this.appStateController.store,
|
AppStateController: this.appStateController.store,
|
||||||
@ -2032,20 +2030,9 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
set isClientOpen (open) {
|
set isClientOpen (open) {
|
||||||
this._isClientOpen = open
|
this._isClientOpen = open
|
||||||
this.isClientOpenAndUnlocked = this.isUnlocked() && open
|
|
||||||
this.detectTokensController.isOpen = open
|
this.detectTokensController.isOpen = open
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A method for activating the retrieval of price data,
|
|
||||||
* which should only be fetched when the UI is visible.
|
|
||||||
* @private
|
|
||||||
* @param {boolean} active - True if price data should be getting fetched.
|
|
||||||
*/
|
|
||||||
set isClientOpenAndUnlocked (active) {
|
|
||||||
this.tokenRatesController.isActive = active
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates RPC engine middleware for processing eth_signTypedData requests
|
* Creates RPC engine middleware for processing eth_signTypedData requests
|
||||||
*
|
*
|
||||||
|
@ -13,8 +13,11 @@ describe('TokenRatesController', function () {
|
|||||||
|
|
||||||
it('should poll on correct interval', async function () {
|
it('should poll on correct interval', async function () {
|
||||||
const stub = sinon.stub(global, 'setInterval')
|
const stub = sinon.stub(global, 'setInterval')
|
||||||
new TokenRatesController({ interval: 1337 }) // eslint-disable-line no-new
|
const rateController = new TokenRatesController() // eslint-disable-line no-new
|
||||||
|
rateController.start(1337)
|
||||||
|
|
||||||
assert.strictEqual(stub.getCall(0).args[1], 1337)
|
assert.strictEqual(stub.getCall(0).args[1], 1337)
|
||||||
stub.restore()
|
stub.restore()
|
||||||
|
rateController.stop()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user