1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

Merge pull request #5892 from MetaMask/fix-net-version-race-condition

Fix race condition in network controller lookup() method.
This commit is contained in:
Thomas Huang 2018-12-07 14:49:00 -08:00 committed by GitHub
commit 575fb607c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,12 +105,18 @@ module.exports = class NetworkController extends EventEmitter {
if (!this._provider) {
return log.warn('NetworkController - lookupNetwork aborted due to missing provider')
}
var { type } = this.providerStore.getState()
const { type } = this.providerStore.getState()
const ethQuery = new EthQuery(this._provider)
const initialNetwork = this.getNetworkState()
ethQuery.sendAsync({ method: 'net_version' }, (err, network) => {
if (err) return this.setNetworkState('loading')
log.info('web3.getNetwork returned ' + network)
this.setNetworkState(network, type)
const currentNetwork = this.getNetworkState()
if (initialNetwork === currentNetwork) {
if (err) {
return this.setNetworkState('loading')
}
log.info('web3.getNetwork returned ' + network)
this.setNetworkState(network, type)
}
})
}