mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
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.
This commit is contained in:
parent
ead8a05034
commit
6c99d09404
@ -43,7 +43,7 @@ EthereumStore.prototype.addAccount = function (address) {
|
|||||||
self._currentState.accounts[address] = {}
|
self._currentState.accounts[address] = {}
|
||||||
self._didUpdate()
|
self._didUpdate()
|
||||||
if (!self.currentBlockNumber) return
|
if (!self.currentBlockNumber) return
|
||||||
self._updateAccount(self.currentBlockNumber, address, noop)
|
self._updateAccount(address, noop)
|
||||||
}
|
}
|
||||||
|
|
||||||
EthereumStore.prototype.removeAccount = function (address) {
|
EthereumStore.prototype.removeAccount = function (address) {
|
||||||
@ -87,37 +87,35 @@ EthereumStore.prototype._updateForBlock = function (block) {
|
|||||||
], function (err) {
|
], function (err) {
|
||||||
if (err) return console.error(err)
|
if (err) return console.error(err)
|
||||||
self.emit('block', self.getState())
|
self.emit('block', self.getState())
|
||||||
|
self._didUpdate()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
EthereumStore.prototype._updateAccounts = function (cb) {
|
EthereumStore.prototype._updateAccounts = function (cb) {
|
||||||
const self = this
|
var accountsState = this._currentState.accounts
|
||||||
var accountsState = self._currentState.accounts
|
|
||||||
var addresses = Object.keys(accountsState)
|
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) {
|
EthereumStore.prototype._updateAccount = function (address, cb) {
|
||||||
const self = this
|
var accountsState = this._currentState.accounts
|
||||||
var accountsState = self._currentState.accounts
|
this.getAccount(address, function (err, result) {
|
||||||
self._query.getAccount(address, function (err, result) {
|
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
result.address = address
|
result.address = address
|
||||||
// only populate if the entry is still present
|
// only populate if the entry is still present
|
||||||
if (accountsState[address]) {
|
if (accountsState[address]) {
|
||||||
accountsState[address] = result
|
accountsState[address] = result
|
||||||
self._didUpdate()
|
|
||||||
}
|
}
|
||||||
cb(null, result)
|
cb(null, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
EthereumStore.prototype.getAccount = function (address, cb) {
|
EthereumStore.prototype.getAccount = function (address, cb) {
|
||||||
const block = 'latest'
|
const query = this._query
|
||||||
async.parallel({
|
async.parallel({
|
||||||
balance: this._query.getBalance.bind(this, address, block),
|
balance: query.getBalance.bind(query, address),
|
||||||
nonce: this._query.getNonce.bind(this, address, block),
|
nonce: query.getTransactionCount.bind(query, address),
|
||||||
code: this._query.getCode.bind(this, address, block),
|
code: query.getCode.bind(query, address),
|
||||||
}, cb)
|
}, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user