-
-
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
Update NotificationServicesController
to accommodate for Snaps Notifications
#4809
base: main
Are you sure you want to change the base?
Conversation
…ommodate for snaps and updated NotificationServicesController tests
NotificationServicesController
to accommodate for Snaps NotificationsNotificationServicesController
to accommodate for Snaps Notifications & remove NotificationController
Removed dependencies detected. Learn more about Socket for GitHub ↗︎ 🚮 Removed packages: npm/@metamask/utils@9.2.1 |
CODEOWNER reviews are being triggered because I used the latest version of EDIT: Split the bumps into a different PR |
NotificationServicesController
to accommodate for Snaps Notifications & remove NotificationController
NotificationServicesController
to accommodate for Snaps Notifications
There was a problem hiding this 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.
const snapNotifications = this.state.metamaskNotificationsList.filter( | ||
(notification) => notification.type === TRIGGER_TYPES.SNAP, | ||
); |
There was a problem hiding this comment.
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?
- We take the prev state
this.state.metamaskNotificationsList
and grab the snap notifications - We reinsert it back into the notification list below.
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
...ion-services-controller/src/NotificationServicesController/NotificationServicesController.ts
Show resolved
Hide resolved
...ion-services-controller/src/NotificationServicesController/NotificationServicesController.ts
Show resolved
Hide resolved
...ion-services-controller/src/NotificationServicesController/NotificationServicesController.ts
Show resolved
Hide resolved
...ion-services-controller/src/NotificationServicesController/NotificationServicesController.ts
Show resolved
Hide resolved
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
Explanation
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.NotificationServicesController
updateMetamaskNotificationsList
function will be the gateway for snaps to add notifications to the controller.Changelog
@metamask/notification-services-controller
getNotificationsByType
to grab a list of notifications by type.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).fetchAndUpdateMetamaskNotifications
to grab snaps from state before repopulating with a new list of other notifications.markNotificaftionsAsRead
to account for snaps notifications.updateMetamaskNotificationsList
to assign a processed notification to state instead of the originally passed in notification as theprocessSnapNotification
function adds on extra properties to the raw notification.Checklist