mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
Remove ComputedbalancesController (#7057)
This commit is contained in:
parent
6dfc16f0fc
commit
ecbde20949
@ -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.
|
||||
|
@ -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
|
@ -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()
|
||||
}
|
||||
|
@ -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": {},
|
||||
|
@ -170,7 +170,6 @@
|
||||
},
|
||||
"currentBlockGasLimit": "0x731e25",
|
||||
"selectedAddressTxList": [],
|
||||
"computedBalances": {},
|
||||
"unapprovedMsgs": {},
|
||||
"unapprovedMsgCount": 0,
|
||||
"unapprovedPersonalMsgs": {},
|
||||
|
@ -687,7 +687,6 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"computedBalances": {},
|
||||
"currentAccountTab": "history",
|
||||
"tokens": [
|
||||
{
|
||||
|
@ -14,7 +14,6 @@
|
||||
"currentBlockGasLimit": "",
|
||||
"unapprovedTxs": {},
|
||||
"selectedAddressTxList": [],
|
||||
"computedBalances": {},
|
||||
"unapprovedMsgs": {},
|
||||
"unapprovedMsgCount": 0,
|
||||
"unapprovedPersonalMsgs": {},
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user