Jl/version v12 10.4/hotfix network version inpage provider #30109
+2,418
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Previously the inpage provider would withhold events for chainChanged events (and property value updates, i.e. window.ethereum.chainId and .networkVersion) when the dapp's network was changed to an rpc endpoint that was unresponsive or did not support net_version. The dapp would instead receive a disconnect event.
Now the inpage provider always emits chainChanged and networkChanged events (and exposes the correct values on window.ethereum.chainId and .networkVersion) when the selected network for the dapp has changed regardless of if the network being changed to is responsive or if it supports net_version requests. It does this by having the wallet send a loading for networkVersion when it cannot be resolved (same behavior as before) AND a new isConnected property in the metamask_getProviderState request and metamask_chainChanged events (these are different from the events emittted by window.ethereum). isConnected is derived from whether the NetworkController.state.networkMetadata[].status value is the Available constant.
Related issues
See: #29936
Providers patch from commit (d919ab6b): MetaMask/providers#404
Manual testing steps
chainChanged
andnetworkChanged
eventschainChanged
andnetworkChanged
eventschainChanged
emits with the correct chainId, butnetworkChanged
emits with a null value, AND there is adisconnect
event emittedchainChanged
andnetworkChanged
events, AND there is aconnect
event emitted with the new chainIdnet_version
implemented. Se that the correct values are emitted for thechainChanged
, thatnetworkChanged
emits null, and that there is nodisconnect
event emittedScreenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist