Merge pull request #5552 from EthersocialNetwork/eth_chainid

network - check eth_chainId and fallback to net_version
feature/default_network_editable
kumavis 6 years ago committed by GitHub
commit 18e530221b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      app/scripts/controllers/network/network.js

@ -107,10 +107,20 @@ module.exports = class NetworkController extends EventEmitter {
} }
var { type } = this.providerStore.getState() var { type } = this.providerStore.getState()
const ethQuery = new EthQuery(this._provider) const ethQuery = new EthQuery(this._provider)
ethQuery.sendAsync({ method: 'net_version' }, (err, network) => { // first attempt to perform lookup via eth_chainId
if (err) return this.setNetworkState('loading') ethQuery.sendAsync({ method: 'eth_chainId' }, (err, chainIdHex) => {
log.info('web3.getNetwork returned ' + network) if (err) {
this.setNetworkState(network, type) // if eth_chainId is not supported, fallback to net_verion
ethQuery.sendAsync({ method: 'net_version' }, (err, network) => {
if (err) return this.setNetworkState('loading')
log.info(`net_version returned ${network}`)
this.setNetworkState(network, type)
})
return
}
const chainId = Number.parseInt(chainIdHex, 16)
log.info(`net_version returned ${chainId}`)
this.setNetworkState(chainId, type)
}) })
} }

Loading…
Cancel
Save