Skip to content

Commit 7517b74

Browse files
committed
add metadata properties to AnnouncementController
1 parent b9cd824 commit 7517b74

File tree

3 files changed

+132
-2
lines changed

3 files changed

+132
-2
lines changed

packages/announcement-controller/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ 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` ([#1234](https://github.com/MetaMask/core/pull/1234))
13+
1014
### Changed
1115

1216
- Bump `@metamask/base-controller` from `^8.0.0` to `^8.3.0` ([#5722](https://github.com/MetaMask/core/pull/5722), [#6284](https://github.com/MetaMask/core/pull/6284), [#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465))
1317

18+
1419
## [7.0.3]
1520

1621
### Changed

packages/announcement-controller/src/AnnouncementController.test.ts

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Messenger } from '@metamask/base-controller';
1+
import { Messenger, deriveStateFromMetadata } from '@metamask/base-controller';
22

33
import type {
44
AnnouncementControllerState,
@@ -164,4 +164,126 @@ describe('announcement controller', () => {
164164
expect(controller.state.announcements[3].isShown).toBe(true);
165165
});
166166
});
167+
168+
describe('metadata', () => {
169+
it('includes expected state in debug snapshots', () => {
170+
const controller = new AnnouncementController({
171+
messenger: getRestrictedMessenger(),
172+
allAnnouncements,
173+
});
174+
175+
expect(
176+
deriveStateFromMetadata(
177+
controller.state,
178+
controller.metadata,
179+
'anonymous',
180+
),
181+
).toMatchInlineSnapshot(`
182+
Object {
183+
"announcements": Object {
184+
"1": Object {
185+
"date": "12/8/2020",
186+
"id": 1,
187+
"isShown": false,
188+
},
189+
"2": Object {
190+
"date": "12/8/2020",
191+
"id": 2,
192+
"isShown": false,
193+
},
194+
},
195+
}
196+
`);
197+
});
198+
199+
it('includes expected state in state logs', () => {
200+
const controller = new AnnouncementController({
201+
messenger: getRestrictedMessenger(),
202+
allAnnouncements,
203+
});
204+
205+
expect(
206+
deriveStateFromMetadata(
207+
controller.state,
208+
controller.metadata,
209+
'includeInStateLogs',
210+
),
211+
).toMatchInlineSnapshot(`
212+
Object {
213+
"announcements": Object {
214+
"1": Object {
215+
"date": "12/8/2020",
216+
"id": 1,
217+
"isShown": false,
218+
},
219+
"2": Object {
220+
"date": "12/8/2020",
221+
"id": 2,
222+
"isShown": false,
223+
},
224+
},
225+
}
226+
`);
227+
});
228+
229+
it('persists expected state', () => {
230+
const controller = new AnnouncementController({
231+
messenger: getRestrictedMessenger(),
232+
allAnnouncements,
233+
});
234+
235+
expect(
236+
deriveStateFromMetadata(
237+
controller.state,
238+
controller.metadata,
239+
'persist',
240+
),
241+
).toMatchInlineSnapshot(`
242+
Object {
243+
"announcements": Object {
244+
"1": Object {
245+
"date": "12/8/2020",
246+
"id": 1,
247+
"isShown": false,
248+
},
249+
"2": Object {
250+
"date": "12/8/2020",
251+
"id": 2,
252+
"isShown": false,
253+
},
254+
},
255+
}
256+
`);
257+
});
258+
259+
it('exposes expected state to UI', () => {
260+
const controller = new AnnouncementController({
261+
messenger: getRestrictedMessenger(),
262+
allAnnouncements,
263+
});
264+
265+
expect(
266+
deriveStateFromMetadata(
267+
controller.state,
268+
controller.metadata,
269+
'usedInUi',
270+
),
271+
).toMatchInlineSnapshot(`
272+
Object {
273+
"announcements": Object {
274+
"1": Object {
275+
"date": "12/8/2020",
276+
"id": 1,
277+
"isShown": false,
278+
},
279+
"2": Object {
280+
"date": "12/8/2020",
281+
"id": 2,
282+
"isShown": false,
283+
},
284+
},
285+
}
286+
`);
287+
});
288+
});
167289
});

packages/announcement-controller/src/AnnouncementController.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
ControllerGetStateAction,
33
ControllerStateChangeEvent,
44
RestrictedMessenger,
5+
StateMetadata,
56
} from '@metamask/base-controller';
67
import { BaseController } from '@metamask/base-controller';
78

@@ -59,10 +60,12 @@ const defaultState = {
5960
announcements: {},
6061
};
6162

62-
const metadata = {
63+
const metadata: StateMetadata<AnnouncementControllerState> = {
6364
announcements: {
65+
includeInStateLogs: true,
6466
persist: true,
6567
anonymous: true,
68+
usedInUi: true,
6669
},
6770
};
6871

0 commit comments

Comments
 (0)