1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Disable token price polling when no client is active

This commit is contained in:
bitpshr 2018-04-16 17:45:18 -04:00
parent d0447f9058
commit b4912f29cd
4 changed files with 14 additions and 0 deletions

View File

@ -200,6 +200,7 @@ function setupController (initState, initLangCode) {
if (isMetaMaskInternalProcess) {
// communication with popup
popupIsOpen = popupIsOpen || (remotePort.name === 'popup')
controller.isClientOpen = true
controller.setupTrustedCommunication(portStream, 'MetaMask')
// record popup as closed
if (remotePort.sender.url.match(/home.html$/)) {
@ -211,6 +212,8 @@ function setupController (initState, initLangCode) {
if (remotePort.sender.url.match(/home.html$/)) {
openMetamaskTabsIDs[remotePort.sender.tab.id] = false
}
controller.isClientOpen = popupIsOpen ||
Object.keys(openMetamaskTabsIDs).some(key => openMetamaskTabsIDs[key])
})
}
if (remotePort.name === 'notification') {

View File

@ -23,6 +23,7 @@ class TokenRatesController {
* Updates exchange rates for all tokens
*/
async updateExchangeRates () {
if (!this.isActive) { return }
const contractExchangeRates = {}
for (const i in this._tokens) {
const address = this._tokens[i].address

View File

@ -269,6 +269,7 @@ module.exports = class MetamaskController extends EventEmitter {
// memStore -> transform -> publicConfigStore
this.on('update', (memState) => {
this.isClientOpenAndUnlocked = memState.isUnlocked && this._isClientOpen
const publicState = selectPublicState(memState)
publicConfigStore.putState(publicState)
})
@ -1030,4 +1031,12 @@ module.exports = class MetamaskController extends EventEmitter {
}
}
set isClientOpen (open) {
this._isClientOpen = open
this.isClientOpenAndUnlocked = this.getState().isUnlocked && open
}
set isClientOpenAndUnlocked (active) {
this.tokenRatesController.isActive = active
}
}

View File

@ -20,6 +20,7 @@ describe('TokenRatesController', () => {
it('should fetch each token rate based on address', async () => {
const controller = new TokenRatesController()
controller.isActive = true
controller.fetchExchangeRate = address => address
controller.tokens = [{ address: 'foo' }, { address: 'bar' }]
await controller.updateExchangeRates()