network controller - move _setProvider to bottom

feature/default_network_editable
kumavis 7 years ago
parent f2d9b75e94
commit 06b5dd2096
  1. 36
      app/scripts/controllers/network.js

@ -41,24 +41,6 @@ module.exports = class NetworkController extends EventEmitter {
this.emit('networkDidChange') this.emit('networkDidChange')
} }
_setProvider (provider) {
// collect old block tracker events
const oldProvider = this._provider
let blockTrackerHandlers
if (oldProvider) {
// capture old block handlers
blockTrackerHandlers = oldProvider._blockTracker.proxyEventHandlers
// tear down
oldProvider.removeAllListeners()
oldProvider.stop()
}
// override block tracler
provider._blockTracker = createEventEmitterProxy(provider._blockTracker, blockTrackerHandlers)
// set as new provider
this._provider = provider
this._proxy.setTarget(provider)
}
verifyNetwork () { verifyNetwork () {
// Check network when restoring connectivity: // Check network when restoring connectivity:
if (this.isNetworkLoading()) this.lookupNetwork() if (this.isNetworkLoading()) this.lookupNetwork()
@ -112,6 +94,24 @@ module.exports = class NetworkController extends EventEmitter {
return provider && provider.rpcTarget ? provider.rpcTarget : DEFAULT_RPC return provider && provider.rpcTarget ? provider.rpcTarget : DEFAULT_RPC
} }
_setProvider (provider) {
// collect old block tracker events
const oldProvider = this._provider
let blockTrackerHandlers
if (oldProvider) {
// capture old block handlers
blockTrackerHandlers = oldProvider._blockTracker.proxyEventHandlers
// tear down
oldProvider.removeAllListeners()
oldProvider.stop()
}
// override block tracler
provider._blockTracker = createEventEmitterProxy(provider._blockTracker, blockTrackerHandlers)
// set as new provider
this._provider = provider
this._proxy.setTarget(provider)
}
_logBlock (block) { _logBlock (block) {
log.info(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`) log.info(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`)
this.verifyNetwork() this.verifyNetwork()

Loading…
Cancel
Save