Skip to content

Commit c130124

Browse files
committed
update types
1 parent c6bfb69 commit c130124

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

packages/snaps-controllers/src/interface/SnapInterfaceController.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { ContentType } from '@metamask/snaps-sdk';
2222
import type { JSXElement } from '@metamask/snaps-sdk/jsx';
2323
import { getJsonSizeUnsafe, validateJsxLinks } from '@metamask/snaps-utils';
2424
import type { Json } from '@metamask/utils';
25-
import { assert } from '@metamask/utils';
25+
import { assert, hasProperty } from '@metamask/utils';
2626
import { castDraft } from 'immer';
2727
import { nanoid } from 'nanoid';
2828

@@ -94,9 +94,32 @@ export type SnapInterfaceControllerStateChangeEvent =
9494
SnapInterfaceControllerState
9595
>;
9696

97+
type OtherNotification = { type: string; [key: string]: unknown };
98+
99+
export type ExpandedView = {
100+
title: string;
101+
interfaceId: string;
102+
footerLink?: { href: string; text: string };
103+
};
104+
105+
type RawSnapNotificationData =
106+
| {
107+
message: string;
108+
origin: string;
109+
}
110+
| { message: string; origin: string; detailedView: ExpandedView };
111+
112+
type SnapNotification = {
113+
type: 'snap';
114+
data: RawSnapNotificationData;
115+
readDate: string | null;
116+
};
117+
118+
type Notification = OtherNotification | SnapNotification;
119+
97120
type NotificationListUpdatedEvent = {
98121
type: 'NotificationServicesController:notificationsListUpdated';
99-
payload: [Record<string, any>[]];
122+
payload: [Notification[]];
100123
};
101124

102125
export type SnapInterfaceControllerEvents =
@@ -425,15 +448,19 @@ export class SnapInterfaceController extends BaseController<
425448
);
426449
}
427450

428-
#onNotificationsListUpdated(notificationsList: Record<string, any>[]) {
451+
#onNotificationsListUpdated(notificationsList: Notification[]) {
429452
const snapNotificationsWithInterface = notificationsList.filter(
430453
(notification) => {
431-
return notification.type === 'snap' && notification.data?.detailedView;
454+
return (
455+
notification.type === 'snap' &&
456+
hasProperty((notification as SnapNotification).data, 'detailedView')
457+
);
432458
},
433459
);
434460

435461
const interfaceIdSet = new Set(
436462
snapNotificationsWithInterface.map(
463+
// @ts-expect-error - Notification is SnapNotification here.
437464
(notification) => notification.data.detailedView.interfaceId,
438465
),
439466
);

0 commit comments

Comments
 (0)