aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
authorDan Finlay <542863+danfinlay@users.noreply.github.com>2018-08-23 04:31:42 +0800
committerGitHub <noreply@github.com>2018-08-23 04:31:42 +0800
commitf30b726df79f1ffe0ba088dba9f3ca730ee7d103 (patch)
tree8829957eae2f9013dc6def202ff11dcf9280035b /app/scripts/metamask-controller.js
parentf495c0e9e03fff740bce5e94c0d14254c2c497e2 (diff)
parentbf6d624e769eb5486b5c491165fad1862435669b (diff)
downloadtangerine-wallet-browser-f30b726df79f1ffe0ba088dba9f3ca730ee7d103.tar
tangerine-wallet-browser-f30b726df79f1ffe0ba088dba9f3ca730ee7d103.tar.gz
tangerine-wallet-browser-f30b726df79f1ffe0ba088dba9f3ca730ee7d103.tar.bz2
tangerine-wallet-browser-f30b726df79f1ffe0ba088dba9f3ca730ee7d103.tar.lz
tangerine-wallet-browser-f30b726df79f1ffe0ba088dba9f3ca730ee7d103.tar.xz
tangerine-wallet-browser-f30b726df79f1ffe0ba088dba9f3ca730ee7d103.tar.zst
tangerine-wallet-browser-f30b726df79f1ffe0ba088dba9f3ca730ee7d103.zip
Merge pull request #5122 from MetaMask/lazy-account-tracker
Network IO Optimization: Lazy AccountTracker
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 4ee88186a..a6215d51b 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -67,6 +67,10 @@ module.exports = class MetamaskController extends EventEmitter {
const initState = opts.initState || {}
this.recordFirstTimeInfo(initState)
+ // this keeps track of how many "controllerStream" connections are open
+ // the only thing that uses controller connections are open metamask UI instances
+ this.activeControllerConnections = 0
+
// platform-specific api
this.platform = opts.platform
@@ -127,6 +131,14 @@ module.exports = class MetamaskController extends EventEmitter {
provider: this.provider,
blockTracker: this.blockTracker,
})
+ // start and stop polling for balances based on activeControllerConnections
+ this.on('controllerConnectionChanged', (activeControllerConnections) => {
+ if (activeControllerConnections > 0) {
+ this.accountTracker.start()
+ } else {
+ this.accountTracker.stop()
+ }
+ })
// key mgmt
const additionalKeyrings = [TrezorKeyring, LedgerBridgeKeyring]
@@ -1197,11 +1209,19 @@ module.exports = class MetamaskController extends EventEmitter {
setupControllerConnection (outStream) {
const api = this.getApi()
const dnode = Dnode(api)
+ // report new active controller connection
+ this.activeControllerConnections++
+ this.emit('controllerConnectionChanged', this.activeControllerConnections)
+ // connect dnode api to remote connection
pump(
outStream,
dnode,
outStream,
(err) => {
+ // report new active controller connection
+ this.activeControllerConnections--
+ this.emit('controllerConnectionChanged', this.activeControllerConnections)
+ // report any error
if (err) log.error(err)
}
)
@@ -1440,6 +1460,7 @@ module.exports = class MetamaskController extends EventEmitter {
}
}
+ // TODO: Replace isClientOpen methods with `controllerConnectionChanged` events.
/**
* A method for recording whether the MetaMask user interface is open or not.
* @private