Skip to content

Commit

Permalink
fix: notification services add new allowed events (#26987)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

This PR introduces a change to the `metamask-controller.js` file to add
an allowed action to the list of permitted actions for the
`NotificationServicesController`. Specifically, the action
`subscribeToPushNotifications` has been added for the
`NotificationServicesPushController`.

This PR is necessary after the release of this update:
MetaMask/core#4653

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26987?quickstart=1)

## **Related issues**

N/A

## **Manual testing steps**

N/A

## **Screenshots/Recordings**

N/A

### **Before**

N/A

### **After**

<!-- [screenshots/recordings] -->

N/A

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
matteoscurati authored Sep 13, 2024
1 parent b01f0c9 commit c5cfd1c
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 252 deletions.
110 changes: 52 additions & 58 deletions app/scripts/controllers/push-notifications/get-notification-message.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,64 @@
import type { NotificationServicesController } from '@metamask/notification-services-controller';
import { NotificationsServicesPushController } from '@metamask/notification-services-controller';
import { NotificationServicesPushController } from '@metamask/notification-services-controller';
import { t as translate } from '../../translate';

const t = (...args: Parameters<typeof translate>) => translate(...args) ?? '';

const translations: NotificationsServicesPushController.Utils.TranslationKeys =
{
pushPlatformNotificationsFundsSentTitle: () =>
t('pushPlatformNotificationsFundsSentTitle'),
pushPlatformNotificationsFundsSentDescriptionDefault: () =>
t('pushPlatformNotificationsFundsSentDescriptionDefault'),
pushPlatformNotificationsFundsSentDescription: (amount, symbol) =>
t('pushPlatformNotificationsFundsSentDescription', amount, symbol),
pushPlatformNotificationsFundsReceivedTitle: () =>
t('pushPlatformNotificationsFundsReceivedTitle'),
pushPlatformNotificationsFundsReceivedDescriptionDefault: () =>
t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
pushPlatformNotificationsFundsReceivedDescription: (amount, symbol) =>
t('pushPlatformNotificationsFundsReceivedDescription', amount, symbol),
pushPlatformNotificationsSwapCompletedTitle: () =>
t('pushPlatformNotificationsSwapCompletedTitle'),
pushPlatformNotificationsSwapCompletedDescription: () =>
t('pushPlatformNotificationsSwapCompletedDescription'),
pushPlatformNotificationsNftSentTitle: () =>
t('pushPlatformNotificationsNftSentTitle'),
pushPlatformNotificationsNftSentDescription: () =>
t('pushPlatformNotificationsNftSentDescription'),
pushPlatformNotificationsNftReceivedTitle: () =>
t('pushPlatformNotificationsNftReceivedTitle'),
pushPlatformNotificationsNftReceivedDescription: () =>
t('pushPlatformNotificationsNftReceivedDescription'),
pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle: () =>
t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),
pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription: () =>
t('pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription'),
pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle: () =>
t('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle'),
pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription: () =>
t(
'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',
),
pushPlatformNotificationsStakingLidoStakeCompletedTitle: () =>
t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),
pushPlatformNotificationsStakingLidoStakeCompletedDescription: () =>
t('pushPlatformNotificationsStakingLidoStakeCompletedDescription'),
pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle: () =>
t('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle'),
pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription:
() =>
t(
'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',
),
pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle: () =>
t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),
pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription: () =>
t('pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription'),
pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle: () =>
t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),
pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription: () =>
t('pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription'),
};
const translations: NotificationServicesPushController.Utils.TranslationKeys = {
pushPlatformNotificationsFundsSentTitle: () =>
t('pushPlatformNotificationsFundsSentTitle'),
pushPlatformNotificationsFundsSentDescriptionDefault: () =>
t('pushPlatformNotificationsFundsSentDescriptionDefault'),
pushPlatformNotificationsFundsSentDescription: (amount, symbol) =>
t('pushPlatformNotificationsFundsSentDescription', amount, symbol),
pushPlatformNotificationsFundsReceivedTitle: () =>
t('pushPlatformNotificationsFundsReceivedTitle'),
pushPlatformNotificationsFundsReceivedDescriptionDefault: () =>
t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
pushPlatformNotificationsFundsReceivedDescription: (amount, symbol) =>
t('pushPlatformNotificationsFundsReceivedDescription', amount, symbol),
pushPlatformNotificationsSwapCompletedTitle: () =>
t('pushPlatformNotificationsSwapCompletedTitle'),
pushPlatformNotificationsSwapCompletedDescription: () =>
t('pushPlatformNotificationsSwapCompletedDescription'),
pushPlatformNotificationsNftSentTitle: () =>
t('pushPlatformNotificationsNftSentTitle'),
pushPlatformNotificationsNftSentDescription: () =>
t('pushPlatformNotificationsNftSentDescription'),
pushPlatformNotificationsNftReceivedTitle: () =>
t('pushPlatformNotificationsNftReceivedTitle'),
pushPlatformNotificationsNftReceivedDescription: () =>
t('pushPlatformNotificationsNftReceivedDescription'),
pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle: () =>
t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),
pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription: () =>
t('pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription'),
pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle: () =>
t('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle'),
pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription: () =>
t('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription'),
pushPlatformNotificationsStakingLidoStakeCompletedTitle: () =>
t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),
pushPlatformNotificationsStakingLidoStakeCompletedDescription: () =>
t('pushPlatformNotificationsStakingLidoStakeCompletedDescription'),
pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle: () =>
t('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle'),
pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription: () =>
t('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription'),
pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle: () =>
t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),
pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription: () =>
t('pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription'),
pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle: () =>
t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),
pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription: () =>
t('pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription'),
};

export function createNotificationMessage(
n: NotificationServicesController.Types.INotification,
) {
return NotificationsServicesPushController.Utils.createOnChainPushNotificationMessage(
return NotificationServicesPushController.Utils.createOnChainPushNotificationMessage(
n,
translations,
);
Expand Down
14 changes: 10 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ import {
UserStorageController,
} from '@metamask/profile-sync-controller';
import {
NotificationsServicesPushController,
NotificationServicesPushController,
NotificationServicesController,
} from '@metamask/notification-services-controller';
import {
Expand Down Expand Up @@ -1485,7 +1485,12 @@ export default class MetamaskController extends EventEmitter {
'NotificationServicesController:disableNotificationServices',
'NotificationServicesController:selectIsNotificationServicesEnabled',
],
allowedEvents: ['KeyringController:lock', 'KeyringController:unlock'],
allowedEvents: [
'KeyringController:lock',
'KeyringController:unlock',
'AccountsController:accountAdded',
'AccountsController:accountRenamed',
],
}),
});

Expand All @@ -1496,9 +1501,9 @@ export default class MetamaskController extends EventEmitter {
allowedEvents: [],
});
this.notificationServicesPushController =
new NotificationsServicesPushController.Controller({
new NotificationServicesPushController.Controller({
messenger: notificationServicesPushControllerMessenger,
state: initState.NotificationsServicesPushController,
state: initState.NotificationServicesPushController,
env: {
apiKey: process.env.FIREBASE_API_KEY ?? '',
authDomain: process.env.FIREBASE_AUTH_DOMAIN ?? '',
Expand Down Expand Up @@ -1560,6 +1565,7 @@ export default class MetamaskController extends EventEmitter {
'UserStorageController:performSetStorage',
'NotificationServicesPushController:enablePushNotifications',
'NotificationServicesPushController:disablePushNotifications',
'NotificationServicesPushController:subscribeToPushNotifications',
'NotificationServicesPushController:updateTriggerPushNotifications',
],
allowedEvents: [
Expand Down
20 changes: 2 additions & 18 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1903,9 +1903,9 @@
"removeEventListener": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/controller-utils": true,
"@metamask/notification-services-controller>@contentful/rich-text-html-renderer": true,
"@metamask/notification-services-controller>@metamask/base-controller": true,
"@metamask/notification-services-controller>firebase": true,
"@metamask/profile-sync-controller": true,
"bignumber.js": true,
Expand All @@ -1918,14 +1918,6 @@
"SuppressedError": true
}
},
"@metamask/notification-services-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/notification-services-controller>firebase": {
"packages": {
"@metamask/notification-services-controller>firebase>@firebase/app": true,
Expand Down Expand Up @@ -2289,22 +2281,14 @@
"setTimeout": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/message-signing-snap>@noble/ciphers": true,
"@metamask/profile-sync-controller>@metamask/base-controller": true,
"@metamask/profile-sync-controller>siwe": true,
"@noble/hashes": true,
"browserify>buffer": true,
"loglevel": true
}
},
"@metamask/profile-sync-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/profile-sync-controller>siwe": {
"globals": {
"console.error": true,
Expand Down
20 changes: 2 additions & 18 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1903,9 +1903,9 @@
"removeEventListener": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/controller-utils": true,
"@metamask/notification-services-controller>@contentful/rich-text-html-renderer": true,
"@metamask/notification-services-controller>@metamask/base-controller": true,
"@metamask/notification-services-controller>firebase": true,
"@metamask/profile-sync-controller": true,
"bignumber.js": true,
Expand All @@ -1918,14 +1918,6 @@
"SuppressedError": true
}
},
"@metamask/notification-services-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/notification-services-controller>firebase": {
"packages": {
"@metamask/notification-services-controller>firebase>@firebase/app": true,
Expand Down Expand Up @@ -2289,22 +2281,14 @@
"setTimeout": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/message-signing-snap>@noble/ciphers": true,
"@metamask/profile-sync-controller>@metamask/base-controller": true,
"@metamask/profile-sync-controller>siwe": true,
"@noble/hashes": true,
"browserify>buffer": true,
"loglevel": true
}
},
"@metamask/profile-sync-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/profile-sync-controller>siwe": {
"globals": {
"console.error": true,
Expand Down
20 changes: 2 additions & 18 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1903,9 +1903,9 @@
"removeEventListener": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/controller-utils": true,
"@metamask/notification-services-controller>@contentful/rich-text-html-renderer": true,
"@metamask/notification-services-controller>@metamask/base-controller": true,
"@metamask/notification-services-controller>firebase": true,
"@metamask/profile-sync-controller": true,
"bignumber.js": true,
Expand All @@ -1918,14 +1918,6 @@
"SuppressedError": true
}
},
"@metamask/notification-services-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/notification-services-controller>firebase": {
"packages": {
"@metamask/notification-services-controller>firebase>@firebase/app": true,
Expand Down Expand Up @@ -2289,22 +2281,14 @@
"setTimeout": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/message-signing-snap>@noble/ciphers": true,
"@metamask/profile-sync-controller>@metamask/base-controller": true,
"@metamask/profile-sync-controller>siwe": true,
"@noble/hashes": true,
"browserify>buffer": true,
"loglevel": true
}
},
"@metamask/profile-sync-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/profile-sync-controller>siwe": {
"globals": {
"console.error": true,
Expand Down
20 changes: 2 additions & 18 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,9 @@
"removeEventListener": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/controller-utils": true,
"@metamask/notification-services-controller>@contentful/rich-text-html-renderer": true,
"@metamask/notification-services-controller>@metamask/base-controller": true,
"@metamask/notification-services-controller>firebase": true,
"@metamask/profile-sync-controller": true,
"bignumber.js": true,
Expand All @@ -2010,14 +2010,6 @@
"SuppressedError": true
}
},
"@metamask/notification-services-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/notification-services-controller>firebase": {
"packages": {
"@metamask/notification-services-controller>firebase>@firebase/app": true,
Expand Down Expand Up @@ -2381,22 +2373,14 @@
"setTimeout": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/message-signing-snap>@noble/ciphers": true,
"@metamask/profile-sync-controller>@metamask/base-controller": true,
"@metamask/profile-sync-controller>siwe": true,
"@noble/hashes": true,
"browserify>buffer": true,
"loglevel": true
}
},
"@metamask/profile-sync-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/profile-sync-controller>siwe": {
"globals": {
"console.error": true,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,15 @@
"@metamask/name-controller": "^8.0.0",
"@metamask/network-controller": "patch:@metamask/network-controller@npm%3A20.2.0#~/.yarn/patches/@metamask-network-controller-npm-20.2.0-98b1a5ae59.patch",
"@metamask/notification-controller": "^6.0.0",
"@metamask/notification-services-controller": "^0.2.1",
"@metamask/notification-services-controller": "^0.5.0",
"@metamask/object-multiplex": "^2.0.0",
"@metamask/obs-store": "^9.0.0",
"@metamask/permission-controller": "^10.0.0",
"@metamask/permission-log-controller": "^2.0.1",
"@metamask/phishing-controller": "^12.0.1",
"@metamask/post-message-stream": "^8.0.0",
"@metamask/ppom-validator": "0.34.0",
"@metamask/profile-sync-controller": "^0.2.1",
"@metamask/profile-sync-controller": "^0.5.0",
"@metamask/providers": "^14.0.2",
"@metamask/queued-request-controller": "^2.0.0",
"@metamask/rate-limit-controller": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/mock-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ async function setupMocking(
});

// Notification APIs
mockNotificationServices(server);
await mockNotificationServices(server);

await server.forGet(/^https:\/\/sourcify.dev\/(.*)/u).thenCallback(() => {
return {
Expand Down
Loading

0 comments on commit c5cfd1c

Please sign in to comment.