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

fix: ensure push notifications are able to be subscribed to when the wallet is locked #4653

Merged
merged 10 commits into from
Sep 6, 2024

Conversation

matteoscurati
Copy link
Contributor

@matteoscurati matteoscurati commented Sep 4, 2024

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

  • ADDED: New method and allowed action NotificationServicesPushController:subscribeToPushNotifications to the NotificationServicesController.
  • CHANGED: Decoupled logic of creating new reg token and subscribing to push notifications in the NotificationServicesPushController enablePushNotifications() method.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@matteoscurati matteoscurati added the team-notifications Notification Team changes. https://github.com/orgs/MetaMask/teams/notifications label Sep 4, 2024
@matteoscurati matteoscurati requested a review from a team as a code owner September 4, 2024 14:09
@Prithpal-Sooriya
Copy link
Contributor

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:

  • persist firebase messaging object
  • try persisting everything?
  • can we jerryrig snaps to work when device is locked?

@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as draft September 4, 2024 21:01
@Prithpal-Sooriya Prithpal-Sooriya changed the title fix: 🐛 move the listener temp: test push notifications when wallet is locked Sep 5, 2024
@Prithpal-Sooriya Prithpal-Sooriya changed the title temp: test push notifications when wallet is locked fix: ensure push notifications are able to be subscribed to when the wallet is locked Sep 6, 2024
@Prithpal-Sooriya
Copy link
Contributor

Prithpal-Sooriya commented Sep 6, 2024

OK, tested this on extension. It seems that we now correctly subscribe to notifications when the wallet is locked or unlocked.
NOTE - Only when the wallet is unlocked can we send to our server any new registration tokens

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
@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as ready for review September 6, 2024 17:45
@Prithpal-Sooriya Prithpal-Sooriya merged commit 00d4a6f into main Sep 6, 2024
116 checks passed
@Prithpal-Sooriya Prithpal-Sooriya deleted the fix/push-notifications-fix-listener branch September 6, 2024 17:50
matteoscurati added a commit to MetaMask/metamask-extension that referenced this pull request Sep 13, 2024
<!--
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-notifications Notification Team changes. https://github.com/orgs/MetaMask/teams/notifications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants