-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Conversation
There was a problem hiding this 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
app/scripts/controllers/network.js
Outdated
log.info('web3.getNetwork returned ' + network) | ||
this.setNetworkState(network) | ||
cb(err, network) |
There was a problem hiding this comment.
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
app/scripts/controllers/network.js
Outdated
if (err) { | ||
this.setNetworkState('loading') | ||
console.error(err) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cb
not called
app/scripts/controllers/network.js
Outdated
@@ -58,15 +58,20 @@ module.exports = class NetworkController extends EventEmitter { | |||
return this.getNetworkState() === 'loading' | |||
} | |||
|
|||
lookupNetwork () { | |||
lookupNetwork (cb = () => {}) { |
There was a problem hiding this comment.
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
app/scripts/platforms/extension.js
Outdated
return navigator.onLine | ||
} | ||
|
||
onLine (cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not clearly named
app/scripts/metamask-controller.js
Outdated
// guard against premature firring of the event listener | ||
if (this.provider) { | ||
// start the provider up | ||
this.provider.stop() |
There was a problem hiding this comment.
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?
app/scripts/metamask-controller.js
Outdated
// look up the network | ||
this.networkController.lookupNetwork(() => { | ||
this.emit('update', this.getState()) | ||
}) |
There was a problem hiding this comment.
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
Related to #2548 |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
I can readily reproduce an instance of #2636 on this branch with these steps:
Results: The network spinner stays on. The block tracker's 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 |
There was a problem hiding this comment.
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
@frankiebee said we can retire this one |
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