diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-10-19 06:08:34 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-10-19 06:08:34 +0800 |
commit | 75177ce34cac589be26fb8089aac04feccdbae81 (patch) | |
tree | b4a8071a787634b8c4fee179e22d0ae2131a9c97 /app/scripts/lib | |
parent | 9cc1e8a6d867b7f0663c55b017b471132f6a719e (diff) | |
download | tangerine-wallet-browser-75177ce34cac589be26fb8089aac04feccdbae81.tar tangerine-wallet-browser-75177ce34cac589be26fb8089aac04feccdbae81.tar.gz tangerine-wallet-browser-75177ce34cac589be26fb8089aac04feccdbae81.tar.bz2 tangerine-wallet-browser-75177ce34cac589be26fb8089aac04feccdbae81.tar.lz tangerine-wallet-browser-75177ce34cac589be26fb8089aac04feccdbae81.tar.xz 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/lib')
-rw-r--r-- | app/scripts/lib/account-tracker.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/scripts/lib/account-tracker.js b/app/scripts/lib/account-tracker.js index cdc21282d..13dea918f 100644 --- a/app/scripts/lib/account-tracker.js +++ b/app/scripts/lib/account-tracker.js @@ -38,6 +38,24 @@ class AccountTracker extends EventEmitter { // public // + syncWithAddresses (addresses) { + const accounts = this.store.getState().accounts + const locals = Object.keys(accounts) + .map(account => accounts[account.address]) + + addresses.forEach((upstream) => { + if (!locals.includes(upstream)) { + this.addAccount(upstream) + } + }) + + locals.forEach((local) => { + if (!addresses.includes(local)) { + this.removeAccount(local) + } + }) + } + addAccount (address) { const accounts = this.store.getState().accounts accounts[address] = {} |