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

feat: bump notifications services controller to v1.0.0 #30532

Merged
merged 2 commits into from
Feb 25, 2025
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
100 changes: 58 additions & 42 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1336,14 +1341,15 @@ export default class MetamaskController extends EventEmitter {
}),
});

/** @type {import('@metamask/notification-services-controller/push-services').NotificationServicesPushControllerMessenger} */
const notificationServicesPushControllerMessenger =
this.controllerMessenger.getRestricted({
name: 'NotificationServicesPushController',
allowedActions: ['AuthenticationController:getBearerToken'],
allowedEvents: [],
});
this.notificationServicesPushController =
new NotificationServicesPushController.Controller({
new NotificationServicesPushController({
messenger: notificationServicesPushControllerMessenger,
state: initState.NotificationServicesPushController,
env: {
Expand All @@ -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(
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@
"isUpdatingMetamaskNotificationsAccount": "object",
"isCheckingAccountsPresence": "boolean"
},
"NotificationServicesPushController": { "fcmToken": "string" },
"NotificationServicesPushController": {
"fcmToken": "string",
"isPushEnabled": "boolean",
"isUpdatingFCMToken": "boolean"
},
"OnboardingController": {
"seedPhraseBackedUp": true,
"firstTimeFlowType": "import",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@
"isUpdatingMetamaskNotificationsAccount": "object",
"isCheckingAccountsPresence": "boolean",
"queuedRequestCount": 0,
"isPushEnabled": "boolean",
"fcmToken": "string",
"isUpdatingFCMToken": "boolean",
"remoteFeatureFlags": {},
"cacheTimestamp": "number",
"accounts": "object",
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5848,22 +5848,22 @@ __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"
uuid: "npm:^8.3.2"
peerDependencies:
"@metamask/keyring-controller": ^19.0.0
"@metamask/profile-sync-controller": ^8.0.0
checksum: 10/8014019e3d2aa174433f8e1f7b6ab895fe0047ba8dfaa93f2a3bb356ea34b066b6193fd0f7c38e8f71b9ed22c89ae2663491e886d598c21db0e03e501a46c6c1
checksum: 10/9cb7cee622ee8485d4424dcf42ffbd4c932572c2c21dc723d6e3e5204fb24f37c01a9080a1826bfd9cfea986233e757cb0630004512415ee966b3110db80f3e9
languageName: node
linkType: hard

Expand Down Expand Up @@ -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"
Expand Down
Loading