aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers/network.js
diff options
context:
space:
mode:
authorDan Finlay <542863+danfinlay@users.noreply.github.com>2017-09-28 02:13:06 +0800
committerGitHub <noreply@github.com>2017-09-28 02:13:06 +0800
commit828dbd7e3fcbb670d3dce4aa31109a4495832caa (patch)
tree8177fb150ae254b838cabec028b3c5e08fbc951e /app/scripts/controllers/network.js
parentca0dff06f5d9283e57b452dcc7e85c31b248b8aa (diff)
parente72083f6e81f888f714125f7c050e777ea5c9bdd (diff)
downloadtangerine-wallet-browser-828dbd7e3fcbb670d3dce4aa31109a4495832caa.tar
tangerine-wallet-browser-828dbd7e3fcbb670d3dce4aa31109a4495832caa.tar.gz
tangerine-wallet-browser-828dbd7e3fcbb670d3dce4aa31109a4495832caa.tar.bz2
tangerine-wallet-browser-828dbd7e3fcbb670d3dce4aa31109a4495832caa.tar.lz
tangerine-wallet-browser-828dbd7e3fcbb670d3dce4aa31109a4495832caa.tar.xz
tangerine-wallet-browser-828dbd7e3fcbb670d3dce4aa31109a4495832caa.tar.zst
tangerine-wallet-browser-828dbd7e3fcbb670d3dce4aa31109a4495832caa.zip
Merge pull request #2155 from MetaMask/filter-fixes-moar
Various fixes you've been waiting for, how exciting!
Diffstat (limited to 'app/scripts/controllers/network.js')
-rw-r--r--app/scripts/controllers/network.js27
1 files changed, 7 insertions, 20 deletions
diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js
index 0a3e5e26b..dc9978043 100644
--- a/app/scripts/controllers/network.js
+++ b/app/scripts/controllers/network.js
@@ -4,6 +4,7 @@ const ObservableStore = require('obs-store')
const ComposedStore = require('obs-store/lib/composed')
const extend = require('xtend')
const EthQuery = require('eth-query')
+const createEventEmitterProxy = require('../lib/events-proxy.js')
const RPC_ADDRESS_LIST = require('../config.js').network
const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby']
@@ -31,16 +32,8 @@ module.exports = class NetworkController extends EventEmitter {
initializeProvider (opts, providerContructor = MetaMaskProvider) {
this.providerInit = opts
this._provider = providerContructor(opts)
- this._proxy = new Proxy(this._provider, {
- get: (obj, name) => {
- if (name === 'on') return this._on.bind(this)
- return this._provider[name]
- },
- set: (obj, name, value) => {
- this._provider[name] = value
- return value
- },
- })
+ this._proxy = createEventEmitterProxy(this._provider)
+ this.provider._blockTracker = createEventEmitterProxy(this._provider._blockTracker)
this.provider.on('block', this._logBlock.bind(this))
this.provider.on('error', this.verifyNetwork.bind(this))
this.ethQuery = new EthQuery(this.provider)
@@ -55,11 +48,11 @@ module.exports = class NetworkController extends EventEmitter {
this._provider.removeAllListeners()
this._provider.stop()
- this.provider = MetaMaskProvider(newInit)
+ this._provider = MetaMaskProvider(newInit)
// apply the listners created by other controllers
- Object.keys(this._providerListeners).forEach((key) => {
- this._providerListeners[key].forEach((handler) => this._provider.addListener(key, handler))
- })
+ const blockTrackerHandlers = this.provider._blockTracker.proxyEventHandlers
+ this.provider.setTarget(this._provider)
+ this.provider._blockTracker = createEventEmitterProxy(this._provider._blockTracker, blockTrackerHandlers)
this.emit('networkDidChange')
}
@@ -121,10 +114,4 @@ module.exports = class NetworkController extends EventEmitter {
log.info(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`)
this.verifyNetwork()
}
-
- _on (event, handler) {
- if (!this._providerListeners[event]) this._providerListeners[event] = []
- this._providerListeners[event].push(handler)
- this._provider.on(event, handler)
- }
}