-
-
Notifications
You must be signed in to change notification settings - Fork 256
feat: migration notification API from v2 to v3 #7102
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
feat: migration notification API from v2 to v3 #7102
Conversation
this is a large notification architecture API change but offers dynamic platform notifications
|
@metamaskbot publish-preview |
| mockGetOnChainNotificationsConfig, | ||
| mockUpdateOnChainNotifications, | ||
| mockGetOnChainNotifications, | ||
| mockGetAPINotifications, |
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.
renamed mock util
| env: { | ||
| featureAnnouncements: FeatureAnnouncementEnv; | ||
| isPushIntegrated?: boolean; | ||
| locale?: () => string; |
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.
We now pass in locale to handle server side in-app platform notifications
...ion-services-controller/src/NotificationServicesController/NotificationServicesController.ts
Outdated
Show resolved
Hide resolved
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
| } | ||
|
|
||
| export const TRIGGER_TYPES_WALLET_SET: Set<string> = new Set([ | ||
| export const NOTIFICATION_API_TRIGGER_TYPES_SET: Set<string> = new Set([ |
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.
Update set and add new types supported by our API
| TRIGGER_TYPES.ERC1155_RECEIVED, | ||
| ]) satisfies Set<Exclude<TRIGGER_TYPES, TRIGGER_TYPES.FEATURES_ANNOUNCEMENT>>; | ||
|
|
||
| export enum TRIGGER_TYPES_GROUPS { |
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.
never used, removed
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.
API returns new data shapes, so mocks needed updating
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.
Added mock Platform Notification shape.
| * @param notification - API Notification (On-Chain or Platform Notification) | ||
| * @returns Normalized Notification | ||
| */ | ||
| export function processAPINotifications( |
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.
New process to handle our API notifications (wallet notifs and platform notifs).
Replaces the old processOnChainNotifications.
Also added an auto-expire to expire old notifications (30 days).
| /** | ||
| * This file was auto-generated by openapi-typescript. | ||
| * Do not make direct changes to the file. | ||
| * Script: `npx openapi-typescript <PATH TO NOTIFICATION API SPEC> -o ./schema.d.ts` |
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.
new schema generated from our open-api spec
| const tokenDecimals = n?.data?.token?.decimals; | ||
| const symbol = n?.payload?.data?.token?.symbol; | ||
| const tokenAmount = n?.payload?.data?.token?.amount; | ||
| const tokenDecimals = n?.payload?.data?.token?.decimals; |
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.
Shape has changed, we now have a payload object that contains these properties.
...ces-controller/src/NotificationServicesController/types/notification-api/notification-api.ts
Show resolved
Hide resolved
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.
Bug: Platform Notifications Silently Dropped
The createOnChainPushNotificationMessage function doesn't handle platform notifications. When a platform notification (with type: 'platform') is passed to this function, it returns null because TRIGGER_TYPES.PLATFORM isn't included in the createOnChainPushNotificationMessages dictionary. Platform notifications have a template field with localized content instead of payload.data, but the function doesn't check for or use this field. This means platform notifications won't generate push notification messages, potentially causing them to be silently dropped in the push notification flow.
packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.ts#L255-L276
Lines 255 to 276 in 3b4c69e
| */ | |
| export function createOnChainPushNotificationMessage( | |
| n: Types.INotification, | |
| translations: TranslationKeys, | |
| ): PushNotificationMessage | null { | |
| if (!n?.type) { | |
| return null; | |
| } | |
| const notificationMessage = | |
| createOnChainPushNotificationMessages(translations)[n.type]; | |
| if (!notificationMessage) { | |
| return null; | |
| } | |
| let description: string | null = null; | |
| try { | |
| description = | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| notificationMessage?.getDescription?.(n as any) ?? | |
| notificationMessage.defaultDescription ?? | |
| null; |
...ces-controller/src/NotificationServicesController/types/notification-api/notification-api.ts
Show resolved
Hide resolved
allows us to filter server side different notifications for each platform
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
Explanation
This is a large notification architecture API change but offers dynamic platform notifications
Details
Devlog: https://www.loom.com/share/ea5fc1457c224b2988fadacbfc21ca2a
Extension Preview: MetaMask/metamask-extension#37709
Mobile Preview: MetaMask/metamask-mobile#22539
References
https://consensyssoftware.atlassian.net/browse/ASSETS-1301
Checklist
Note
Migrates notifications to the v3 API with unified on-chain/platform notifications, locale-aware fetching, and updated controller/types/push logic.
/api/v3/notificationsand/api/v3/notifications/mark-as-read.{ addresses: string[], locale: string, platform: 'extension'|'mobile' }; config query unchanged; mark-as-read body{ ids }.NormalisedAPINotification(union of on-chain + platform) andUnprocessedRawNotification.TRIGGER_TYPES.PLATFORM; update trigger type set and constants.toRawOnChainNotificationwithtoRawAPINotification; removeprocess-onchain-notificationsin favor ofprocessAPINotifications.onchain-notificationstoapi-notifications(getAPINotifications,getNotificationsApiConfigCached,markNotificationsAsRead).payload.Written by Cursor Bugbot for commit 3562e62. This will update automatically on new commits. Configure here.