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
As we slowly multichain-ize our code, we are converting code that implicitly uses the global network to instead require a reference to a network client ID. In some cases, we need the chain ID associated with a network. The typical way to do this is:
However, this is a bit of a hack. The reason for this is that configuration property on a network client holds data that is used to initialize the client for a chain. But we do not need a chain ID to initialize a network client, since a chain already knows its ID. We only added chainId to NetworkClientConfiguration for convenience, but it really shouldn't be there. Instead, the network configuration is where consumers should get the chain ID.
The NetworkController does have a getNetworkConfigurationByNetworkClientId, but unfortunately it is not as convenient to use as it should, as it is possible for this method to return undefined. So while it would be more accurate to say this, I imagine consumers would probably rather not say it:
functionsomeFunctionThatUsesTheNetwork({ networkClientId }: {networkClientId: NetworkClientId}){constnetworkClient=messenger.call('NetworkController:getNetworkClientById',networkClientId,);constnetworkConfiguration=messenger.call('NetworkController:getNetworkConfigurationByNetworkClientId',networkClientId,);if(networkConfiguration===undefined){thrownewError("Network configuration not found for network client ID '${networkClientId}'");}constchainId=networkConfiguration.chainId;// ...}
We can make this better for consumers.
Acceptance Criteria
A method exists in NetworkController that allows consumers to pass a network client ID and get the network client and the network configuration in one go. This method should throw if a network configuration cannot be found so we don't have to return undefined (or we should find a way to avoid the undefined altogether).
The getNetworkConfigurationByNetworkClientId method and action are deprecated.
The configuration property on NetworkClient is deprecated.
Considerations
Consider calling the new method findNetworkByNetworkClientId, and the combination of a network client + network configuration a Network. The reasoning here is that we already have a light concept of a "network" because we have the methods addNetwork, updateNetwork and removeNetwork.
The text was updated successfully, but these errors were encountered:
Problem
As we slowly multichain-ize our code, we are converting code that implicitly uses the global network to instead require a reference to a network client ID. In some cases, we need the chain ID associated with a network. The typical way to do this is:
However, this is a bit of a hack. The reason for this is that
configuration
property on a network client holds data that is used to initialize the client for a chain. But we do not need a chain ID to initialize a network client, since a chain already knows its ID. We only addedchainId
toNetworkClientConfiguration
for convenience, but it really shouldn't be there. Instead, the network configuration is where consumers should get the chain ID.The NetworkController does have a
getNetworkConfigurationByNetworkClientId
, but unfortunately it is not as convenient to use as it should, as it is possible for this method to returnundefined
. So while it would be more accurate to say this, I imagine consumers would probably rather not say it:We can make this better for consumers.
Acceptance Criteria
undefined
(or we should find a way to avoid theundefined
altogether).getNetworkConfigurationByNetworkClientId
method and action are deprecated.configuration
property on NetworkClient is deprecated.Considerations
findNetworkByNetworkClientId
, and the combination of a network client + network configuration aNetwork
. The reasoning here is that we already have a light concept of a "network" because we have the methodsaddNetwork
,updateNetwork
andremoveNetwork
.The text was updated successfully, but these errors were encountered: