mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
network - make network controller internal network switching explicit
This commit is contained in:
parent
a2b6d3ffc5
commit
1ad8a9a0ff
@ -10,7 +10,7 @@ const RPC_ADDRESS_LIST = require('../config.js').network
|
|||||||
const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby']
|
const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby']
|
||||||
|
|
||||||
module.exports = class NetworkController extends EventEmitter {
|
module.exports = class NetworkController extends EventEmitter {
|
||||||
|
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
super()
|
super()
|
||||||
config.provider.rpcTarget = this.getRpcAddressForType(config.provider.type, config.provider)
|
config.provider.rpcTarget = this.getRpcAddressForType(config.provider.type, config.provider)
|
||||||
@ -20,7 +20,6 @@ module.exports = class NetworkController extends EventEmitter {
|
|||||||
this._proxy = createEventEmitterProxy()
|
this._proxy = createEventEmitterProxy()
|
||||||
|
|
||||||
this.on('networkDidChange', this.lookupNetwork)
|
this.on('networkDidChange', this.lookupNetwork)
|
||||||
this.providerStore.subscribe((state) => this._switchNetwork({ rpcUrl: state.rpcTarget }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeProvider (_providerParams) {
|
initializeProvider (_providerParams) {
|
||||||
@ -64,6 +63,7 @@ module.exports = class NetworkController extends EventEmitter {
|
|||||||
type: 'rpc',
|
type: 'rpc',
|
||||||
rpcTarget: rpcUrl,
|
rpcTarget: rpcUrl,
|
||||||
})
|
})
|
||||||
|
this._switchNetwork({ rpcUrl })
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentRpcAddress () {
|
getCurrentRpcAddress () {
|
||||||
@ -79,6 +79,7 @@ module.exports = class NetworkController extends EventEmitter {
|
|||||||
const rpcTarget = this.getRpcAddressForType(type)
|
const rpcTarget = this.getRpcAddressForType(type)
|
||||||
assert(rpcTarget, `NetworkController - unknown rpc address for type "${type}"`)
|
assert(rpcTarget, `NetworkController - unknown rpc address for type "${type}"`)
|
||||||
this.providerStore.updateState({ type, rpcTarget })
|
this.providerStore.updateState({ type, rpcTarget })
|
||||||
|
this._switchNetwork({ rpcUrl: rpcTarget })
|
||||||
}
|
}
|
||||||
|
|
||||||
getProviderConfig () {
|
getProviderConfig () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user