diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-09-27 05:09:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-27 05:09:17 +0800 |
commit | ff5e8746bee0d7461df02e7f2186ff7c90bfcb50 (patch) | |
tree | b78ee58bb8c79ca27aa7be7490d3502ce9583b3b /app/scripts/controllers | |
parent | 87fc44c45a5bb511fe60b2c3fe7e7c78f5f6584f (diff) | |
parent | 9d1cb0f76dce203299200940f21e868f6a5efef3 (diff) | |
download | tangerine-wallet-browser-ff5e8746bee0d7461df02e7f2186ff7c90bfcb50.tar tangerine-wallet-browser-ff5e8746bee0d7461df02e7f2186ff7c90bfcb50.tar.gz tangerine-wallet-browser-ff5e8746bee0d7461df02e7f2186ff7c90bfcb50.tar.bz2 tangerine-wallet-browser-ff5e8746bee0d7461df02e7f2186ff7c90bfcb50.tar.lz tangerine-wallet-browser-ff5e8746bee0d7461df02e7f2186ff7c90bfcb50.tar.xz tangerine-wallet-browser-ff5e8746bee0d7461df02e7f2186ff7c90bfcb50.tar.zst tangerine-wallet-browser-ff5e8746bee0d7461df02e7f2186ff7c90bfcb50.zip |
Merge pull request #2180 from MetaMask/proxy-blockTracker
Wrap block tracker in events proxy
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r-- | app/scripts/controllers/network.js | 27 | ||||
-rw-r--r-- | app/scripts/controllers/transactions.js | 2 |
2 files changed, 8 insertions, 21 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) - } } diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index fb3be6073..4e52a3c14 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -70,7 +70,7 @@ module.exports = class TransactionController extends EventEmitter { this.pendingTxTracker.on('txFailed', this.setTxStatusFailed.bind(this)) this.pendingTxTracker.on('txConfirmed', this.setTxStatusConfirmed.bind(this)) - this.blockTracker.on('rawBlock', this.pendingTxTracker.checkForTxInBlock.bind(this.pendingTxTracker)) + this.blockTracker.on('block', this.pendingTxTracker.checkForTxInBlock.bind(this.pendingTxTracker)) // this is a little messy but until ethstore has been either // removed or redone this is to guard against the race condition // where ethStore hasent been populated by the results yet |