1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Manually debugged refactor

This commit is contained in:
Dan Finlay 2016-06-24 16:46:18 -07:00
parent 122018a96a
commit d3e0e7fe45
2 changed files with 14 additions and 13 deletions

View File

@ -90,14 +90,15 @@ function setupControllerConnection (stream) {
var api = controller.getApi()
var dnode = Dnode(api)
stream.pipe(dnode).pipe(stream)
dnode.on('remote', () => {
dnode.on('remote', (remote) => {
// push updates to popup
controller.ethStore.on('update', controller.sendUpdate)
idStore.on('update', controller.sendUpdate)
controller.ethStore.on('update', controller.sendUpdate.bind(controller))
controller.remote = remote
idStore.on('update', controller.sendUpdate.bind(controller))
// teardown on disconnect
eos(stream, () => {
controller.ethStore.removeListener('update', controller.sendUpdate)
controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller))
})
})
}

View File

@ -7,18 +7,16 @@ const HostStore = require('./lib/remote-store.js').HostStore
const Web3 = require('web3')
const ConfigManager = require('./lib/config-manager')
module.exports = MetamaskController
class MetamaskController {
module.exports = class MetamaskController {
constructor (opts) {
this.configManager = new ConfigManager(opts)
this.provider = this.initializeProvider(opts)
this.ethStore = new EthStore(this.provider)
this.idStore = new IdentityStore({
configManager: this.configManager,
ethStore: this.ethStore,
})
this.provider = this.initializeProvider(opts)
this.ethStore = new EthStore(this.provider)
this.idStore.setStore(this.ethStore)
this.messageManager = messageManager
this.publicConfigStore = this.initPublicConfigStore()
}
@ -35,7 +33,7 @@ class MetamaskController {
const idStore = this.idStore
return {
getState: function (cb) { cb(null, this.getState()) },
getState: (cb) => { cb(null, this.getState()) },
setRpcTarget: this.setRpcTarget.bind(this),
setProviderType: this.setProviderType.bind(this),
useEtherscanProvider: this.useEtherscanProvider.bind(this),
@ -99,7 +97,9 @@ class MetamaskController {
}
sendUpdate () {
this.remote.sendUpdate(this.getState())
if (this.remote) {
this.remote.sendUpdate(this.getState())
}
}
initializeProvider (opts) {
@ -126,7 +126,7 @@ class MetamaskController {
idStore.web3 = web3
idStore.getNetwork()
provider.on('block', this.processBlock)
provider.on('block', this.processBlock.bind(this))
provider.on('error', idStore.getNetwork.bind(idStore))
return provider