aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-10-19 06:08:34 +0800
committerDan Finlay <dan@danfinlay.com>2017-10-19 06:08:34 +0800
commit75177ce34cac589be26fb8089aac04feccdbae81 (patch)
treeb4a8071a787634b8c4fee179e22d0ae2131a9c97 /app/scripts/controllers
parent9cc1e8a6d867b7f0663c55b017b471132f6a719e (diff)
downloadtangerine-wallet-browser-75177ce34cac589be26fb8089aac04feccdbae81.tar.gz
tangerine-wallet-browser-75177ce34cac589be26fb8089aac04feccdbae81.tar.zst
tangerine-wallet-browser-75177ce34cac589be26fb8089aac04feccdbae81.zip
Make account tracking more reactive
We were doing a lot of conditional observation & updating. Pulled out a bunch of that for generic observer/syncers.
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r--app/scripts/controllers/computed-balances.js22
1 files changed, 14 insertions, 8 deletions
diff --git a/app/scripts/controllers/computed-balances.js b/app/scripts/controllers/computed-balances.js
index 3479eae2b..009405d29 100644
--- a/app/scripts/controllers/computed-balances.js
+++ b/app/scripts/controllers/computed-balances.js
@@ -25,22 +25,28 @@ class ComputedbalancesController {
}
}
- forgetAllBalances () {
- this.balances = {}
- }
-
_initBalanceUpdating () {
const store = this.accountTracker.store.getState()
- this.addAnyAccountsFromStore(store)
- this.accountTracker.store.subscribe(this.addAnyAccountsFromStore.bind(this))
+ this.syncAllAccountsFromStore(store)
+ this.accountTracker.store.subscribe(this.syncAllAccountsFromStore.bind(this))
}
- addAnyAccountsFromStore(store) {
- const balances = store.accounts
+ syncAllAccountsFromStore(store) {
+ const upstream = Object.keys(store.accounts)
+ const balances = Object.keys(this.balances)
+ .map(address => this.balances[address])
+ // Follow new addresses
for (let address in balances) {
this.trackAddressIfNotAlready(address)
}
+
+ // Unfollow old ones
+ balances.forEach(({ address }) => {
+ if (!upstream.includes(address)) {
+ delete this.balances[address]
+ }
+ })
}
trackAddressIfNotAlready (address) {