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

Update NotificationServicesController to accommodate for Snaps Notifications #4809

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

hmalik88
Copy link
Contributor

@hmalik88 hmalik88 commented Oct 17, 2024

Explanation

  • What is the current state of things and why does it need to change? We currently have snap types living in the extension, which should exist in this repo instead. Also, the extension is using two controllers to handle notifications, the NotificationController solely exists for the purpose of snap notifications. With the revamping of the notifications system, it is best to house all notifications in one place.
  • What is the solution your changes offer and how does it work? Add snap logic to the NotificationServicesController
  • Are there any changes whose purpose might not obvious to those unfamiliar with the domain? The updateMetamaskNotificationsList function will be the gateway for snaps to add notifications to the controller.

Changelog

@metamask/notification-services-controller

  • ADDED: getNotificationsByType to grab a list of notifications by type.
  • ADDED: deleteNotificationById to delete a notification in the controller's state (to be only used by notifications that live in this controller which currently is just snaps).
  • CHANGED: fetchAndUpdateMetamaskNotifications to grab snaps from state before repopulating with a new list of other notifications.
  • CHANGED: markNotificaftionsAsRead to account for snaps notifications.
  • CHANGED: updateMetamaskNotificationsList to assign a processed notification to state instead of the originally passed in notification as the processSnapNotification function adds on extra properties to the raw notification.

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
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@hmalik88 hmalik88 requested a review from a team as a code owner October 17, 2024 17:50
@hmalik88 hmalik88 requested review from a team as code owners October 17, 2024 18:04
@hmalik88 hmalik88 requested review from a team as code owners October 17, 2024 18:23
@hmalik88 hmalik88 changed the title Update NotificationServicesController to accommodate for Snaps Notifications Update NotificationServicesController to accommodate for Snaps Notifications & remove NotificationController Oct 17, 2024
Copy link

socket-security bot commented Oct 17, 2024

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: npm/@metamask/utils@9.2.1

View full report↗︎

@hmalik88
Copy link
Contributor Author

hmalik88 commented Oct 17, 2024

CODEOWNER reviews are being triggered because I used the latest version of @metamask/utils in the NotificationServicesController and was required to update the rest of the packages as well to be in parity. There are no breaking changes from 9.1.0 -> 9.3.0

EDIT: Split the bumps into a different PR

@hmalik88 hmalik88 changed the title Update NotificationServicesController to accommodate for Snaps Notifications & remove NotificationController Update NotificationServicesController to accommodate for Snaps Notifications Oct 17, 2024
Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some initial comments.

I think we can move forward with this after our sync session.

Comment on lines +1129 to +1131
const snapNotifications = this.state.metamaskNotificationsList.filter(
(notification) => notification.type === TRIGGER_TYPES.SNAP,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is so we don't overwrite and lose snap notifications correct?

  1. We take the prev state this.state.metamaskNotificationsList and grab the snap notifications
  2. We reinsert it back into the notification list below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!

@@ -24,6 +24,7 @@ export enum TRIGGER_TYPES {
ROCKETPOOL_STAKING_REWARDS = 'rocketpool_staking_rewards',
NOTIONAL_LOAN_EXPIRATION = 'notional_loan_expiration',
SPARK_FI_HEALTH_FACTOR = 'spark_fi_health_factor',
SNAP = 'snap',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree with this change.

Currently all of these notifications types are notifications coming from our services, we need to see if this doesn't cause issues with our backend calls (create notifications, update notifications, update push links, etc).

I think we are save as the Sets and Data Structures below are responsible for main core logic.

snapNotificationIds = snapNotifications.map(
(notification) => notification.id,
);
}
} catch (err) {
log.warn('Something failed when marking notifications as read', err);
}

// Update the state (state is also used on counter & badge)
this.update((state) => {
const currentReadList = state.metamaskNotificationsReadList;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matteoscurati it's been a while, but what was the purpose of the "read list" when we have the "notification list" below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same, good question!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

2 participants