Skip to content

Replace network/isCustomNetwork with networkStatus#1073

Closed
cryptodev-2s wants to merge 2 commits intomainfrom
replace-network-and-iscustomnetwork
Closed

Replace network/isCustomNetwork with networkStatus#1073
cryptodev-2s wants to merge 2 commits intomainfrom
replace-network-and-iscustomnetwork

Conversation

@cryptodev-2s
Copy link
Contributor

@cryptodev-2s cryptodev-2s commented Jan 23, 2023

The network controller contains two related state properties: network
and isCustomNetwork.

The first property is strange: it can either be a number, which
represents the version of the network as obtained via net_version, or
"loading", which is a sort of null state that either means we don't have
a network to connect to, or we do but it's not accessible. In any case,
the net_version RPC method, much less the idea of a network version,
is no longer standard, so we don't need to store it.

The second property is unnecessary, as we can already obtain whether a
network is "custom" (i.e. not one of the ones we know about by default)
by looking at the type within the provider config object.

Therefore, we can remove these state properties and replace them with a
simple property that merely tracks whether we have an accessible network
or not.

Fixes #1020.

@cryptodev-2s cryptodev-2s requested a review from a team as a code owner January 23, 2023 16:11
@Gudahtt

This comment was marked as resolved.

The network controller contains two related state properties: `network`
and `isCustomNetwork`.

The first property is strange: it can either be a number, which
represents the version of the network as obtained via `net_version`, or
"loading", which is a sort of null state that either means we don't have
a network to connect to, or we do but it's not accessible. In any case,
the `net_version` RPC method, much less the idea of a network version,
is no longer standard, so we don't need to store it.

The second property is unnecessary, as we can already obtain whether a
network is "custom" (i.e. not one of the ones we know about by default)
by looking at the `type` within the provider config object.

Therefore, we can remove these state properties and replace them with a
simple property that merely tracks whether we have an accessible network
or not.

Co-authored-by: Salah <salah-eddine.saakoun@consensys.net>
@mcmire mcmire force-pushed the replace-network-and-iscustomnetwork branch from 2db91e4 to f98e942 Compare February 16, 2023 05:28
@mcmire mcmire changed the title feat: replace network and isCustomNetwork with currentNetworkType Replace network/isCustomNetwork with networkStatus Feb 16, 2023
Comment on lines +53 to +57
* created for the currently selected network and the network is provably
* accessible.
* @property loading - Represents the state in which a provider object does not
* exist for the currently selected network, or it does exist but the network is
* provably inaccessible.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Maybe better to use softer language here since we only check periodically, and since the way we check today is a bit questionable and might not be a guarantee that the network is accessible (e.g. if a network doesn't implement net_version, or uses a cache for static methods like this, it might not reflect whether the network is accessible or not).

Suggested change
* created for the currently selected network and the network is provably
* accessible.
* @property loading - Represents the state in which a provider object does not
* exist for the currently selected network, or it does exist but the network is
* provably inaccessible.
* created for the currently selected network and the network is seems
* accessible.
* @property loading - Represents the state in which a provider object does not
* exist for the currently selected network, or it does exist but the network is
* seems inaccessible.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

Looks great! There seems to be a conflict to resolve though.

Also, could we compile a list of all of the breaking changes? Lots on the transaction controller here too.

@mcmire
Copy link
Contributor

mcmire commented Mar 6, 2023

I need to revisit this. I'll try to focus on this after my current task on the extension side.

@mcmire mcmire marked this pull request as draft March 9, 2023 23:47
@mcmire
Copy link
Contributor

mcmire commented Mar 9, 2023

Placing this back in draft until MetaMask/metamask-extension#17556 is merged.

@Gudahtt
Copy link
Member

Gudahtt commented Apr 25, 2023

This was replaced by #1196 and #1199

@Gudahtt Gudahtt closed this Apr 25, 2023
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.

NetworkController API normalization: Replace network state with networkStatus state and delete isCustomNetwork state

3 participants