Skip to content

Commit

Permalink
support both eth_chainId and net_version
Browse files Browse the repository at this point in the history
get the real chainId using eth_chainId and use net_version as a fallback
  • Loading branch information
hackmod committed Oct 19, 2018
1 parent ea21494 commit 2f6530a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/scripts/controllers/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ module.exports = class NetworkController extends EventEmitter {
return log.warn('NetworkController - lookupNetwork aborted due to missing provider')
}
const ethQuery = new EthQuery(this._provider)
ethQuery.sendAsync({ method: 'net_version' }, (err, network) => {
if (err) return this.setNetworkState('loading')
log.info('web3.getNetwork returned ' + network)
this.setNetworkState(network)
ethQuery.sendAsync({ method: 'eth_chainId' }, (err, chainId) => {
if (err) {
ethQuery.sendAsync({ method: 'net_version' }, (err, network) => {
if (err) return this.setNetworkState('loading')
log.info('web3.getNetwork returned net_version = ' + network)
this.setNetworkState(network)
})
return
}
log.info('web3.getNetwork returned chainId = ' + parseInt(chainId))
this.setNetworkState(parseInt(chainId))
})
}

Expand Down

0 comments on commit 2f6530a

Please sign in to comment.