controllers - network - move default config out of first-time-state
This commit is contained in:
parent
53caa49666
commit
fec4c50657
|
@ -19,14 +19,27 @@ const {
|
||||||
const LOCALHOST_RPC_URL = 'http://localhost:8545'
|
const LOCALHOST_RPC_URL = 'http://localhost:8545'
|
||||||
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET]
|
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET]
|
||||||
|
|
||||||
|
const env = process.env.METAMASK_ENV
|
||||||
|
const METAMASK_DEBUG = process.env.METAMASK_DEBUG
|
||||||
|
const testMode = (METAMASK_DEBUG || env === 'test')
|
||||||
|
|
||||||
|
const defaultProviderConfig = {
|
||||||
|
type: testMode ? RINKEBY : MAINNET,
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = class NetworkController extends EventEmitter {
|
module.exports = class NetworkController extends EventEmitter {
|
||||||
|
|
||||||
constructor (config) {
|
constructor (opts = {}) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
// parse options
|
||||||
|
const providerConfig = opts.provider || defaultProviderConfig
|
||||||
|
console.log('providerStore:', providerConfig)
|
||||||
|
// create stores
|
||||||
|
this.providerStore = new ObservableStore(providerConfig)
|
||||||
this.networkStore = new ObservableStore('loading')
|
this.networkStore = new ObservableStore('loading')
|
||||||
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 })
|
||||||
|
// create event emitter proxy
|
||||||
this._proxy = createEventEmitterProxy()
|
this._proxy = createEventEmitterProxy()
|
||||||
|
|
||||||
this.on('networkDidChange', this.lookupNetwork)
|
this.on('networkDidChange', this.lookupNetwork)
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
// test and development environment variables
|
|
||||||
const env = process.env.METAMASK_ENV
|
|
||||||
const METAMASK_DEBUG = process.env.METAMASK_DEBUG
|
|
||||||
const { DEFAULT_NETWORK, MAINNET } = require('./controllers/network/enums')
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} FirstTimeState
|
* @typedef {Object} FirstTimeState
|
||||||
|
@ -14,11 +10,6 @@ const { DEFAULT_NETWORK, MAINNET } = require('./controllers/network/enums')
|
||||||
*/
|
*/
|
||||||
const initialState = {
|
const initialState = {
|
||||||
config: {},
|
config: {},
|
||||||
NetworkController: {
|
|
||||||
provider: {
|
|
||||||
type: (METAMASK_DEBUG || env === 'test') ? DEFAULT_NETWORK : MAINNET,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = initialState
|
module.exports = initialState
|
||||||
|
|
Loading…
Reference in New Issue