Skip to content

Commit bbc5326

Browse files
Merge branch 'main' into feat/internal-account-validation-data
2 parents 2238799 + c28abce commit bbc5326

File tree

7 files changed

+98
-48
lines changed

7 files changed

+98
-48
lines changed

.github/workflows/add-wallet-framework-team-prs-and-issues-to-project.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
jobs:
1010
call_shared_workflow:
1111
name: 'Call the Shared Workflow'
12+
permissions:
13+
issues: write
14+
pull-requests: write
15+
contents: read
16+
repository-projects: write
1217
uses: metamask/github-tools/.github/workflows/add-item-to-project.yml@bce51a03da4736bef72f67b71ca77714a38fc067
1318
with:
1419
project-url: 'https://github.com/orgs/MetaMask/projects/113'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/core-monorepo",
3-
"version": "319.0.0",
3+
"version": "320.0.0",
44
"private": true,
55
"description": "Monorepo for packages shared between MetaMask clients",
66
"repository": {

packages/assets-controllers/CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [53.1.0]
11+
12+
### Added
13+
14+
- Add token display data controller for search & discovery ([#5307](https://github.com/MetaMask/core/pull/5307))
15+
1016
## [53.0.0]
1117

1218
### Added
@@ -1454,7 +1460,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14541460
14551461
- Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
14561462
1457-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@53.0.0...HEAD
1463+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@53.1.0...HEAD
1464+
[53.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@53.0.0...@metamask/assets-controllers@53.1.0
14581465
[53.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@52.0.0...@metamask/assets-controllers@53.0.0
14591466
[52.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@51.0.2...@metamask/assets-controllers@52.0.0
14601467
[51.0.2]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@51.0.1...@metamask/assets-controllers@51.0.2

packages/assets-controllers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/assets-controllers",
3-
"version": "53.0.0",
3+
"version": "53.1.0",
44
"description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
55
"keywords": [
66
"MetaMask",

packages/network-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4242
- Bump `@metamask/eth-json-rpc-infura` to `^10.1.0`
4343
- Bump `@metamask/eth-json-rpc-middleware` to `^15.1.0`
4444

45+
### Fixed
46+
47+
- Fix `findNetworkClientIdByChainId` to return the network client ID for the chain's configured default RPC endpoint instead of its first listed RPC endpoint ([#5344](https://github.com/MetaMask/core/pull/5344))
48+
4549
## [22.2.1]
4650

4751
### Changed

packages/network-controller/src/NetworkController.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,20 +2108,27 @@ export class NetworkController extends BaseController<
21082108
}
21092109

21102110
/**
2111-
* Searches for a network configuration ID with the given ChainID and returns it.
2111+
* Searches for the default RPC endpoint configured for the given chain and
2112+
* returns its network client ID. This can then be passed to
2113+
* {@link getNetworkClientById} to retrieve the network client.
21122114
*
2113-
* @param chainId - ChainId to search for
2114-
* @returns networkClientId of the network configuration with the given chainId
2115+
* @param chainId - Chain ID to search for.
2116+
* @returns The ID of the network client created for the chain's default RPC
2117+
* endpoint.
21152118
*/
21162119
findNetworkClientIdByChainId(chainId: Hex): NetworkClientId {
2117-
const networkClients = this.getNetworkClientRegistry();
2118-
const networkClientEntry = Object.entries(networkClients).find(
2119-
([_, networkClient]) => networkClient.configuration.chainId === chainId,
2120-
);
2121-
if (networkClientEntry === undefined) {
2122-
throw new Error("Couldn't find networkClientId for chainId");
2120+
const networkConfiguration =
2121+
this.state.networkConfigurationsByChainId[chainId];
2122+
2123+
if (!networkConfiguration) {
2124+
throw new Error(`Invalid chain ID "${chainId}"`);
21232125
}
2124-
return networkClientEntry[0];
2126+
2127+
const { networkClientId } =
2128+
networkConfiguration.rpcEndpoints[
2129+
networkConfiguration.defaultRpcEndpointIndex
2130+
];
2131+
return networkClientId;
21252132
}
21262133

21272134
/**

packages/network-controller/tests/NetworkController.test.ts

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -919,48 +919,75 @@ describe('NetworkController', () => {
919919
});
920920
});
921921

922-
describe('findNetworkConfigurationByChainId', () => {
923-
it('returns the network configuration for the given chainId', async () => {
922+
describe.each([
923+
[
924+
'findNetworkClientIdByChainId',
925+
(
926+
{
927+
controller,
928+
}: {
929+
controller: NetworkController;
930+
},
931+
args: Parameters<NetworkController['findNetworkClientIdByChainId']>,
932+
): ReturnType<NetworkController['findNetworkClientIdByChainId']> =>
933+
controller.findNetworkClientIdByChainId(...args),
934+
],
935+
[
936+
'NetworkController:findNetworkClientIdByChainId',
937+
(
938+
{
939+
messenger,
940+
}: {
941+
messenger: Messenger<
942+
NetworkControllerActions,
943+
NetworkControllerEvents
944+
>;
945+
},
946+
args: Parameters<NetworkController['findNetworkClientIdByChainId']>,
947+
): ReturnType<NetworkController['findNetworkClientIdByChainId']> =>
948+
messenger.call(
949+
'NetworkController:findNetworkClientIdByChainId',
950+
...args,
951+
),
952+
],
953+
])('%s', (_desc, findNetworkClientIdByChainId) => {
954+
it('returns the ID of the network client corresponding to the default RPC endpoint for the given chain', async () => {
924955
await withController(
925-
{ infuraProjectId: 'some-infura-project-id' },
926-
async ({ controller }) => {
927-
const fakeNetworkClient = buildFakeClient();
928-
mockCreateNetworkClient().mockReturnValue(fakeNetworkClient);
929-
930-
const networkClientId =
931-
controller.findNetworkClientIdByChainId('0x1');
932-
expect(networkClientId).toBe('mainnet');
956+
{
957+
state: buildNetworkControllerStateWithDefaultSelectedNetworkClientId({
958+
networkConfigurationsByChainId: {
959+
'0x1337': buildCustomNetworkConfiguration({
960+
chainId: '0x1337' as const,
961+
defaultRpcEndpointIndex: 1,
962+
rpcEndpoints: [
963+
buildCustomRpcEndpoint({
964+
networkClientId: 'AAAA-AAAA-AAAA-AAAA',
965+
}),
966+
buildCustomRpcEndpoint({
967+
networkClientId: 'BBBB-BBBB-BBBB-BBBB',
968+
}),
969+
],
970+
}),
971+
},
972+
}),
933973
},
934-
);
935-
});
974+
({ controller, messenger }) => {
975+
const networkClientId = findNetworkClientIdByChainId(
976+
{ controller, messenger },
977+
['0x1337'],
978+
);
936979

937-
it('throws if the chainId doesnt exist in the configuration', async () => {
938-
await withController(
939-
{ infuraProjectId: 'some-infura-project-id' },
940-
async ({ controller }) => {
941-
const fakeNetworkClient = buildFakeClient();
942-
mockCreateNetworkClient().mockReturnValue(fakeNetworkClient);
943-
expect(() =>
944-
controller.findNetworkClientIdByChainId('0xdeadbeef'),
945-
).toThrow("Couldn't find networkClientId for chainId");
980+
expect(networkClientId).toBe('BBBB-BBBB-BBBB-BBBB');
946981
},
947982
);
948983
});
949984

950-
it('is callable from the controller messenger', async () => {
951-
await withController(
952-
{ infuraProjectId: 'some-infura-project-id' },
953-
async ({ messenger }) => {
954-
const fakeNetworkClient = buildFakeClient();
955-
mockCreateNetworkClient().mockReturnValue(fakeNetworkClient);
956-
957-
const networkClientId = messenger.call(
958-
'NetworkController:findNetworkClientIdByChainId',
959-
'0x1',
960-
);
961-
expect(networkClientId).toBe('mainnet');
962-
},
963-
);
985+
it('throws if there are no network clients registered for the given chain', async () => {
986+
await withController(({ controller, messenger }) => {
987+
expect(() =>
988+
findNetworkClientIdByChainId({ controller, messenger }, ['0x999999']),
989+
).toThrow('Invalid chain ID "0x999999"');
990+
});
964991
});
965992
});
966993

0 commit comments

Comments
 (0)