Skip to content

Commit 9ed03e0

Browse files
authored
feat: Add new metadata properties to SelectedNetworkController (#6526)
1 parent 0a6e91c commit 9ed03e0

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

packages/selected-network-controller/CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6526](https://github.com/MetaMask/core/pull/6526))
13+
1014
### Changed
1115

1216
- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

packages/selected-network-controller/src/SelectedNetworkController.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ import type { Patch } from 'immer';
2121
export const controllerName = 'SelectedNetworkController';
2222

2323
const stateMetadata = {
24-
domains: { persist: true, anonymous: false },
24+
domains: {
25+
includeInStateLogs: true,
26+
persist: true,
27+
anonymous: false,
28+
usedInUi: true,
29+
},
2530
};
2631

2732
const getDefaultState = () => ({ domains: {} });

packages/selected-network-controller/tests/SelectedNetworkController.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Messenger } from '@metamask/base-controller';
1+
import { deriveStateFromMetadata, Messenger } from '@metamask/base-controller';
22
import {
33
type ProviderProxy,
44
type BlockTrackerProxy,
@@ -1137,4 +1137,66 @@ describe('SelectedNetworkController', () => {
11371137
});
11381138
});
11391139
});
1140+
1141+
describe('metadata', () => {
1142+
it('includes expected state in debug snapshots', () => {
1143+
const { controller } = setup();
1144+
1145+
expect(
1146+
deriveStateFromMetadata(
1147+
controller.state,
1148+
controller.metadata,
1149+
'anonymous',
1150+
),
1151+
).toMatchInlineSnapshot(`Object {}`);
1152+
});
1153+
1154+
it('includes expected state in state logs', () => {
1155+
const { controller } = setup();
1156+
1157+
expect(
1158+
deriveStateFromMetadata(
1159+
controller.state,
1160+
controller.metadata,
1161+
'includeInStateLogs',
1162+
),
1163+
).toMatchInlineSnapshot(`
1164+
Object {
1165+
"domains": Object {},
1166+
}
1167+
`);
1168+
});
1169+
1170+
it('persists expected state', () => {
1171+
const { controller } = setup();
1172+
1173+
expect(
1174+
deriveStateFromMetadata(
1175+
controller.state,
1176+
controller.metadata,
1177+
'persist',
1178+
),
1179+
).toMatchInlineSnapshot(`
1180+
Object {
1181+
"domains": Object {},
1182+
}
1183+
`);
1184+
});
1185+
1186+
it('exposes expected state to UI', () => {
1187+
const { controller } = setup();
1188+
1189+
expect(
1190+
deriveStateFromMetadata(
1191+
controller.state,
1192+
controller.metadata,
1193+
'usedInUi',
1194+
),
1195+
).toMatchInlineSnapshot(`
1196+
Object {
1197+
"domains": Object {},
1198+
}
1199+
`);
1200+
});
1201+
});
11401202
});

0 commit comments

Comments
 (0)