Skip to content

Commit

Permalink
fix: disable notifications (#4890)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmalik88 authored Nov 1, 2024
1 parent 6814f82 commit 096f2d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ 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';

Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 096f2d1

Please sign in to comment.