diff --git a/app/scripts/background.js b/app/scripts/background.js index 02497d487..db2d9e8bb 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -133,7 +133,6 @@ setupMetamaskMeshMetrics() * @property {number} unapprovedTypedMsgCount - The number of messages in unapprovedTypedMsgs. * @property {string[]} keyringTypes - An array of unique keyring identifying strings, representing available strategies for creating accounts. * @property {Keyring[]} keyrings - An array of keyring descriptions, summarizing the accounts that are available for use, and what keyrings they belong to. - * @property {Object} computedBalances - Maps accounts to their balances, accounting for balance changes from pending transactions. * @property {string} currentAccountTab - A view identifying string for displaying the current displayed view, allows user to have a preferred tab in the old UI (between tokens and history). * @property {string} selectedAddress - A lower case hex string of the currently selected address. * @property {string} currentCurrency - A string identifying the user's preferred display currency, for use in showing conversion rates. diff --git a/app/scripts/controllers/computed-balances.js b/app/scripts/controllers/computed-balances.js deleted file mode 100644 index caa061df4..000000000 --- a/app/scripts/controllers/computed-balances.js +++ /dev/null @@ -1,120 +0,0 @@ -const ObservableStore = require('obs-store') -const extend = require('xtend') -const BalanceController = require('./balance') - -/** - * @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 - this.txController = txController - this.blockTracker = blockTracker - - const initState = extend({ - computedBalances: {}, - }, opts.initState) - this.store = new ObservableStore(initState) - this.balances = {} - - this._initBalanceUpdating() - } - - /** - * Updates balances associated with each internal address - */ - updateAllBalances () { - Object.keys(this.balances).forEach((balance) => { - const address = balance.address - this.balances[address].updateBalance() - }) - } - - /** - * 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) - .map(address => this.balances[address]) - - // Follow new addresses - for (const address in balances) { - this.trackAddressIfNotAlready(address) - } - - // Unfollow old ones - balances.forEach(({ address }) => { - if (!upstream.includes(address)) { - delete this.balances[address] - } - }) - } - - /** - * 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)) { - this.trackAddress(address) - } - } - - /** - * 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, - accountTracker: this.accountTracker, - txController: this.txController, - blockTracker: this.blockTracker, - }) - updater.store.subscribe((accountBalance) => { - const newState = this.store.getState() - newState.computedBalances[address] = accountBalance - this.store.updateState(newState) - }) - this.balances[address] = updater - updater.updateBalance() - } -} - -module.exports = ComputedbalancesController diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 1bf34a074..b9b44ea80 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -35,7 +35,6 @@ const MessageManager = require('./lib/message-manager') const PersonalMessageManager = require('./lib/personal-message-manager') const TypedMessageManager = require('./lib/typed-message-manager') const TransactionController = require('./controllers/transactions') -const BalancesController = require('./controllers/computed-balances') const TokenRatesController = require('./controllers/token-rates') const DetectTokensController = require('./controllers/detect-tokens') const ProviderApprovalController = require('./controllers/provider-approval') @@ -235,17 +234,9 @@ module.exports = class MetamaskController extends EventEmitter { } }) - // computed balances (accounting for pending transactions) - this.balancesController = new BalancesController({ - accountTracker: this.accountTracker, - txController: this.txController, - blockTracker: this.blockTracker, - }) this.networkController.on('networkDidChange', () => { - this.balancesController.updateAllBalances() this.setCurrentCurrency(this.currencyRateController.state.currentCurrency, function () {}) }) - this.balancesController.updateAllBalances() this.shapeshiftController = new ShapeShiftController(undefined, initState.ShapeShiftController) @@ -288,7 +279,6 @@ module.exports = class MetamaskController extends EventEmitter { NetworkController: this.networkController.store, AccountTracker: this.accountTracker.store, TxController: this.txController.memStore, - BalancesController: this.balancesController.store, CachedBalancesController: this.cachedBalancesController.store, TokenRatesController: this.tokenRatesController.store, MessageManager: this.messageManager.memStore, @@ -724,7 +714,6 @@ module.exports = class MetamaskController extends EventEmitter { } await this.preferencesController.syncAddresses(accounts) - await this.balancesController.updateAllBalances() await this.txController.pendingTxTracker.updatePendingTxs() return this.keyringController.fullUpdate() } diff --git a/development/states/first-time.json b/development/states/first-time.json index c6c4899d8..4a77bfbe5 100644 --- a/development/states/first-time.json +++ b/development/states/first-time.json @@ -4,7 +4,6 @@ "isUnlocked": false, "rpcTarget": "https://rawtestrpc.metamask.io/", "identities": {}, - "computedBalances": {}, "frequentRpcList": [], "unapprovedTxs": {}, "featureFlags": {"betaUI": false}, @@ -60,7 +59,6 @@ } }, "identities": {}, - "computedBalances": {}, "confirmTransaction": { "txData": {}, "tokenData": {}, diff --git a/development/states/navigate-txs.json b/development/states/navigate-txs.json index 4e47f8bca..39d24c1ea 100644 --- a/development/states/navigate-txs.json +++ b/development/states/navigate-txs.json @@ -170,7 +170,6 @@ }, "currentBlockGasLimit": "0x731e25", "selectedAddressTxList": [], - "computedBalances": {}, "unapprovedMsgs": {}, "unapprovedMsgCount": 0, "unapprovedPersonalMsgs": {}, diff --git a/development/states/pending-tx.json b/development/states/pending-tx.json index 82406a59d..f97bf3d43 100644 --- a/development/states/pending-tx.json +++ b/development/states/pending-tx.json @@ -687,7 +687,6 @@ ] } ], - "computedBalances": {}, "currentAccountTab": "history", "tokens": [ { diff --git a/test/data/2-state.json b/test/data/2-state.json index fe1d15cc1..9d6dc9af5 100644 --- a/test/data/2-state.json +++ b/test/data/2-state.json @@ -14,7 +14,6 @@ "currentBlockGasLimit": "", "unapprovedTxs": {}, "selectedAddressTxList": [], - "computedBalances": {}, "unapprovedMsgs": {}, "unapprovedMsgCount": 0, "unapprovedPersonalMsgs": {}, diff --git a/ui/app/pages/confirm-transaction/conf-tx.js b/ui/app/pages/confirm-transaction/conf-tx.js index d66cb699d..4f3868bc8 100644 --- a/ui/app/pages/confirm-transaction/conf-tx.js +++ b/ui/app/pages/confirm-transaction/conf-tx.js @@ -38,7 +38,6 @@ function mapStateToProps (state) { provider: state.metamask.provider, currentCurrency: state.metamask.currentCurrency, blockGasLimit: state.metamask.currentBlockGasLimit, - computedBalances: state.metamask.computedBalances, unapprovedMsgCount, unapprovedPersonalMsgCount, unapprovedTypedMessagesCount,