aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-08-22 07:49:24 +0800
committerkumavis <aaron@kumavis.me>2018-08-22 07:49:24 +0800
commita2654108bed88db5cd09c22049471c5c3f1199d6 (patch)
tree051bbe917635163a646d567ff092c17f078a76b7 /app
parent3ac2b40dcf4b60f13184ff8b97f9099a6a22852e (diff)
downloadtangerine-wallet-browser-a2654108bed88db5cd09c22049471c5c3f1199d6.tar
tangerine-wallet-browser-a2654108bed88db5cd09c22049471c5c3f1199d6.tar.gz
tangerine-wallet-browser-a2654108bed88db5cd09c22049471c5c3f1199d6.tar.bz2
tangerine-wallet-browser-a2654108bed88db5cd09c22049471c5c3f1199d6.tar.lz
tangerine-wallet-browser-a2654108bed88db5cd09c22049471c5c3f1199d6.tar.xz
tangerine-wallet-browser-a2654108bed88db5cd09c22049471c5c3f1199d6.tar.zst
tangerine-wallet-browser-a2654108bed88db5cd09c22049471c5c3f1199d6.zip
account-tracker - only track blocks when there are activeControllerConnections
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/account-tracker.js18
-rw-r--r--app/scripts/metamask-controller.js8
2 files changed, 24 insertions, 2 deletions
diff --git a/app/scripts/lib/account-tracker.js b/app/scripts/lib/account-tracker.js
index b7e2c7cbe..3a52d5e8d 100644
--- a/app/scripts/lib/account-tracker.js
+++ b/app/scripts/lib/account-tracker.js
@@ -43,10 +43,24 @@ class AccountTracker {
this._provider = opts.provider
this._query = pify(new EthQuery(this._provider))
this._blockTracker = opts.blockTracker
- // subscribe to latest block
- this._blockTracker.on('latest', this._updateForBlock.bind(this))
// blockTracker.currentBlock may be null
this._currentBlockNumber = this._blockTracker.getCurrentBlock()
+ // bind function for easier listener syntax
+ this._updateForBlock = this._updateForBlock.bind(this)
+ }
+
+ start () {
+ // remove first to avoid double add
+ this._blockTracker.removeListener('latest', this._updateForBlock)
+ // add listener
+ this._blockTracker.addListener('latest', this._updateForBlock)
+ // fetch account balances
+ this._updateAccounts()
+ }
+
+ stop () {
+ // remove listener
+ this._blockTracker.removeListener('latest', this._updateForBlock)
}
/**
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 9082daac9..71df45ba0 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -131,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]