-
-
Notifications
You must be signed in to change notification settings - Fork 184
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: ensure push notifications are able to be subscribed to when the wallet is locked #4653
Conversation
...ices-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts
Outdated
Show resolved
Hide resolved
Gosh, testing in extension. There are some issues related to push notifications when the wallet is locked. Because we rely on snaps for auth, and snaps can't be called when the wallet is locked, we are unable to authenticate whilst locked. Due to this we can't send any registration token updates to our server. So push notifications eventually fail when the wallet is locked. Also, for some odd reason, when the extension is refreshed the existing registration token becomes invalid and push notifications stop working. Yeah a few things we need to iron out during these flows... Things to try:
|
…Mask/core into fix/push-notifications-fix-listener
OK, tested this on extension. It seems that we now correctly subscribe to notifications when the wallet is locked or unlocked. |
specifically the services file. It seems we were using a lot of mocks here, so replaced them with nock for a more true to like fetch experience
...ication-services-controller/src/NotificationServicesPushController/services/services.test.ts
Show resolved
Hide resolved
<!-- 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.
Explanation
Push notifications currently are only able to be subscribed to when the wallet is unlocked on initialisation. So if a user closes and re-opens a browser, they will not attach the push subscription, and thus will receive silent push notifications.
We now add an additional method that allows us to decouple the authenticated methods (create new registration token and send to server), which can only be done when the wallet is locked, from the subscription methods (which subscribe to the push listener).
Now users who had closed their browser and re-opened will ensure that they receive the correct notification and not a silent notification.
References
Changelog
@metamask/notification-services-controller
NotificationServicesPushController:subscribeToPushNotifications
to theNotificationServicesController
.NotificationServicesPushController
enablePushNotifications()
method.Checklist