@@ -22,7 +22,7 @@ import { ContentType } from '@metamask/snaps-sdk';
22
22
import type { JSXElement } from '@metamask/snaps-sdk/jsx' ;
23
23
import { getJsonSizeUnsafe , validateJsxLinks } from '@metamask/snaps-utils' ;
24
24
import type { Json } from '@metamask/utils' ;
25
- import { assert } from '@metamask/utils' ;
25
+ import { assert , hasProperty } from '@metamask/utils' ;
26
26
import { castDraft } from 'immer' ;
27
27
import { nanoid } from 'nanoid' ;
28
28
@@ -94,9 +94,32 @@ export type SnapInterfaceControllerStateChangeEvent =
94
94
SnapInterfaceControllerState
95
95
> ;
96
96
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
+
97
120
type NotificationListUpdatedEvent = {
98
121
type : 'NotificationServicesController:notificationsListUpdated' ;
99
- payload : [ Record < string , any > [ ] ] ;
122
+ payload : [ Notification [ ] ] ;
100
123
} ;
101
124
102
125
export type SnapInterfaceControllerEvents =
@@ -425,15 +448,19 @@ export class SnapInterfaceController extends BaseController<
425
448
) ;
426
449
}
427
450
428
- #onNotificationsListUpdated( notificationsList : Record < string , any > [ ] ) {
451
+ #onNotificationsListUpdated( notificationsList : Notification [ ] ) {
429
452
const snapNotificationsWithInterface = notificationsList . filter (
430
453
( notification ) => {
431
- return notification . type === 'snap' && notification . data ?. detailedView ;
454
+ return (
455
+ notification . type === 'snap' &&
456
+ hasProperty ( ( notification as SnapNotification ) . data , 'detailedView' )
457
+ ) ;
432
458
} ,
433
459
) ;
434
460
435
461
const interfaceIdSet = new Set (
436
462
snapNotificationsWithInterface . map (
463
+ // @ts -expect-error - Notification is SnapNotification here.
437
464
( notification ) => notification . data . detailedView . interfaceId ,
438
465
) ,
439
466
) ;
0 commit comments