aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-06-25 07:46:18 +0800
committerDan Finlay <dan@danfinlay.com>2016-06-25 07:46:18 +0800
commitd3e0e7fe45a1dc2159b26155b974ced16548ea44 (patch)
tree7eacaee6ef26915ea6c00a12f784014a10749059 /app
parent122018a96a1b2b6d9b7eefe150ff76a9de69bdd7 (diff)
downloadtangerine-wallet-browser-d3e0e7fe45a1dc2159b26155b974ced16548ea44.tar
tangerine-wallet-browser-d3e0e7fe45a1dc2159b26155b974ced16548ea44.tar.gz
tangerine-wallet-browser-d3e0e7fe45a1dc2159b26155b974ced16548ea44.tar.bz2
tangerine-wallet-browser-d3e0e7fe45a1dc2159b26155b974ced16548ea44.tar.lz
tangerine-wallet-browser-d3e0e7fe45a1dc2159b26155b974ced16548ea44.tar.xz
tangerine-wallet-browser-d3e0e7fe45a1dc2159b26155b974ced16548ea44.tar.zst
tangerine-wallet-browser-d3e0e7fe45a1dc2159b26155b974ced16548ea44.zip
Manually debugged refactor
Diffstat (limited to 'app')
-rw-r--r--app/scripts/background.js9
-rw-r--r--app/scripts/metamask-controller.js18
2 files changed, 14 insertions, 13 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 09cdffecd..97e3269ba 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -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))
})
})
}
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 262c20b96..d09b4c5f9 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -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