1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

network-controller - use obj-proxy for providerProxy

This commit is contained in:
kumavis 2017-10-10 17:26:44 -07:00
parent 7d50a56198
commit 0f8d7dacb1
3 changed files with 11 additions and 25 deletions

View File

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

View File

@ -71,11 +71,11 @@
"eth-contract-metadata": "^1.1.4",
"eth-hd-keyring": "^1.2.1",
"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-phishing-detect": "^1.1.4",
"eth-query": "^2.1.2",
"eth-rpc-client": "^1.0.0",
"eth-rpc-client": "^1.0.3",
"eth-sig-util": "^1.4.0",
"eth-simple-keyring": "^1.1.1",
"eth-token-tracker": "^1.1.4",

View File

@ -14,15 +14,15 @@ describe('# Network Controller', function () {
},
})
networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor)
networkController.initializeProvider(networkControllerProviderInit)
})
describe('network', function () {
describe('#provider', function () {
it('provider should be updatable without reassignment', function () {
networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor)
const proxy = networkController._proxy
proxy.setTarget({ test: true, on: () => {} })
assert.ok(proxy.test)
networkController.initializeProvider(networkControllerProviderInit)
const providerProxy = networkController.providerProxy
providerProxy.setTarget({ test: true })
assert.ok(providerProxy.test)
})
})
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() {}