diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-04-21 05:10:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-21 05:10:05 +0800 |
commit | 74c419f9b65841c2966d1fe3b7414bf11e09e0d8 (patch) | |
tree | b685af5f2383a6d1159ed339e29b831f094aa079 /app/scripts/controllers | |
parent | 00efcf9e8ba34d448b628c98d32ad12d5be2ffc9 (diff) | |
parent | 8636f3bae547ace7d099a3ed516bf013dfe3858e (diff) | |
download | tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.gz tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.bz2 tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.lz tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.xz tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.tar.zst tangerine-wallet-browser-74c419f9b65841c2966d1fe3b7414bf11e09e0d8.zip |
Merge pull request #4020 from MetaMask/i3941-jsdoc-bitpshr
Documentation
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r-- | app/scripts/controllers/computed-balances.js | 45 | ||||
-rw-r--r-- | app/scripts/controllers/token-rates.js | 6 |
2 files changed, 47 insertions, 4 deletions
diff --git a/app/scripts/controllers/computed-balances.js b/app/scripts/controllers/computed-balances.js index 907b087cf..1a6802f9a 100644 --- a/app/scripts/controllers/computed-balances.js +++ b/app/scripts/controllers/computed-balances.js @@ -2,8 +2,24 @@ const ObservableStore = require('obs-store') const extend = require('xtend') const BalanceController = require('./balance') -class ComputedbalancesController { +/** + * @typedef {Object} ComputedBalancesOptions + * @property {Object} accountTracker Account tracker store reference + * @property {Object} txController Token controller reference + * @property {Object} blockTracker Block tracker reference + * @property {Object} initState Initial state to populate this internal store with + */ +/** + * Background controller responsible for syncing + * and computing ETH balances for all accounts + */ +class ComputedbalancesController { + /** + * Creates a new controller instance + * + * @param {ComputedBalancesOptions} [opts] Controller configuration parameters + */ constructor (opts = {}) { const { accountTracker, txController, blockTracker } = opts this.accountTracker = accountTracker @@ -19,6 +35,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 +45,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 {{ accounts: Object }} store Account tracking state + */ syncAllAccountsFromStore (store) { const upstream = Object.keys(store.accounts) const balances = Object.keys(this.balances) @@ -50,6 +80,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 +94,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, diff --git a/app/scripts/controllers/token-rates.js b/app/scripts/controllers/token-rates.js index 22e3e8154..28409ea10 100644 --- a/app/scripts/controllers/token-rates.js +++ b/app/scripts/controllers/token-rates.js @@ -46,7 +46,7 @@ class TokenRatesController { } /** - * @type {Number} - Interval used to poll for exchange rates + * @type {Number} */ set interval (interval) { this._handle && clearInterval(this._handle) @@ -55,7 +55,7 @@ class TokenRatesController { } /** - * @type {Object} - Preferences controller instance + * @type {Object} */ set preferences (preferences) { this._preferences && this._preferences.unsubscribe() @@ -66,7 +66,7 @@ class TokenRatesController { } /** - * @type {Array} - Array of token objects with contract addresses + * @type {Array} */ set tokens (tokens) { this._tokens = tokens |