network-controller - use obj-proxy for providerProxy

feature/default_network_editable
kumavis 7 years ago
parent 7d50a56198
commit 0f8d7dacb1
  1. 7
      app/scripts/controllers/network.js
  2. 4
      package.json
  3. 25
      test/unit/network-contoller-test.js

@ -6,6 +6,7 @@ const extend = require('xtend')
const EthQuery = require('eth-query') const EthQuery = require('eth-query')
const createEthRpcClient = require('eth-rpc-client') const createEthRpcClient = require('eth-rpc-client')
const createEventEmitterProxy = require('../lib/events-proxy.js') const createEventEmitterProxy = require('../lib/events-proxy.js')
const createObjectProxy = require('../lib/obj-proxy.js')
const RPC_ADDRESS_LIST = require('../config.js').network const RPC_ADDRESS_LIST = require('../config.js').network
const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby'] const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby']
@ -17,7 +18,7 @@ module.exports = class NetworkController extends EventEmitter {
this.networkStore = new ObservableStore('loading') this.networkStore = new ObservableStore('loading')
this.providerStore = new ObservableStore(config.provider) this.providerStore = new ObservableStore(config.provider)
this.store = new ComposedStore({ provider: this.providerStore, network: this.networkStore }) this.store = new ComposedStore({ provider: this.providerStore, network: this.networkStore })
this.providerProxy = createEventEmitterProxy() this.providerProxy = createObjectProxy()
this.blockTrackerProxy = createEventEmitterProxy() this.blockTrackerProxy = createEventEmitterProxy()
this.on('networkDidChange', this.lookupNetwork) this.on('networkDidChange', this.lookupNetwork)
@ -27,8 +28,8 @@ module.exports = class NetworkController extends EventEmitter {
this._baseProviderParams = _providerParams this._baseProviderParams = _providerParams
const rpcUrl = this.getCurrentRpcAddress() const rpcUrl = this.getCurrentRpcAddress()
this._configureStandardClient({ rpcUrl }) this._configureStandardClient({ rpcUrl })
this.providerProxy.on('block', this._logBlock.bind(this)) this.blockTrackerProxy.on('block', this._logBlock.bind(this))
this.providerProxy.on('error', this.verifyNetwork.bind(this)) this.blockTrackerProxy.on('error', this.verifyNetwork.bind(this))
this.ethQuery = new EthQuery(this.providerProxy) this.ethQuery = new EthQuery(this.providerProxy)
this.lookupNetwork() this.lookupNetwork()
} }

@ -71,11 +71,11 @@
"eth-contract-metadata": "^1.1.4", "eth-contract-metadata": "^1.1.4",
"eth-hd-keyring": "^1.2.1", "eth-hd-keyring": "^1.2.1",
"eth-json-rpc-filters": "^1.2.2", "eth-json-rpc-filters": "^1.2.2",
"eth-json-rpc-middleware": "^1.4.1", "eth-json-rpc-middleware": "^1.4.2",
"eth-keyring-controller": "^2.1.0", "eth-keyring-controller": "^2.1.0",
"eth-phishing-detect": "^1.1.4", "eth-phishing-detect": "^1.1.4",
"eth-query": "^2.1.2", "eth-query": "^2.1.2",
"eth-rpc-client": "^1.0.0", "eth-rpc-client": "^1.0.3",
"eth-sig-util": "^1.4.0", "eth-sig-util": "^1.4.0",
"eth-simple-keyring": "^1.1.1", "eth-simple-keyring": "^1.1.1",
"eth-token-tracker": "^1.1.4", "eth-token-tracker": "^1.1.4",

@ -14,15 +14,15 @@ describe('# Network Controller', function () {
}, },
}) })
networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor) networkController.initializeProvider(networkControllerProviderInit)
}) })
describe('network', function () { describe('network', function () {
describe('#provider', function () { describe('#provider', function () {
it('provider should be updatable without reassignment', function () { it('provider should be updatable without reassignment', function () {
networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor) networkController.initializeProvider(networkControllerProviderInit)
const proxy = networkController._proxy const providerProxy = networkController.providerProxy
proxy.setTarget({ test: true, on: () => {} }) providerProxy.setTarget({ test: true })
assert.ok(proxy.test) assert.ok(providerProxy.test)
}) })
}) })
describe('#getNetworkState', function () { describe('#getNetworkState', function () {
@ -66,19 +66,4 @@ describe('# Network Controller', function () {
}) })
}) })
function dummyProviderConstructor() {
return {
// provider
sendAsync: noop,
// block tracker
_blockTracker: {},
start: noop,
stop: noop,
on: noop,
addListener: noop,
once: noop,
removeAllListeners: noop,
}
}
function noop() {} function noop() {}
Loading…
Cancel
Save