aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r--app/scripts/controllers/balance.js23
-rw-r--r--app/scripts/controllers/computed-balances.js10
2 files changed, 18 insertions, 15 deletions
diff --git a/app/scripts/controllers/balance.js b/app/scripts/controllers/balance.js
index ddeb06cf9..964dff0df 100644
--- a/app/scripts/controllers/balance.js
+++ b/app/scripts/controllers/balance.js
@@ -5,10 +5,11 @@ const BN = require('ethereumjs-util').BN
class BalanceController {
constructor (opts = {}) {
- const { address, accountTracker, txController } = opts
+ const { address, accountTracker, txController, blockTracker } = opts
this.address = address
this.accountTracker = accountTracker
this.txController = txController
+ this.blockTracker = blockTracker
const initState = {
ethBalance: undefined,
@@ -16,11 +17,11 @@ class BalanceController {
this.store = new ObservableStore(initState)
this.balanceCalc = new PendingBalanceCalculator({
- getBalance: () => Promise.resolve(this._getBalance()),
+ getBalance: () => this._getBalance(),
getPendingTransactions: this._getPendingTransactions.bind(this),
})
- this.registerUpdates()
+ this._registerUpdates()
}
async updateBalance () {
@@ -30,29 +31,29 @@ class BalanceController {
})
}
- registerUpdates () {
+ _registerUpdates () {
const update = this.updateBalance.bind(this)
this.txController.on('submitted', update)
this.txController.on('confirmed', update)
this.txController.on('failed', update)
- this.txController.blockTracker.on('block', update)
+ this.accountTracker.store.subscribe(update)
+ this.blockTracker.on('block', update)
}
- _getBalance () {
- const store = this.accountTracker.getState()
- const balances = store.accounts
- const entry = balances[this.address]
+ async _getBalance () {
+ const { accounts } = this.accountTracker.store.getState()
+ const entry = accounts[this.address]
const balance = entry.balance
return balance ? new BN(balance.substring(2), 16) : undefined
}
- _getPendingTransactions () {
+ async _getPendingTransactions () {
const pending = this.txController.getFilteredTxList({
from: this.address,
status: 'submitted',
err: undefined,
})
- return Promise.resolve(pending)
+ return pending
}
}
diff --git a/app/scripts/controllers/computed-balances.js b/app/scripts/controllers/computed-balances.js
index 576746164..2479e1b3a 100644
--- a/app/scripts/controllers/computed-balances.js
+++ b/app/scripts/controllers/computed-balances.js
@@ -5,9 +5,10 @@ const BalanceController = require('./balance')
class ComputedbalancesController {
constructor (opts = {}) {
- const { accountTracker, txController } = opts
+ const { accountTracker, txController, blockTracker } = opts
this.accountTracker = accountTracker
this.txController = txController
+ this.blockTracker = blockTracker
const initState = extend({
computedBalances: {},
@@ -19,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) {
@@ -50,6 +51,7 @@ class ComputedbalancesController {
address,
accountTracker: this.accountTracker,
txController: this.txController,
+ blockTracker: this.blockTracker,
})
updater.store.subscribe((accountBalance) => {
let newState = this.store.getState()