aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-09-27 06:17:24 +0800
committerGitHub <noreply@github.com>2017-09-27 06:17:24 +0800
commit6ca519e97c4c282023ab6b7788715ff8d7ec8189 (patch)
treec1f884dcd4f7e4af7d2846bb937aa531d1352400
parentb1daa5ae260be0aa91516bde0cbdb8820099587b (diff)
parent651098c70d21edbca98a96ef2a8800d164035638 (diff)
downloadtangerine-wallet-browser-6ca519e97c4c282023ab6b7788715ff8d7ec8189.tar.gz
tangerine-wallet-browser-6ca519e97c4c282023ab6b7788715ff8d7ec8189.tar.zst
tangerine-wallet-browser-6ca519e97c4c282023ab6b7788715ff8d7ec8189.zip
Merge pull request #2183 from MetaMask/Fix2094
Fix 2094 related issues
-rw-r--r--app/scripts/controllers/balance.js4
-rw-r--r--app/scripts/controllers/computed-balances.js6
-rw-r--r--app/scripts/lib/account-tracker.js32
-rw-r--r--app/scripts/metamask-controller.js10
4 files changed, 28 insertions, 24 deletions
diff --git a/app/scripts/controllers/balance.js b/app/scripts/controllers/balance.js
index ab0cfe907..964dff0df 100644
--- a/app/scripts/controllers/balance.js
+++ b/app/scripts/controllers/balance.js
@@ -36,12 +36,12 @@ class BalanceController {
this.txController.on('submitted', update)
this.txController.on('confirmed', update)
this.txController.on('failed', update)
- this.accountTracker.subscribe(update)
+ this.accountTracker.store.subscribe(update)
this.blockTracker.on('block', update)
}
async _getBalance () {
- const { accounts } = this.accountTracker.getState()
+ const { accounts } = this.accountTracker.store.getState()
const entry = accounts[this.address]
const balance = entry.balance
return balance ? new BN(balance.substring(2), 16) : undefined
diff --git a/app/scripts/controllers/computed-balances.js b/app/scripts/controllers/computed-balances.js
index 2b27d128d..2479e1b3a 100644
--- a/app/scripts/controllers/computed-balances.js
+++ b/app/scripts/controllers/computed-balances.js
@@ -20,15 +20,15 @@ class ComputedbalancesController {
}
updateAllBalances () {
- for (let address in this.balances) {
+ for (let address in this.accountTracker.store.getState().accounts) {
this.balances[address].updateBalance()
}
}
_initBalanceUpdating () {
- const store = this.accountTracker.getState()
+ const store = this.accountTracker.store.getState()
this.addAnyAccountsFromStore(store)
- this.accountTracker.subscribe(this.addAnyAccountsFromStore.bind(this))
+ this.accountTracker.store.subscribe(this.addAnyAccountsFromStore.bind(this))
}
addAnyAccountsFromStore(store) {
diff --git a/app/scripts/lib/account-tracker.js b/app/scripts/lib/account-tracker.js
index bf949597b..e2892b1ce 100644
--- a/app/scripts/lib/account-tracker.js
+++ b/app/scripts/lib/account-tracker.js
@@ -10,15 +10,21 @@
const async = require('async')
const EthQuery = require('eth-query')
const ObservableStore = require('obs-store')
+const EventEmitter = require('events').EventEmitter
function noop () {}
-class EthereumStore extends ObservableStore {
+class AccountTracker extends EventEmitter {
constructor (opts = {}) {
- super({
+ super()
+
+ const initState = {
accounts: {},
- })
+ currentBlockGasLimit: '',
+ }
+ this.store = new ObservableStore(initState)
+
this._provider = opts.provider
this._query = new EthQuery(this._provider)
this._blockTracker = opts.blockTracker
@@ -33,17 +39,17 @@ class EthereumStore extends ObservableStore {
//
addAccount (address) {
- const accounts = this.getState().accounts
+ const accounts = this.store.getState().accounts
accounts[address] = {}
- this.updateState({ accounts })
+ this.store.updateState({ accounts })
if (!this._currentBlockNumber) return
this._updateAccount(address)
}
removeAccount (address) {
- const accounts = this.getState().accounts
+ const accounts = this.store.getState().accounts
delete accounts[address]
- this.updateState({ accounts })
+ this.store.updateState({ accounts })
}
//
@@ -54,29 +60,31 @@ class EthereumStore extends ObservableStore {
const blockNumber = '0x' + block.number.toString('hex')
this._currentBlockNumber = blockNumber
+ this.store.updateState({ currentBlockGasLimit: `0x${block.gasLimit.toString('hex')}` })
+
async.parallel([
this._updateAccounts.bind(this),
], (err) => {
if (err) return console.error(err)
- this.emit('block', this.getState())
+ this.emit('block', this.store.getState())
})
}
_updateAccounts (cb = noop) {
- const accounts = this.getState().accounts
+ const accounts = this.store.getState().accounts
const addresses = Object.keys(accounts)
async.each(addresses, this._updateAccount.bind(this), cb)
}
_updateAccount (address, cb = noop) {
- const accounts = this.getState().accounts
this._getAccount(address, (err, result) => {
if (err) return cb(err)
result.address = address
+ const accounts = this.store.getState().accounts
// only populate if the entry is still present
if (accounts[address]) {
accounts[address] = result
- this.updateState({ accounts })
+ this.store.updateState({ accounts })
}
cb(null, result)
})
@@ -93,4 +101,4 @@ class EthereumStore extends ObservableStore {
}
-module.exports = EthereumStore
+module.exports = AccountTracker
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index cca796678..0f850b7f5 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -86,6 +86,7 @@ module.exports = class MetamaskController extends EventEmitter {
// eth data query tools
this.ethQuery = new EthQuery(this.provider)
+ // account tracker watches balances, nonces, and any code at their address.
this.accountTracker = new AccountTracker({
provider: this.provider,
blockTracker: this.blockTracker,
@@ -99,11 +100,6 @@ module.exports = class MetamaskController extends EventEmitter {
encryptor: opts.encryptor || undefined,
})
- // account tracker watches balances, nonces, and any code at their address.
- this.accountTracker = new AccountTracker({
- provider: this.provider,
- blockTracker: this.provider,
- })
this.keyringController.on('newAccount', (address) => {
this.preferencesController.setSelectedAddress(address)
this.accountTracker.addAccount(address)
@@ -194,7 +190,7 @@ module.exports = class MetamaskController extends EventEmitter {
// manual mem state subscriptions
this.networkController.store.subscribe(this.sendUpdate.bind(this))
- this.accountTracker.subscribe(this.sendUpdate.bind(this))
+ this.accountTracker.store.subscribe(this.sendUpdate.bind(this))
this.txController.memStore.subscribe(this.sendUpdate.bind(this))
this.balancesController.store.subscribe(this.sendUpdate.bind(this))
this.messageManager.memStore.subscribe(this.sendUpdate.bind(this))
@@ -277,7 +273,7 @@ module.exports = class MetamaskController extends EventEmitter {
isInitialized,
},
this.networkController.store.getState(),
- this.accountTracker.getState(),
+ this.accountTracker.store.getState(),
this.txController.memStore.getState(),
this.messageManager.memStore.getState(),
this.personalMessageManager.memStore.getState(),