Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query network version when metamask is back on line #3004

Closed
wants to merge 7 commits into from
Closed

Conversation

frankiebee
Copy link
Contributor

partial fix for issue #2636 however their maybe some other things in that issue that i am not considering.

the issue this fixes is that if a provider was created when offline the network spinner goes for ever and a request never goes through for net_version, this should fix that.

their are subsequent issues that have been discovered in the pursuit of fixing this one:
MetaMask/eth-block-tracker#27
#3003

@frankiebee frankiebee added the DO-NOT-MERGE Pull requests that should not be merged label Jan 17, 2018
@frankiebee frankiebee removed the DO-NOT-MERGE Pull requests that should not be merged label Jan 17, 2018
Copy link
Member

@kumavis kumavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find, implementation needs some improvements

log.info('web3.getNetwork returned ' + network)
this.setNetworkState(network)
cb(err, network)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err is truthy, this part will not be reached

if (err) {
this.setNetworkState('loading')
console.error(err)
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cb not called

@@ -58,15 +58,20 @@ module.exports = class NetworkController extends EventEmitter {
return this.getNetworkState() === 'loading'
}

lookupNetwork () {
lookupNetwork (cb = () => {}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define noop up by the require statements

return navigator.onLine
}

onLine (cb) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clearly named

// guard against premature firring of the event listener
if (this.provider) {
// start the provider up
this.provider.stop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is referring to the blockTracker actually, correct?

// look up the network
this.networkController.lookupNetwork(() => {
this.emit('update', this.getState())
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not the correct way to emit updates for MetamaskController

@danfinlay
Copy link
Contributor

Related to #2548

@danfinlay danfinlay requested a review from tmashuang January 25, 2018 21:15
Copy link
Contributor

@danfinlay danfinlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should have a changelog.

Frankie isn't doing well, so I'm going to make my requested changes.

if (err) return this.setNetworkState('loading')
if (err) {
this.setNetworkState('loading')
console.error(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be log.error to use our loglevel utility.

@@ -61,6 +61,21 @@ module.exports = class MetamaskController extends EventEmitter {
// network store
this.networkController = new NetworkController(initState.NetworkController)

// setup onLine lister for restarting the provider
if (this.platform.addOnLineListener) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"online" is one word, I'd rather we didn't camel case it into two. Non blocking.

}

addOnLineListener (cb) {
window.addEventListener('online', cb)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah camel cased correctly here. Incorrect capitalization kinda driving me nuts, going to change it myself.

@danfinlay danfinlay dismissed kumavis’s stale review February 1, 2018 19:39

Requested changes were made.

@danfinlay
Copy link
Contributor

danfinlay commented Feb 1, 2018

I can readily reproduce an instance of #2636 on this branch with these steps:

  1. Select main network
  2. Ensure Ganache/local network is not running
  3. Switch to the local network which is not running
  4. Turn on the local network/ganache

Results: The network spinner stays on.

The block tracker's start method returns a promise that does not seem to get any retries.

Regression:

If a test network is successfully connected, and then disconnected, the network indicator is never shown. This seems to me like it breaks the basic functionality of the network connection spinner, and is arguably worse than the current behavior.

I wouldn't want to merge this until the spinner accurately reflects network status.

@@ -26,6 +26,14 @@ class ExtensionPlatform {
cb(e)
}
}

isOnline () {
return navigator.onLine
Copy link
Member

@kumavis kumavis Mar 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sadly, this is the web api's camelization

@kumavis
Copy link
Member

kumavis commented Mar 28, 2018

@frankiebee said we can retire this one

@kumavis kumavis closed this Mar 28, 2018
@kumavis kumavis deleted the i#2636 branch March 28, 2018 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants