Skip to content

Commit 442894c

Browse files
fix: remove push check in main notification controller
instead the push controller will bail early and do the correct checks
1 parent c96fc29 commit 442894c

File tree

3 files changed

+7
-32
lines changed

3 files changed

+7
-32
lines changed

packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import * as OnChainNotifications from './services/onchain-notifications';
4747
import type { INotification } from './types';
4848
import type { UserStorage } from './types/user-storage/user-storage';
4949
import * as Utils from './utils/utils';
50-
import type { NotificationServicesPushControllerGetStateAction } from '../NotificationServicesPushController';
5150

5251
// Mock type used for testing purposes
5352
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -959,7 +958,6 @@ function mockNotificationMessenger() {
959958
'KeyringController:getState',
960959
'AuthenticationController:getBearerToken',
961960
'AuthenticationController:isSignedIn',
962-
'NotificationServicesPushController:getState',
963961
'NotificationServicesPushController:disablePushNotifications',
964962
'NotificationServicesPushController:enablePushNotifications',
965963
'NotificationServicesPushController:updateTriggerPushNotifications',
@@ -1015,14 +1013,6 @@ function mockNotificationMessenger() {
10151013
const mockPerformSetStorage =
10161014
typedMockAction<UserStorageController.UserStorageControllerPerformSetStorage>();
10171015

1018-
const mockPushControllerGetState =
1019-
typedMockAction<NotificationServicesPushControllerGetStateAction>().mockReturnValue(
1020-
{
1021-
fcmToken: '',
1022-
isPushEnabled: true,
1023-
},
1024-
);
1025-
10261016
jest.spyOn(messenger, 'call').mockImplementation((...args) => {
10271017
const [actionType] = args;
10281018

@@ -1046,10 +1036,6 @@ function mockNotificationMessenger() {
10461036
return mockIsSignedIn();
10471037
}
10481038

1049-
if (actionType === 'NotificationServicesPushController:getState') {
1050-
return mockPushControllerGetState();
1051-
}
1052-
10531039
if (
10541040
actionType ===
10551041
'NotificationServicesPushController:disablePushNotifications'

packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import type { OnChainRawNotification } from './types/on-chain-notification/on-ch
3434
import type { UserStorage } from './types/user-storage/user-storage';
3535
import * as Utils from './utils/utils';
3636
import type {
37-
NotificationServicesPushControllerGetStateAction,
3837
NotificationServicesPushControllerStateChangeEvent,
3938
NotificationServicesPushControllerState,
4039
} from '../NotificationServicesPushController';
@@ -238,7 +237,6 @@ export type AllowedActions =
238237
| UserStorageController.UserStorageControllerPerformGetStorage
239238
| UserStorageController.UserStorageControllerPerformSetStorage
240239
// Push Notifications Controller Requests
241-
| NotificationServicesPushControllerGetStateAction
242240
| NotificationServicesPushControllerEnablePushNotifications
243241
| NotificationServicesPushControllerDisablePushNotifications
244242
| NotificationServicesPushControllerUpdateTriggerPushNotifications
@@ -365,10 +363,6 @@ export default class NotificationServicesController extends BaseController<
365363
};
366364

367365
readonly #pushNotifications = {
368-
isEnabled: () =>
369-
this.messagingSystem.call('NotificationServicesPushController:getState')
370-
?.isPushEnabled ?? false,
371-
372366
subscribeToPushEnabled: async () => {
373367
this.messagingSystem.subscribe(
374368
'NotificationServicesPushController:stateChange',
@@ -399,9 +393,6 @@ export default class NotificationServicesController extends BaseController<
399393
);
400394
},
401395
enablePushNotifications: async (UUIDs: string[]) => {
402-
if (!this.#pushNotifications.isEnabled()) {
403-
return;
404-
}
405396
try {
406397
await this.messagingSystem.call(
407398
'NotificationServicesPushController:enablePushNotifications',
@@ -412,9 +403,6 @@ export default class NotificationServicesController extends BaseController<
412403
}
413404
},
414405
disablePushNotifications: async (UUIDs: string[]) => {
415-
if (!this.#pushNotifications.isEnabled()) {
416-
return;
417-
}
418406
try {
419407
await this.messagingSystem.call(
420408
'NotificationServicesPushController:disablePushNotifications',
@@ -425,9 +413,6 @@ export default class NotificationServicesController extends BaseController<
425413
}
426414
},
427415
updatePushNotifications: async (UUIDs: string[]) => {
428-
if (!this.#pushNotifications.isEnabled()) {
429-
return;
430-
}
431416
try {
432417
await this.messagingSystem.call(
433418
'NotificationServicesPushController:updateTriggerPushNotifications',
@@ -438,9 +423,6 @@ export default class NotificationServicesController extends BaseController<
438423
}
439424
},
440425
subscribe: () => {
441-
if (!this.#pushNotifications.isEnabled()) {
442-
return;
443-
}
444426
this.messagingSystem.subscribe(
445427
'NotificationServicesPushController:onNewNotifications',
446428
(notification) => {

packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,18 @@ export default class NotificationServicesPushController extends BaseController<
215215

216216
setIsPushNotificationsEnabled(isEnabled: boolean) {
217217
this.update((state) => {
218+
if (!state.isPushEnabled) {
219+
state.fcmToken = '';
220+
}
218221
state.isPushEnabled = isEnabled;
219222
});
220223
}
221224

222225
async subscribeToPushNotifications() {
226+
if (!this.#config.isPushFeatureEnabled) {
227+
return;
228+
}
229+
223230
if (this.#pushListenerUnsubscribe) {
224231
this.#pushListenerUnsubscribe();
225232
this.#pushListenerUnsubscribe = undefined;

0 commit comments

Comments
 (0)