diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-01-05 06:54:40 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-01-05 06:54:40 +0800 |
commit | 6c99d09404d4b0a43d49c7a98351018f61229542 (patch) | |
tree | 50539e7b24b1386ec2c5f7fc456d7a1e80bb958d | |
parent | ead8a05034e22da36d2a0d02109f3de35f1785f1 (diff) | |
download | tangerine-wallet-browser-6c99d09404d4b0a43d49c7a98351018f61229542.tar tangerine-wallet-browser-6c99d09404d4b0a43d49c7a98351018f61229542.tar.gz tangerine-wallet-browser-6c99d09404d4b0a43d49c7a98351018f61229542.tar.bz2 tangerine-wallet-browser-6c99d09404d4b0a43d49c7a98351018f61229542.tar.lz tangerine-wallet-browser-6c99d09404d4b0a43d49c7a98351018f61229542.tar.xz tangerine-wallet-browser-6c99d09404d4b0a43d49c7a98351018f61229542.tar.zst tangerine-wallet-browser-6c99d09404d4b0a43d49c7a98351018f61229542.zip |
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.
-rw-r--r-- | app/scripts/lib/eth-store.js | 22 |
1 files changed, 10 insertions, 12 deletions
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) } |