aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-09-23 04:59:25 +0800
committerDan Finlay <dan@danfinlay.com>2017-09-23 04:59:25 +0800
commit11c8c07bfc6677e347873f02ae8c401f8d6c4dcf (patch)
treef94da3caa86d7fd7de6275d25cb9c161175208e3 /app/scripts/metamask-controller.js
parent977405fc7d89256a911e73b83a6678235fa1cfb8 (diff)
downloadtangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar
tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.gz
tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.bz2
tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.lz
tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.xz
tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.zst
tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.zip
Refactor eth-store into account-tracker
EthStore was only being used for tracking account balances and nonces now, so I removed its block-tracking duties, renamed it account-tracker, and removed it as a dependency from `KeyringController`, so that KRC can go live on without a hard dep on it.
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js26
1 files changed, 16 insertions, 10 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 02c06ead2..b1cfe1a2d 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -4,7 +4,7 @@ const promiseToCallback = require('promise-to-callback')
const pipe = require('pump')
const Dnode = require('dnode')
const ObservableStore = require('obs-store')
-const EthStore = require('./lib/eth-store')
+const AccountTracker = require('./lib/account-tracker')
const EthQuery = require('eth-query')
const streamIntoProvider = require('web3-stream-provider/handler')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
@@ -81,19 +81,25 @@ module.exports = class MetamaskController extends EventEmitter {
// eth data query tools
this.ethQuery = new EthQuery(this.provider)
- this.ethStore = new EthStore({
- provider: this.provider,
- blockTracker: this.provider,
- })
// key mgmt
this.keyringController = new KeyringController({
initState: initState.KeyringController,
- ethStore: this.ethStore,
+ accountTracker: this.accountTracker,
getNetwork: this.networkController.getNetworkState.bind(this.networkController),
})
+
+ // account tracker watches balances, nonces, and any code at their address.
+ this.accountTracker = new AccountTracker({
+ provider: this.provider,
+ blockTracker: this.provider,
+ })
this.keyringController.on('newAccount', (address) => {
this.preferencesController.setSelectedAddress(address)
+ this.accountTracker.addAccount(address)
+ })
+ this.keyringController.on('removedAccount', (address) => {
+ this.accountTracker.removeAccount(address)
})
// address book controller
@@ -112,13 +118,13 @@ module.exports = class MetamaskController extends EventEmitter {
provider: this.provider,
blockTracker: this.provider,
ethQuery: this.ethQuery,
- ethStore: this.ethStore,
+ accountTracker: this.accountTracker,
})
this.txController.on('newUnaprovedTx', opts.showUnapprovedTx.bind(opts))
// computed balances (accounting for pending transactions)
this.balancesController = new BalancesController({
- ethStore: this.ethStore,
+ accountTracker: this.accountTracker,
txController: this.txController,
})
this.networkController.on('networkDidChange', () => {
@@ -177,7 +183,7 @@ module.exports = class MetamaskController extends EventEmitter {
// manual mem state subscriptions
this.networkController.store.subscribe(this.sendUpdate.bind(this))
- this.ethStore.subscribe(this.sendUpdate.bind(this))
+ this.accountTracker.subscribe(this.sendUpdate.bind(this))
this.txController.memStore.subscribe(this.sendUpdate.bind(this))
this.balancesController.store.subscribe(this.sendUpdate.bind(this))
this.messageManager.memStore.subscribe(this.sendUpdate.bind(this))
@@ -260,7 +266,7 @@ module.exports = class MetamaskController extends EventEmitter {
isInitialized,
},
this.networkController.store.getState(),
- this.ethStore.getState(),
+ this.accountTracker.getState(),
this.txController.memStore.getState(),
this.messageManager.memStore.getState(),
this.personalMessageManager.memStore.getState(),