diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index d1288bc74d2a..07929a532f29 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -142,9 +142,15 @@ import { UserStorageController, } from '@metamask/profile-sync-controller'; import { - NotificationServicesPushController, - NotificationServicesController, -} from '@metamask/notification-services-controller'; + TRIGGER_TYPES, + Controller as NotificationServicesController, +} from '@metamask/notification-services-controller/notification-services'; +import { Controller as NotificationServicesPushController } from '@metamask/notification-services-controller/push-services'; +import { + createRegToken, + deleteRegToken, + createSubscribeToPushNotifications, +} from '@metamask/notification-services-controller/push-services/web'; import { Caip25CaveatMutators, Caip25CaveatType, @@ -373,7 +379,6 @@ import { SnapsRegistryInit, } from './controller-init/snaps'; -const { TRIGGER_TYPES } = NotificationServicesController.Constants; export const METAMASK_CONTROLLER_EVENTS = { // Fired after state changes that impact the extension badge (unapproved msg count) // The process of updating the badge happens in app/scripts/background.js. @@ -1336,6 +1341,7 @@ export default class MetamaskController extends EventEmitter { }), }); + /** @type {import('@metamask/notification-services-controller/push-services').NotificationServicesPushControllerMessenger} */ const notificationServicesPushControllerMessenger = this.controllerMessenger.getRestricted({ name: 'NotificationServicesPushController', @@ -1343,7 +1349,7 @@ export default class MetamaskController extends EventEmitter { allowedEvents: [], }); this.notificationServicesPushController = - new NotificationServicesPushController.Controller({ + new NotificationServicesPushController({ messenger: notificationServicesPushControllerMessenger, state: initState.NotificationServicesPushController, env: { @@ -1357,10 +1363,17 @@ export default class MetamaskController extends EventEmitter { vapidKey: process.env.VAPID_KEY ?? '', }, config: { - isPushEnabled: isManifestV3, + isPushFeatureEnabled: isManifestV3, platform: 'extension', - onPushNotificationReceived, - onPushNotificationClicked, + pushService: { + createRegToken, + deleteRegToken, + subscribeToPushNotifications: createSubscribeToPushNotifications({ + messenger: notificationServicesPushControllerMessenger, + onReceivedHandler: onPushNotificationReceived, + onClickHandler: onPushNotificationClicked, + }), + }, }, }); notificationServicesPushControllerMessenger.subscribe( @@ -1392,41 +1405,44 @@ export default class MetamaskController extends EventEmitter { }, ); - this.notificationServicesController = - new NotificationServicesController.Controller({ - messenger: this.controllerMessenger.getRestricted({ - name: 'NotificationServicesController', - allowedActions: [ - 'KeyringController:getAccounts', - 'KeyringController:getState', - 'AuthenticationController:getBearerToken', - 'AuthenticationController:isSignedIn', - 'AuthenticationController:performSignIn', - 'UserStorageController:getStorageKey', - 'UserStorageController:performGetStorage', - 'UserStorageController:performSetStorage', - 'NotificationServicesPushController:enablePushNotifications', - 'NotificationServicesPushController:disablePushNotifications', - 'NotificationServicesPushController:subscribeToPushNotifications', - 'NotificationServicesPushController:updateTriggerPushNotifications', - ], - allowedEvents: [ - 'KeyringController:stateChange', - 'KeyringController:lock', - 'KeyringController:unlock', - 'NotificationServicesPushController:onNewNotifications', - ], - }), - state: initState.NotificationServicesController, - env: { - isPushIntegrated: isManifestV3, - featureAnnouncements: { - platform: 'extension', - spaceId: process.env.CONTENTFUL_ACCESS_SPACE_ID ?? '', - accessToken: process.env.CONTENTFUL_ACCESS_TOKEN ?? '', - }, - }, + /** @type {import('@metamask/notification-services-controller/notification-services').NotificationServicesControllerMessenger} */ + const notificationServicesControllerMessenger = + this.controllerMessenger.getRestricted({ + name: 'NotificationServicesController', + allowedActions: [ + 'KeyringController:getAccounts', + 'KeyringController:getState', + 'AuthenticationController:getBearerToken', + 'AuthenticationController:isSignedIn', + 'AuthenticationController:performSignIn', + 'UserStorageController:getStorageKey', + 'UserStorageController:performGetStorage', + 'UserStorageController:performSetStorage', + 'NotificationServicesPushController:enablePushNotifications', + 'NotificationServicesPushController:disablePushNotifications', + 'NotificationServicesPushController:subscribeToPushNotifications', + 'NotificationServicesPushController:updateTriggerPushNotifications', + ], + allowedEvents: [ + 'KeyringController:stateChange', + 'KeyringController:lock', + 'KeyringController:unlock', + 'NotificationServicesPushController:onNewNotifications', + 'NotificationServicesPushController:stateChange', + ], }); + this.notificationServicesController = new NotificationServicesController({ + messenger: notificationServicesControllerMessenger, + state: initState.NotificationServicesController, + env: { + isPushIntegrated: isManifestV3, + featureAnnouncements: { + platform: 'extension', + spaceId: process.env.CONTENTFUL_ACCESS_SPACE_ID ?? '', + accessToken: process.env.CONTENTFUL_ACCESS_TOKEN ?? '', + }, + }, + }); // account tracker watches balances, nonces, and any code at their address this.accountTrackerController = new AccountTrackerController({ diff --git a/package.json b/package.json index e0f31eba6c97..ae45994c86a4 100644 --- a/package.json +++ b/package.json @@ -295,7 +295,7 @@ "@metamask/multichain-transactions-controller": "^0.5.0", "@metamask/name-controller": "^8.0.3", "@metamask/network-controller": "patch:@metamask/network-controller@npm%3A22.1.1#~/.yarn/patches/@metamask-network-controller-npm-22.1.1-09b6510f1e.patch", - "@metamask/notification-services-controller": "^0.21.0", + "@metamask/notification-services-controller": "^1.0.0", "@metamask/object-multiplex": "^2.0.0", "@metamask/obs-store": "^9.0.0", "@metamask/permission-controller": "^11.0.6", diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json index 14c0bde14a1a..c188dc16d6db 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json @@ -184,7 +184,11 @@ "isUpdatingMetamaskNotificationsAccount": "object", "isCheckingAccountsPresence": "boolean" }, - "NotificationServicesPushController": { "fcmToken": "string" }, + "NotificationServicesPushController": { + "fcmToken": "string", + "isPushEnabled": "boolean", + "isUpdatingFCMToken": "boolean" + }, "OnboardingController": { "seedPhraseBackedUp": true, "firstTimeFlowType": "import", diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json index 75ee3aebc3ec..8ab8822be8e3 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json @@ -287,7 +287,9 @@ "isUpdatingMetamaskNotificationsAccount": "object", "isCheckingAccountsPresence": "boolean", "queuedRequestCount": 0, + "isPushEnabled": "boolean", "fcmToken": "string", + "isUpdatingFCMToken": "boolean", "remoteFeatureFlags": {}, "cacheTimestamp": "number", "accounts": "object", diff --git a/yarn.lock b/yarn.lock index 13079f51d0d8..e90c625f38f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5848,14 +5848,14 @@ __metadata: languageName: node linkType: hard -"@metamask/notification-services-controller@npm:^0.21.0": - version: 0.21.0 - resolution: "@metamask/notification-services-controller@npm:0.21.0" +"@metamask/notification-services-controller@npm:^1.0.0": + version: 1.0.0 + resolution: "@metamask/notification-services-controller@npm:1.0.0" dependencies: "@contentful/rich-text-html-renderer": "npm:^16.5.2" "@metamask/base-controller": "npm:^8.0.0" "@metamask/controller-utils": "npm:^11.5.0" - "@metamask/utils": "npm:^11.1.0" + "@metamask/utils": "npm:^11.2.0" bignumber.js: "npm:^9.1.2" firebase: "npm:^11.2.0" loglevel: "npm:^1.8.1" @@ -5863,7 +5863,7 @@ __metadata: peerDependencies: "@metamask/keyring-controller": ^19.0.0 "@metamask/profile-sync-controller": ^8.0.0 - checksum: 10/8014019e3d2aa174433f8e1f7b6ab895fe0047ba8dfaa93f2a3bb356ea34b066b6193fd0f7c38e8f71b9ed22c89ae2663491e886d598c21db0e03e501a46c6c1 + checksum: 10/9cb7cee622ee8485d4424dcf42ffbd4c932572c2c21dc723d6e3e5204fb24f37c01a9080a1826bfd9cfea986233e757cb0630004512415ee966b3110db80f3e9 languageName: node linkType: hard @@ -26976,7 +26976,7 @@ __metadata: "@metamask/multichain-transactions-controller": "npm:^0.5.0" "@metamask/name-controller": "npm:^8.0.3" "@metamask/network-controller": "patch:@metamask/network-controller@npm%3A22.1.1#~/.yarn/patches/@metamask-network-controller-npm-22.1.1-09b6510f1e.patch" - "@metamask/notification-services-controller": "npm:^0.21.0" + "@metamask/notification-services-controller": "npm:^1.0.0" "@metamask/object-multiplex": "npm:^2.0.0" "@metamask/obs-store": "npm:^9.0.0" "@metamask/permission-controller": "npm:^11.0.6"