From dce046fa24ac540fd2fa4dd64dd07f1d2918ad8c Mon Sep 17 00:00:00 2001 From: Hassan Malik Date: Sat, 2 Nov 2024 04:19:45 +0900 Subject: [PATCH 1/2] fix disable notifications --- .../NotificationServicesController.test.ts | 12 +++++++++++- .../NotificationServicesController.ts | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts index 2e3da824191..02c209f55f1 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts @@ -43,6 +43,7 @@ import { processSnapNotification } from './processors/process-snap-notifications import * as OnChainNotifications from './services/onchain-notifications'; import type { UserStorage } from './types/user-storage/user-storage'; import * as Utils from './utils/utils'; +import { INotification } from './types'; // Mock type used for testing purposes // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -834,7 +835,13 @@ describe('metamask-notifications - disableMetamaskNotifications()', () => { const controller = new NotificationServicesController({ messenger: mocks.messenger, env: { featureAnnouncements: featureAnnouncementsEnv }, - state: { isNotificationServicesEnabled: true }, + state: { + isNotificationServicesEnabled: true, + metamaskNotificationsList: [ + createMockFeatureAnnouncementRaw() as INotification, + createMockSnapNotification() as INotification, + ], + }, }); const promise = controller.disableNotificationServices(); @@ -847,6 +854,9 @@ describe('metamask-notifications - disableMetamaskNotifications()', () => { // Act - final state expect(controller.state.isUpdatingMetamaskNotifications).toBe(false); expect(controller.state.isNotificationServicesEnabled).toBe(false); + expect(controller.state.metamaskNotificationsList).toStrictEqual([ + createMockSnapNotification(), + ]); expect(mocks.mockDisablePushNotifications).toHaveBeenCalled(); diff --git a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts index 5a8d204e4a9..1421b6cf690 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts @@ -924,11 +924,17 @@ export default class NotificationServicesController extends BaseController< const UUIDs = Utils.getAllUUIDs(userStorage); await this.#pushNotifications.disablePushNotifications(UUIDs); + const snapNotifications = this.state.metamaskNotificationsList.filter( + (notification) => notification.type === TRIGGER_TYPES.SNAP, + ); + // Clear Notification States (toggles and list) this.update((state) => { state.isNotificationServicesEnabled = false; state.isFeatureAnnouncementsEnabled = false; - state.metamaskNotificationsList = []; + // reassigning the notifications list with just snaps + // since the disable shouldn't affect snaps notifications + state.metamaskNotificationsList = snapNotifications; }); } catch (e) { log.error('Unable to disable notifications', e); From 3271ab51378e1f5d96288baf43349992358fde32 Mon Sep 17 00:00:00 2001 From: Hassan Malik Date: Sat, 2 Nov 2024 04:35:18 +0900 Subject: [PATCH 2/2] lint fix --- .../NotificationServicesController.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts index 02c209f55f1..13745c925b7 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts @@ -41,9 +41,9 @@ import { processFeatureAnnouncement } from './processors'; import { processNotification } from './processors/process-notifications'; import { processSnapNotification } from './processors/process-snap-notifications'; import * as OnChainNotifications from './services/onchain-notifications'; +import type { INotification } from './types'; import type { UserStorage } from './types/user-storage/user-storage'; import * as Utils from './utils/utils'; -import { INotification } from './types'; // Mock type used for testing purposes // eslint-disable-next-line @typescript-eslint/no-explicit-any