aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorbitpshr <mail@bitpshr.net>2018-04-17 05:45:18 +0800
committerbitpshr <mail@bitpshr.net>2018-04-17 06:12:05 +0800
commitb4912f29cd3b6e0a5df81e9f69acc50b03e31c0c (patch)
tree16920399eb3be919d017148b299dd61d68b5d92d /app
parentd0447f90583275868bb72aa7ae8f670bf3668173 (diff)
downloadtangerine-wallet-browser-b4912f29cd3b6e0a5df81e9f69acc50b03e31c0c.tar
tangerine-wallet-browser-b4912f29cd3b6e0a5df81e9f69acc50b03e31c0c.tar.gz
tangerine-wallet-browser-b4912f29cd3b6e0a5df81e9f69acc50b03e31c0c.tar.bz2
tangerine-wallet-browser-b4912f29cd3b6e0a5df81e9f69acc50b03e31c0c.tar.lz
tangerine-wallet-browser-b4912f29cd3b6e0a5df81e9f69acc50b03e31c0c.tar.xz
tangerine-wallet-browser-b4912f29cd3b6e0a5df81e9f69acc50b03e31c0c.tar.zst
tangerine-wallet-browser-b4912f29cd3b6e0a5df81e9f69acc50b03e31c0c.zip
Disable token price polling when no client is active
Diffstat (limited to 'app')
-rw-r--r--app/scripts/background.js3
-rw-r--r--app/scripts/controllers/token-rates.js1
-rw-r--r--app/scripts/metamask-controller.js9
3 files changed, 13 insertions, 0 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 5878cd2e8..3f0e289c9 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -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') {
diff --git a/app/scripts/controllers/token-rates.js b/app/scripts/controllers/token-rates.js
index 85a8ca24e..22e3e8154 100644
--- a/app/scripts/controllers/token-rates.js
+++ b/app/scripts/controllers/token-rates.js
@@ -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
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 750a97b86..73b7cfbb0 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -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
+ }
}