From 6c99d09404d4b0a43d49c7a98351018f61229542 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 4 Jan 2017 14:54:40 -0800 Subject: Fixed bugs with sanity-checking - Was incorrectly calling some eth-query methods (left over from old local eth-query) - Was still passing block to getAccount in addAccount - Now emitting update only after all account balances are loaded, reducing UI update traffic. --- app/scripts/lib/eth-store.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/scripts/lib/eth-store.js b/app/scripts/lib/eth-store.js index 3b5501095..a42b2417f 100644 --- a/app/scripts/lib/eth-store.js +++ b/app/scripts/lib/eth-store.js @@ -43,7 +43,7 @@ EthereumStore.prototype.addAccount = function (address) { self._currentState.accounts[address] = {} self._didUpdate() if (!self.currentBlockNumber) return - self._updateAccount(self.currentBlockNumber, address, noop) + self._updateAccount(address, noop) } EthereumStore.prototype.removeAccount = function (address) { @@ -87,37 +87,35 @@ EthereumStore.prototype._updateForBlock = function (block) { ], function (err) { if (err) return console.error(err) self.emit('block', self.getState()) + self._didUpdate() }) } EthereumStore.prototype._updateAccounts = function (cb) { - const self = this - var accountsState = self._currentState.accounts + var accountsState = this._currentState.accounts var addresses = Object.keys(accountsState) - async.each(addresses, self._updateAccount.bind(self), cb) + async.each(addresses, this._updateAccount.bind(this), cb) } EthereumStore.prototype._updateAccount = function (address, cb) { - const self = this - var accountsState = self._currentState.accounts - self._query.getAccount(address, function (err, result) { + var accountsState = this._currentState.accounts + this.getAccount(address, function (err, result) { if (err) return cb(err) result.address = address // only populate if the entry is still present if (accountsState[address]) { accountsState[address] = result - self._didUpdate() } cb(null, result) }) } EthereumStore.prototype.getAccount = function (address, cb) { - const block = 'latest' + const query = this._query async.parallel({ - balance: this._query.getBalance.bind(this, address, block), - nonce: this._query.getNonce.bind(this, address, block), - code: this._query.getCode.bind(this, address, block), + balance: query.getBalance.bind(query, address), + nonce: query.getTransactionCount.bind(query, address), + code: query.getCode.bind(query, address), }, cb) } -- cgit