Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable notifications #4890

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading