Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2054,14 +2054,15 @@ export class NetworkController extends BaseController<
* Creates and registers network clients for the collection of Infura and
* custom RPC endpoints that can be used to make requests for a particular
* chain, storing the given configuration object in state for later reference.
* After adding the network, it automatically sets it as the active network.
*
* @param fields - The object that describes the new network/chain and lists
* the RPC endpoints which front that chain.
* @returns The newly added network configuration.
* @throws if any part of `fields` would produce invalid state.
* @see {@link NetworkConfiguration}
*/
addNetwork(fields: AddNetworkFields): NetworkConfiguration {
async addNetwork(fields: AddNetworkFields): Promise<NetworkConfiguration> {
const { rpcEndpoints: setOfRpcEndpointFields } = fields;

const autoManagedNetworkClientRegistry =
Expand Down Expand Up @@ -2113,6 +2114,13 @@ export class NetworkController extends BaseController<
newNetworkConfiguration,
);

// Set the newly added network as the active network using the default RPC endpoint
const defaultRpcEndpoint =
newNetworkConfiguration.rpcEndpoints[
newNetworkConfiguration.defaultRpcEndpointIndex
];
await this.setActiveNetwork(defaultRpcEndpoint.networkClientId);

return newNetworkConfiguration;
}

Expand Down
Loading