1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00

network - convert localhost from custom rpc to network type

This commit is contained in:
kumavis 2017-09-29 16:35:58 -07:00
parent b88d11f86e
commit d6ea2fa425
5 changed files with 12 additions and 23 deletions

View File

@ -2,11 +2,13 @@ const MAINET_RPC_URL = 'https://mainnet.infura.io/metamask'
const ROPSTEN_RPC_URL = 'https://ropsten.infura.io/metamask' const ROPSTEN_RPC_URL = 'https://ropsten.infura.io/metamask'
const KOVAN_RPC_URL = 'https://kovan.infura.io/metamask' const KOVAN_RPC_URL = 'https://kovan.infura.io/metamask'
const RINKEBY_RPC_URL = 'https://rinkeby.infura.io/metamask' const RINKEBY_RPC_URL = 'https://rinkeby.infura.io/metamask'
const LOCALHOST_RPC_URL = 'http://localhost:8545'
global.METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' global.METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
module.exports = { module.exports = {
network: { network: {
localhost: LOCALHOST_RPC_URL,
mainnet: MAINET_RPC_URL, mainnet: MAINET_RPC_URL,
ropsten: ROPSTEN_RPC_URL, ropsten: ROPSTEN_RPC_URL,
kovan: KOVAN_RPC_URL, kovan: KOVAN_RPC_URL,

View File

@ -10,6 +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)

View File

@ -336,7 +336,6 @@ module.exports = class MetamaskController extends EventEmitter {
// network management // network management
setProviderType: nodeify(networkController.setProviderType, networkController), setProviderType: nodeify(networkController.setProviderType, networkController),
setDefaultRpc: nodeify(this.setDefaultRpc, this),
setCustomRpc: nodeify(this.setCustomRpc, this), setCustomRpc: nodeify(this.setCustomRpc, this),
// PreferencesController // PreferencesController
@ -696,12 +695,6 @@ module.exports = class MetamaskController extends EventEmitter {
// network // network
async setDefaultRpc () {
const localhost = 'http://localhost:8545'
this.networkController.setRpcTarget(localhost)
return localhost
}
async setCustomRpc (rpcTarget, rpcList) { async setCustomRpc (rpcTarget, rpcList) {
this.networkController.setRpcTarget(rpcTarget) this.networkController.setRpcTarget(rpcTarget)
await this.preferencesController.updateFrequentRpcList(rpcTarget) await this.preferencesController.updateFrequentRpcList(rpcTarget)

View File

@ -126,7 +126,6 @@ var actions = {
showAddTokenPage, showAddTokenPage,
addToken, addToken,
setRpcTarget: setRpcTarget, setRpcTarget: setRpcTarget,
setDefaultRpcTarget: setDefaultRpcTarget,
setProviderType: setProviderType, setProviderType: setProviderType,
// loading overlay // loading overlay
SHOW_LOADING: 'SHOW_LOADING_INDICATION', SHOW_LOADING: 'SHOW_LOADING_INDICATION',
@ -706,16 +705,19 @@ function markAccountsFound () {
// config // config
// //
// default rpc target refers to localhost:8545 in this instance. function setProviderType (type) {
function setDefaultRpcTarget () {
log.debug(`background.setDefaultRpcTarget`)
return (dispatch) => { return (dispatch) => {
background.setDefaultRpc((err, result) => { log.debug(`background.setProviderType`)
background.setProviderType(type, (err, result) => {
if (err) { if (err) {
log.error(err) log.error(err)
return dispatch(self.displayWarning('Had a problem changing networks.')) return dispatch(self.displayWarning('Had a problem changing networks!'))
} }
}) })
return {
type: actions.SET_PROVIDER_TYPE,
value: type,
}
} }
} }
@ -744,15 +746,6 @@ function addToAddressBook (recipient, nickname) {
} }
} }
function setProviderType (type) {
log.debug(`background.setProviderType`)
background.setProviderType(type)
return {
type: actions.SET_PROVIDER_TYPE,
value: type,
}
}
function useEtherscanProvider () { function useEtherscanProvider () {
log.debug(`background.useEtherscanProvider`) log.debug(`background.useEtherscanProvider`)
background.useEtherscanProvider() background.useEtherscanProvider()

View File

@ -319,7 +319,7 @@ App.prototype.renderNetworkDropdown = function () {
{ {
key: 'default', key: 'default',
closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }), closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }),
onClick: () => props.dispatch(actions.setDefaultRpcTarget()), onClick: () => props.dispatch(actions.setProviderType('localhost')),
style: { style: {
fontSize: '18px', fontSize: '18px',
}, },