From c130124a689f1474e28ce13f58d73cec6383635f Mon Sep 17 00:00:00 2001 From: Hassan Malik Date: Thu, 7 Nov 2024 23:11:37 +0900 Subject: [PATCH] update types --- .../src/interface/SnapInterfaceController.ts | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/snaps-controllers/src/interface/SnapInterfaceController.ts b/packages/snaps-controllers/src/interface/SnapInterfaceController.ts index 3cc50bd317..0cc765ed42 100644 --- a/packages/snaps-controllers/src/interface/SnapInterfaceController.ts +++ b/packages/snaps-controllers/src/interface/SnapInterfaceController.ts @@ -22,7 +22,7 @@ import { ContentType } from '@metamask/snaps-sdk'; import type { JSXElement } from '@metamask/snaps-sdk/jsx'; import { getJsonSizeUnsafe, validateJsxLinks } from '@metamask/snaps-utils'; import type { Json } from '@metamask/utils'; -import { assert } from '@metamask/utils'; +import { assert, hasProperty } from '@metamask/utils'; import { castDraft } from 'immer'; import { nanoid } from 'nanoid'; @@ -94,9 +94,32 @@ export type SnapInterfaceControllerStateChangeEvent = SnapInterfaceControllerState >; +type OtherNotification = { type: string; [key: string]: unknown }; + +export type ExpandedView = { + title: string; + interfaceId: string; + footerLink?: { href: string; text: string }; +}; + +type RawSnapNotificationData = + | { + message: string; + origin: string; + } + | { message: string; origin: string; detailedView: ExpandedView }; + +type SnapNotification = { + type: 'snap'; + data: RawSnapNotificationData; + readDate: string | null; +}; + +type Notification = OtherNotification | SnapNotification; + type NotificationListUpdatedEvent = { type: 'NotificationServicesController:notificationsListUpdated'; - payload: [Record[]]; + payload: [Notification[]]; }; export type SnapInterfaceControllerEvents = @@ -425,15 +448,19 @@ export class SnapInterfaceController extends BaseController< ); } - #onNotificationsListUpdated(notificationsList: Record[]) { + #onNotificationsListUpdated(notificationsList: Notification[]) { const snapNotificationsWithInterface = notificationsList.filter( (notification) => { - return notification.type === 'snap' && notification.data?.detailedView; + return ( + notification.type === 'snap' && + hasProperty((notification as SnapNotification).data, 'detailedView') + ); }, ); const interfaceIdSet = new Set( snapNotificationsWithInterface.map( + // @ts-expect-error - Notification is SnapNotification here. (notification) => notification.data.detailedView.interfaceId, ), );