Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
hmalik88 committed Nov 7, 2024
1 parent c6bfb69 commit c130124
Showing 1 changed file with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<string, any>[]];
payload: [Notification[]];
};

export type SnapInterfaceControllerEvents =
Expand Down Expand Up @@ -425,15 +448,19 @@ export class SnapInterfaceController extends BaseController<
);
}

#onNotificationsListUpdated(notificationsList: Record<string, any>[]) {
#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')

Check warning on line 456 in packages/snaps-controllers/src/interface/SnapInterfaceController.ts

View check run for this annotation

Codecov / codecov/patch

packages/snaps-controllers/src/interface/SnapInterfaceController.ts#L453-L456

Added lines #L453 - L456 were not covered by tests
);
},
);

const interfaceIdSet = new Set(
snapNotificationsWithInterface.map(
// @ts-expect-error - Notification is SnapNotification here.
(notification) => notification.data.detailedView.interfaceId,

Check warning on line 464 in packages/snaps-controllers/src/interface/SnapInterfaceController.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L464 was not covered by tests
),
);
Expand Down

0 comments on commit c130124

Please sign in to comment.