From 75177ce34cac589be26fb8089aac04feccdbae81 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 18 Oct 2017 15:08:34 -0700 Subject: Make account tracking more reactive We were doing a lot of conditional observation & updating. Pulled out a bunch of that for generic observer/syncers. --- app/scripts/lib/account-tracker.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app/scripts/lib/account-tracker.js') 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] = {} -- cgit v1.2.3