You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both the extension and mobile apps operate directly on controller state:
The extension picks properties from state via selectors and uses them within Redux actions
The mobile app reads state directly from controller state
In some cases, the client needs to get the chain ID of the currently selected global network, and all they have is state (they do not have access to a controller instance or a messenger). While the network client ID is easy to get purely from state — it's just stored as selectedNetworkClientId on NetworkController state` — the chain ID is not. The client must do the following:
functiongetCurrentChainId(networkControllerState: NetworkControllerState){constselectedNetworkConfiguration=Object.values(networkControllerState).networkConfigurationsByChainId.find((networkConfiguration)=>{returnnetworkConfiguration.rpcEndpoints.some((rpcEndpoint)=>{returnrpcEndpoint.networkClientId===networkControllerState.selectedNetworkClientId;});});if(selectedNetworkConfiguration===undefined){thrownewError("Could not find network configuration for selected network client ID '${networkControllerState.selectedNetworkClientId}'");}returnnetworkConfiguration.chainId;}
This is cumbersome, and I imagine engineers do not want to do this (or will figure out a shortcut which may compromise type safety).
Acceptance Criteria
Consumers are able to access the chain ID of the currently selected network in a type-safe way without needing to iterate over networkConfigurationsByChainId.
Considerations
We could add a new state property, selectedChainId, which would be set whenever selectedNetworkClientId is set.
This would not only satisfy the requirements but would also allow the consumer to easily look up the network configuration for the currently selected network purely from state if they wanted:
Problem
Both the extension and mobile apps operate directly on controller state:
In some cases, the client needs to get the chain ID of the currently selected global network, and all they have is state (they do not have access to a controller instance or a messenger). While the network client ID is easy to get purely from state — it's just stored as
selectedNetworkClientId
on NetworkController state` — the chain ID is not. The client must do the following:This is cumbersome, and I imagine engineers do not want to do this (or will figure out a shortcut which may compromise type safety).
Acceptance Criteria
networkConfigurationsByChainId
.Considerations
We could add a new state property,
selectedChainId
, which would be set wheneverselectedNetworkClientId
is set.This would not only satisfy the requirements but would also allow the consumer to easily look up the network configuration for the currently selected network purely from state if they wanted:
which is not currently possible just using
selectedNetworkClientId
.The text was updated successfully, but these errors were encountered: