aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers
diff options
context:
space:
mode:
authorbitpshr <mail@bitpshr.net>2018-04-20 02:37:08 +0800
committerbitpshr <mail@bitpshr.net>2018-04-20 02:37:08 +0800
commit9c7eafc86f1d9d06dd6a5b66ecd2154b09299d03 (patch)
tree0f2f3acbf39e43e86b92c4fe3af194c48186c1aa /app/scripts/controllers
parent1ef6528921263fb9dbae35476a1d9827e1d87508 (diff)
downloadtangerine-wallet-browser-9c7eafc86f1d9d06dd6a5b66ecd2154b09299d03.tar
tangerine-wallet-browser-9c7eafc86f1d9d06dd6a5b66ecd2154b09299d03.tar.gz
tangerine-wallet-browser-9c7eafc86f1d9d06dd6a5b66ecd2154b09299d03.tar.bz2
tangerine-wallet-browser-9c7eafc86f1d9d06dd6a5b66ecd2154b09299d03.tar.lz
tangerine-wallet-browser-9c7eafc86f1d9d06dd6a5b66ecd2154b09299d03.tar.xz
tangerine-wallet-browser-9c7eafc86f1d9d06dd6a5b66ecd2154b09299d03.tar.zst
tangerine-wallet-browser-9c7eafc86f1d9d06dd6a5b66ecd2154b09299d03.zip
Add more documentation to computed balances controller
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r--app/scripts/controllers/computed-balances.js37
1 files changed, 36 insertions, 1 deletions
diff --git a/app/scripts/controllers/computed-balances.js b/app/scripts/controllers/computed-balances.js
index 907b087cf..cf2e05333 100644
--- a/app/scripts/controllers/computed-balances.js
+++ b/app/scripts/controllers/computed-balances.js
@@ -2,8 +2,16 @@ const ObservableStore = require('obs-store')
const extend = require('xtend')
const BalanceController = require('./balance')
+/**
+ * Background controller responsible for syncing
+ * and computing ETH balances for all accounts
+ */
class ComputedbalancesController {
-
+ /**
+ * Creates a new controller instance
+ *
+ * @param {Object} [opts] Controller configuration parameters
+ */
constructor (opts = {}) {
const { accountTracker, txController, blockTracker } = opts
this.accountTracker = accountTracker
@@ -19,6 +27,9 @@ class ComputedbalancesController {
this._initBalanceUpdating()
}
+ /**
+ * Updates balances associated with each internal address
+ */
updateAllBalances () {
Object.keys(this.balances).forEach((balance) => {
const address = balance.address
@@ -26,12 +37,23 @@ class ComputedbalancesController {
})
}
+ /**
+ * Initializes internal address tracking
+ *
+ * @private
+ */
_initBalanceUpdating () {
const store = this.accountTracker.store.getState()
this.syncAllAccountsFromStore(store)
this.accountTracker.store.subscribe(this.syncAllAccountsFromStore.bind(this))
}
+ /**
+ * Uses current account state to sync and track all
+ * addresses associated with the current account
+ *
+ * @param {Object} store Account tracking state
+ */
syncAllAccountsFromStore (store) {
const upstream = Object.keys(store.accounts)
const balances = Object.keys(this.balances)
@@ -50,6 +72,13 @@ class ComputedbalancesController {
})
}
+ /**
+ * Conditionally establishes a new subscription
+ * to track an address associated with the current
+ * account
+ *
+ * @param {string} address Address to conditionally subscribe to
+ */
trackAddressIfNotAlready (address) {
const state = this.store.getState()
if (!(address in state.computedBalances)) {
@@ -57,6 +86,12 @@ class ComputedbalancesController {
}
}
+ /**
+ * Establishes a new subscription to track an
+ * address associated with the current account
+ *
+ * @param {string} address Address to conditionally subscribe to
+ */
trackAddress (address) {
const updater = new BalanceController({
address,