@metamask-previews/notification-services-controller 18.1.0-preview-f059664 → 18.1.0-preview-8ccfcb37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (18) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  3. package/dist/NotificationServicesController/NotificationServicesController.d.cts +1 -0
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  5. package/dist/NotificationServicesController/NotificationServicesController.d.mts +1 -0
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  7. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  8. package/dist/NotificationServicesController/processors/process-notifications.d.cts +21 -21
  9. package/dist/NotificationServicesController/processors/process-notifications.d.mts +21 -21
  10. package/dist/NotificationServicesController/services/feature-announcements.cjs +19 -1
  11. package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
  12. package/dist/NotificationServicesController/services/feature-announcements.d.cts +2 -1
  13. package/dist/NotificationServicesController/services/feature-announcements.d.cts.map +1 -1
  14. package/dist/NotificationServicesController/services/feature-announcements.d.mts +2 -1
  15. package/dist/NotificationServicesController/services/feature-announcements.d.mts.map +1 -1
  16. package/dist/NotificationServicesController/services/feature-announcements.mjs +19 -1
  17. package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
  18. package/package.json +3 -1
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesController.mjs","sourceRoot":"","sources":["../../src/NotificationServicesController/NotificationServicesController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACrB,mCAAmC;AACpC,OAAO,EAKL,YAAY,EAEb,qCAAqC;AAEtC,OAAO,EAAE,MAAM,EAAE,wBAAwB;AACzC,OAAO,IAAG,iBAAiB;;AAE3B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AC5C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,KAAK,CAAC,sCAAsC;YAC1C,KAAK,CAAC,sCAAsC,CAAC,MAAM,CACjD,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,CACzD,CAAC;IACN,CAAC,CAAC,CAAC;AACL,CAAC;eA5ZkB,8BAA8B","sourcesContent":["import type {\n RestrictedMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n isValidHexAddress,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport {\n type KeyringControllerStateChangeEvent,\n type KeyringControllerGetStateAction,\n type KeyringControllerLockEvent,\n type KeyringControllerUnlockEvent,\n KeyringTypes,\n type KeyringControllerState,\n} from '@metamask/keyring-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport { assert } from '@metamask/utils';\nimport log from 'loglevel';\n\nimport { TRIGGER_TYPES } from './constants/notification-schema';\nimport {\n processAndFilterNotifications,\n safeProcessNotification,\n} from './processors/process-notifications';\nimport * as FeatureNotifications from './services/feature-announcements';\nimport * as OnChainNotifications from './services/onchain-notifications';\nimport { createPerpOrderNotification } from './services/perp-notifications';\nimport type {\n INotification,\n MarkAsReadNotificationsParam,\n} from './types/notification/notification';\nimport type { OnChainRawNotification } from './types/on-chain-notification/on-chain-notification';\nimport type { OrderInput } from './types/perps';\nimport type {\n NotificationServicesPushControllerEnablePushNotificationsAction,\n NotificationServicesPushControllerDisablePushNotificationsAction,\n NotificationServicesPushControllerSubscribeToNotificationsAction,\n NotificationServicesPushControllerStateChangeEvent,\n NotificationServicesPushControllerOnNewNotificationEvent,\n} from '../NotificationServicesPushController';\n\n// Unique name for the controller\nconst controllerName = 'NotificationServicesController';\n\n/**\n * State shape for NotificationServicesController\n */\nexport type NotificationServicesControllerState = {\n /**\n * We store and manage accounts that have been seen/visted through the\n * account subscription. This allows us to track and add notifications for new accounts and not previous accounts added.\n */\n subscriptionAccountsSeen: string[];\n\n /**\n * Flag that indicates if the metamask notifications feature has been seen\n */\n isMetamaskNotificationsFeatureSeen: boolean;\n\n /**\n * Flag that indicates if the metamask notifications are enabled\n */\n isNotificationServicesEnabled: boolean;\n\n /**\n * Flag that indicates if the feature announcements are enabled\n */\n isFeatureAnnouncementsEnabled: boolean;\n\n /**\n * List of metamask notifications\n */\n metamaskNotificationsList: INotification[];\n\n /**\n * List of read metamask notifications\n */\n metamaskNotificationsReadList: string[];\n /**\n * Flag that indicates that the creating notifications is in progress\n */\n isUpdatingMetamaskNotifications: boolean;\n /**\n * Flag that indicates that the fetching notifications is in progress\n * This is used to show a loading spinner in the UI\n * when fetching notifications\n */\n isFetchingMetamaskNotifications: boolean;\n /**\n * Flag that indicates that the updating notifications for a specific address is in progress\n */\n isUpdatingMetamaskNotificationsAccount: string[];\n /**\n * Flag that indicates that the checking accounts presence is in progress\n */\n isCheckingAccountsPresence: boolean;\n};\n\nconst metadata: StateMetadata<NotificationServicesControllerState> = {\n subscriptionAccountsSeen: {\n includeInStateLogs: true,\n persist: true,\n anonymous: true,\n usedInUi: true,\n },\n\n isMetamaskNotificationsFeatureSeen: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n isNotificationServicesEnabled: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n isFeatureAnnouncementsEnabled: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n metamaskNotificationsList: {\n includeInStateLogs: true,\n persist: true,\n anonymous: true,\n usedInUi: true,\n },\n metamaskNotificationsReadList: {\n includeInStateLogs: false,\n persist: true,\n anonymous: true,\n usedInUi: true,\n },\n isUpdatingMetamaskNotifications: {\n includeInStateLogs: false,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n isFetchingMetamaskNotifications: {\n includeInStateLogs: false,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n isUpdatingMetamaskNotificationsAccount: {\n includeInStateLogs: false,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n isCheckingAccountsPresence: {\n includeInStateLogs: false,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n};\nexport const defaultState: NotificationServicesControllerState = {\n subscriptionAccountsSeen: [],\n isMetamaskNotificationsFeatureSeen: false,\n isNotificationServicesEnabled: false,\n isFeatureAnnouncementsEnabled: false,\n metamaskNotificationsList: [],\n metamaskNotificationsReadList: [],\n isUpdatingMetamaskNotifications: false,\n isFetchingMetamaskNotifications: false,\n isUpdatingMetamaskNotificationsAccount: [],\n isCheckingAccountsPresence: false,\n};\n\nconst locallyPersistedNotificationTypes = new Set<TRIGGER_TYPES>([\n TRIGGER_TYPES.SNAP,\n]);\n\nexport type NotificationServicesControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesControllerState\n >;\n\nexport type NotificationServicesControllerUpdateMetamaskNotificationsList = {\n type: `${typeof controllerName}:updateMetamaskNotificationsList`;\n handler: NotificationServicesController['updateMetamaskNotificationsList'];\n};\n\nexport type NotificationServicesControllerDisableNotificationServices = {\n type: `${typeof controllerName}:disableNotificationServices`;\n handler: NotificationServicesController['disableNotificationServices'];\n};\n\nexport type NotificationServicesControllerGetNotificationsByType = {\n type: `${typeof controllerName}:getNotificationsByType`;\n handler: NotificationServicesController['getNotificationsByType'];\n};\n\nexport type NotificationServicesControllerDeleteNotificationsById = {\n type: `${typeof controllerName}:deleteNotificationsById`;\n handler: NotificationServicesController['deleteNotificationsById'];\n};\n\n// Messenger Actions\nexport type Actions =\n | NotificationServicesControllerGetStateAction\n | NotificationServicesControllerUpdateMetamaskNotificationsList\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerGetNotificationsByType\n | NotificationServicesControllerDeleteNotificationsById;\n\n// Allowed Actions\nexport type AllowedActions =\n // Keyring Controller Requests\n | KeyringControllerGetStateAction\n // Auth Controller Requests\n | AuthenticationController.AuthenticationControllerGetBearerToken\n | AuthenticationController.AuthenticationControllerIsSignedIn\n | AuthenticationController.AuthenticationControllerPerformSignIn\n // Push Notifications Controller Requests\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerSubscribeToNotificationsAction;\n\n// Events\nexport type NotificationServicesControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesControllerState\n >;\n\nexport type NotificationListUpdatedEvent = {\n type: `${typeof controllerName}:notificationsListUpdated`;\n payload: [INotification[]];\n};\n\nexport type MarkNotificationsAsReadEvent = {\n type: `${typeof controllerName}:markNotificationsAsRead`;\n payload: [INotification[]];\n};\n\n// Events\nexport type Events =\n | NotificationServicesControllerStateChangeEvent\n | NotificationListUpdatedEvent\n | MarkNotificationsAsReadEvent;\n\n// Allowed Events\nexport type AllowedEvents =\n // Keyring Events\n | KeyringControllerStateChangeEvent\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n // Push Notification Events\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerStateChangeEvent;\n\n// Type for the messenger of NotificationServicesController\nexport type NotificationServicesControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\ntype FeatureAnnouncementEnv = {\n spaceId: string;\n accessToken: string;\n platform: 'extension' | 'mobile';\n};\n\n/**\n * Controller that enables wallet notifications and feature announcements\n */\nexport default class NotificationServicesController extends BaseController<\n typeof controllerName,\n NotificationServicesControllerState,\n NotificationServicesControllerMessenger\n> {\n readonly #keyringController = {\n isUnlocked: false,\n\n setupLockedStateSubscriptions: (onUnlock: () => Promise<void>) => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#keyringController.isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#keyringController.isUnlocked = true;\n // messaging system cannot await promises\n // we don't need to wait for a result on this.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n onUnlock();\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#keyringController.isUnlocked = false;\n });\n },\n };\n\n readonly #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n isSignedIn: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n };\n\n readonly #pushNotifications = {\n // Flag to check is notifications have been setup when the browser/extension is initialized.\n // We want to re-initialize push notifications when the browser/extension is refreshed\n // To ensure we subscribe to the most up-to-date notifications\n isSetup: false,\n\n subscribeToPushNotifications: async () => {\n await this.messagingSystem.call(\n 'NotificationServicesPushController:subscribeToPushNotifications',\n );\n },\n enablePushNotifications: async (addresses: string[]) => {\n try {\n await this.messagingSystem.call(\n 'NotificationServicesPushController:enablePushNotifications',\n addresses,\n );\n } catch (e) {\n log.error('Silently failed to enable push notifications', e);\n }\n },\n disablePushNotifications: async () => {\n try {\n await this.messagingSystem.call(\n 'NotificationServicesPushController:disablePushNotifications',\n );\n } catch (e) {\n log.error('Silently failed to disable push notifications', e);\n }\n },\n subscribe: () => {\n this.messagingSystem.subscribe(\n 'NotificationServicesPushController:onNewNotifications',\n (notification) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.updateMetamaskNotificationsList(notification);\n },\n );\n },\n initializePushNotifications: async () => {\n if (!this.state.isNotificationServicesEnabled) {\n return;\n }\n if (this.#pushNotifications.isSetup) {\n return;\n }\n\n // If wallet is unlocked, we can create a fresh push subscription\n // Otherwise we can subscribe to original subscription\n try {\n if (!this.#keyringController.isUnlocked) {\n throw new Error('Keyring is locked');\n }\n await this.enablePushNotifications();\n this.#pushNotifications.isSetup = true;\n } catch {\n await this.#pushNotifications\n .subscribeToPushNotifications()\n .catch(() => {\n // do nothing\n });\n }\n },\n };\n\n readonly #accounts = {\n // Flag to ensure we only setup once\n isNotificationAccountsSetup: false,\n\n getNotificationAccounts: () => {\n const { keyrings } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n const firstHDKeyring = keyrings.find(\n (k) => k.type === KeyringTypes.hd.toString(),\n );\n const keyringAccounts = firstHDKeyring?.accounts ?? null;\n return keyringAccounts;\n },\n\n /**\n * Used to get list of addresses from keyring (wallet addresses)\n *\n * @returns addresses removed, added, and latest list of addresses\n */\n listAccounts: () => {\n // Get previous and current account sets\n const nonChecksumAccounts = this.#accounts.getNotificationAccounts();\n if (!nonChecksumAccounts) {\n return {\n accountsAdded: [],\n accountsRemoved: [],\n accounts: [],\n };\n }\n\n const accounts = nonChecksumAccounts\n .map((a) => toChecksumHexAddress(a))\n .filter((a) => isValidHexAddress(a));\n const currentAccountsSet = new Set(accounts);\n const prevAccountsSet = new Set(this.state.subscriptionAccountsSeen);\n\n // Invalid value you cannot have zero accounts\n // Only occurs when the Accounts controller is initializing.\n if (accounts.length === 0) {\n return {\n accountsAdded: [],\n accountsRemoved: [],\n accounts: [],\n };\n }\n\n // Calculate added and removed addresses\n const accountsAdded = accounts.filter((a) => !prevAccountsSet.has(a));\n const accountsRemoved = [...prevAccountsSet.values()].filter(\n (a) => !currentAccountsSet.has(a),\n );\n\n // Update accounts seen\n this.update((state) => {\n state.subscriptionAccountsSeen = [...currentAccountsSet];\n });\n\n return {\n accountsAdded,\n accountsRemoved,\n accounts,\n };\n },\n\n /**\n * Initializes the cache/previous list. This is handy so we have an accurate in-mem state of the previous list of accounts.\n */\n initialize: (): void => {\n if (\n this.#keyringController.isUnlocked &&\n !this.#accounts.isNotificationAccountsSetup\n ) {\n this.#accounts.listAccounts();\n this.#accounts.isNotificationAccountsSetup = true;\n }\n },\n\n /**\n * Subscription to any state change in the keyring controller (aka wallet accounts).\n * We can call the `listAccounts` defined above to find out about any accounts added, removed\n * And call effects to subscribe/unsubscribe to notifications.\n */\n subscribe: () => {\n this.messagingSystem.subscribe(\n 'KeyringController:stateChange',\n\n async (totalAccounts, prevTotalAccounts) => {\n const hasTotalAccountsChanged = totalAccounts !== prevTotalAccounts;\n if (\n !this.state.isNotificationServicesEnabled ||\n !hasTotalAccountsChanged\n ) {\n return;\n }\n\n const { accountsAdded, accountsRemoved } =\n this.#accounts.listAccounts();\n\n const promises: Promise<unknown>[] = [];\n if (accountsAdded.length > 0) {\n promises.push(this.enableAccounts(accountsAdded));\n }\n if (accountsRemoved.length > 0) {\n promises.push(this.disableAccounts(accountsRemoved));\n }\n await Promise.allSettled(promises);\n },\n (state: KeyringControllerState) => {\n return (\n state?.keyrings?.flatMap?.((keyring) => keyring.accounts)?.length ??\n 0\n );\n },\n );\n },\n };\n\n readonly #featureAnnouncementEnv: FeatureAnnouncementEnv;\n\n /**\n * Creates a NotificationServicesController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n * @param args.env - environment variables for a given controller.\n * @param args.env.featureAnnouncements - env variables for feature announcements.\n * @param args.env.isPushIntegrated - toggle push notifications on/off if client has integrated them.\n */\n constructor({\n messenger,\n state,\n env,\n }: {\n messenger: NotificationServicesControllerMessenger;\n state?: Partial<NotificationServicesControllerState>;\n env: {\n featureAnnouncements: FeatureAnnouncementEnv;\n isPushIntegrated?: boolean;\n };\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#featureAnnouncementEnv = env.featureAnnouncements;\n this.#registerMessageHandlers();\n this.#clearLoadingStates();\n }\n\n init() {\n this.#keyringController.setupLockedStateSubscriptions(async () => {\n this.#accounts.initialize();\n await this.#pushNotifications.initializePushNotifications();\n });\n\n this.#accounts.initialize();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#pushNotifications.initializePushNotifications();\n this.#accounts.subscribe();\n this.#pushNotifications.subscribe();\n }\n\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateMetamaskNotificationsList`,\n this.updateMetamaskNotificationsList.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:disableNotificationServices`,\n this.disableNotificationServices.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getNotificationsByType`,\n this.getNotificationsByType.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:deleteNotificationsById`,\n this.deleteNotificationsById.bind(this),\n );\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingMetamaskNotifications = false;\n state.isCheckingAccountsPresence = false;\n state.isFetchingMetamaskNotifications = false;\n state.isUpdatingMetamaskNotificationsAccount = [];\n });\n }\n\n #assertAuthEnabled() {\n if (!this.#auth.isSignedIn()) {\n this.update((state) => {\n state.isNotificationServicesEnabled = false;\n });\n throw new Error('User is not signed in.');\n }\n }\n\n async #enableAuth() {\n const isSignedIn = this.#auth.isSignedIn();\n if (!isSignedIn) {\n await this.#auth.signIn();\n }\n }\n\n async #getBearerToken() {\n this.#assertAuthEnabled();\n\n const bearerToken = await this.#auth.getBearerToken();\n\n if (!bearerToken) {\n throw new Error('Missing BearerToken');\n }\n\n return { bearerToken };\n }\n\n /**\n * Sets the state of notification creation process.\n *\n * This method updates the `isUpdatingMetamaskNotifications` state, which can be used to indicate\n * whether the notification creation process is currently active or not. This is useful\n * for UI elements that need to reflect the state of ongoing operations, such as loading\n * indicators or disabled buttons during processing.\n *\n * @param isUpdatingMetamaskNotifications - A boolean value representing the new state of the notification creation process.\n */\n #setIsUpdatingMetamaskNotifications(\n isUpdatingMetamaskNotifications: boolean,\n ) {\n this.update((state) => {\n state.isUpdatingMetamaskNotifications = isUpdatingMetamaskNotifications;\n });\n }\n\n /**\n * Updates the state to indicate whether fetching of MetaMask notifications is in progress.\n *\n * This method is used to set the `isFetchingMetamaskNotifications` state, which can be utilized\n * to show or hide loading indicators in the UI when notifications are being fetched.\n *\n * @param isFetchingMetamaskNotifications - A boolean value representing the fetching state.\n */\n #setIsFetchingMetamaskNotifications(\n isFetchingMetamaskNotifications: boolean,\n ) {\n this.update((state) => {\n state.isFetchingMetamaskNotifications = isFetchingMetamaskNotifications;\n });\n }\n\n /**\n * Updates the state to indicate that the checking of accounts presence is in progress.\n *\n * This method modifies the `isCheckingAccountsPresence` state, which can be used to manage UI elements\n * that depend on the status of account presence checks, such as displaying loading indicators or disabling\n * buttons while the check is ongoing.\n *\n * @param isCheckingAccountsPresence - A boolean value indicating whether the account presence check is currently active.\n */\n #setIsCheckingAccountsPresence(isCheckingAccountsPresence: boolean) {\n this.update((state) => {\n state.isCheckingAccountsPresence = isCheckingAccountsPresence;\n });\n }\n\n /**\n * Updates the state to indicate that account updates are in progress.\n * Removes duplicate accounts before updating the state.\n *\n * @param accounts - The accounts being updated.\n */\n #updateUpdatingAccountsState(accounts: string[]) {\n this.update((state) => {\n const uniqueAccounts = new Set([\n ...state.isUpdatingMetamaskNotificationsAccount,\n ...accounts,\n ]);\n state.isUpdatingMetamaskNotificationsAccount = Array.from(uniqueAccounts);\n });\n }\n\n /**\n * Clears the state indicating that account updates are complete.\n *\n * @param accounts - The accounts that have finished updating.\n */\n #clearUpdatingAccountsState(accounts: string[]) {\n this.update((state) => {\n state.isUpdatingMetamaskNotificationsAccount =\n state.isUpdatingMetamaskNotificationsAccount.filter(\n (existingAccount) => !accounts.includes(existingAccount),\n );\n });\n }\n\n /**\n * Public method to expose enabling push notifications\n */\n public async enablePushNotifications() {\n try {\n const { bearerToken } = await this.#getBearerToken();\n const { accounts } = this.#accounts.listAccounts();\n const addressesWithNotifications =\n await OnChainNotifications.getOnChainNotificationsConfigCached(\n bearerToken,\n accounts,\n );\n const addresses = addressesWithNotifications\n .filter((a) => Boolean(a.enabled))\n .map((a) => a.address);\n if (addresses.length > 0) {\n await this.#pushNotifications.enablePushNotifications(addresses);\n }\n } catch (e) {\n log.error('Failed to enable push notifications', e);\n }\n }\n\n /**\n * Public method to expose disabling push notifications\n */\n public async disablePushNotifications() {\n await this.#pushNotifications.disablePushNotifications();\n }\n\n public async checkAccountsPresence(\n accounts: string[],\n ): Promise<Record<string, boolean>> {\n try {\n this.#setIsCheckingAccountsPresence(true);\n\n // Retrieve user storage\n const { bearerToken } = await this.#getBearerToken();\n const addressesWithNotifications =\n await OnChainNotifications.getOnChainNotificationsConfigCached(\n bearerToken,\n accounts,\n );\n\n const result: Record<string, boolean> = {};\n addressesWithNotifications.forEach((a) => {\n result[a.address] = a.enabled;\n });\n return result;\n } catch (error) {\n log.error('Failed to check accounts presence', error);\n throw error;\n } finally {\n this.#setIsCheckingAccountsPresence(false);\n }\n }\n\n /**\n * Sets the enabled state of feature announcements.\n *\n * **Action** - used in the notification settings to enable/disable feature announcements.\n *\n * @param featureAnnouncementsEnabled - A boolean value indicating the desired enabled state of the feature announcements.\n * @async\n * @throws {Error} If fails to update\n */\n public async setFeatureAnnouncementsEnabled(\n featureAnnouncementsEnabled: boolean,\n ) {\n try {\n this.update((s) => {\n s.isFeatureAnnouncementsEnabled = featureAnnouncementsEnabled;\n });\n } catch (e) {\n log.error('Unable to toggle feature announcements', e);\n throw new Error('Unable to toggle feature announcements');\n }\n }\n\n /**\n * This creates/re-creates on-chain triggers defined in User Storage.\n *\n * **Action** - Used during Sign In / Enabling of notifications.\n *\n * @param opts - optional options to mutate this functionality\n * @param opts.resetNotifications - this will not use the users stored preferences, and instead re-create notification triggers\n * It will help in case uses get into a corrupted state or wants to wipe their notifications.\n * @returns The updated or newly created user storage.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async createOnChainTriggers(opts?: {\n resetNotifications?: boolean;\n }): Promise<void> {\n try {\n this.#setIsUpdatingMetamaskNotifications(true);\n\n const { bearerToken } = await this.#getBearerToken();\n\n const { accounts } = this.#accounts.listAccounts();\n\n // 1. See if has enabled notifications before\n const addressesWithNotifications =\n await OnChainNotifications.getOnChainNotificationsConfigCached(\n bearerToken,\n accounts,\n );\n\n // Notifications API can return array with addresses set to false\n // So assert that at least one address is enabled\n let accountsWithNotifications = addressesWithNotifications\n .filter((a) => Boolean(a.enabled))\n .map((a) => a.address);\n\n // 2. Enable Notifications (if no accounts subscribed or we are resetting)\n if (accountsWithNotifications.length === 0 || opts?.resetNotifications) {\n await OnChainNotifications.updateOnChainNotifications(\n bearerToken,\n accounts.map((address) => ({ address, enabled: true })),\n );\n accountsWithNotifications = accounts;\n }\n\n // 3. Lazily enable push notifications (FCM may take some time, so keeps UI unblocked)\n this.#pushNotifications\n .enablePushNotifications(accountsWithNotifications)\n .catch(() => {\n // Do Nothing\n });\n\n // Update the state of the controller\n this.update((state) => {\n state.isNotificationServicesEnabled = true;\n state.isFeatureAnnouncementsEnabled = true;\n state.isMetamaskNotificationsFeatureSeen = true;\n });\n } catch (err) {\n log.error('Failed to create On Chain triggers', err);\n throw new Error('Failed to create On Chain triggers');\n } finally {\n this.#setIsUpdatingMetamaskNotifications(false);\n }\n }\n\n /**\n * Enables all MetaMask notifications for the user.\n * This is identical flow when initializing notifications for the first time.\n *\n * @throws {Error} If there is an error during the process of enabling notifications.\n */\n public async enableMetamaskNotifications() {\n try {\n this.#setIsUpdatingMetamaskNotifications(true);\n await this.#enableAuth();\n await this.createOnChainTriggers();\n } catch (e) {\n log.error('Unable to enable notifications', e);\n throw new Error('Unable to enable notifications');\n } finally {\n this.#setIsUpdatingMetamaskNotifications(false);\n }\n }\n\n /**\n * Disables all MetaMask notifications for the user.\n * This method ensures that the user is authenticated, retrieves all linked accounts,\n * and disables on-chain triggers for each account. It also sets the global notification\n * settings for MetaMask, feature announcements to false.\n *\n * @throws {Error} If the user is not authenticated or if there is an error during the process.\n */\n public async disableNotificationServices() {\n this.#setIsUpdatingMetamaskNotifications(true);\n\n // Attempt Disable Push Notifications\n try {\n await this.#pushNotifications.disablePushNotifications();\n } catch {\n // Do nothing\n }\n\n // Update State: remove non-permitted notifications & disable flags\n const snapNotifications = this.state.metamaskNotificationsList.filter(\n (notification) => notification.type === TRIGGER_TYPES.SNAP,\n );\n this.update((state) => {\n state.isNotificationServicesEnabled = false;\n state.isFeatureAnnouncementsEnabled = false;\n // reassigning the notifications list with just snaps\n // since the disable shouldn't affect snaps notifications\n state.metamaskNotificationsList = snapNotifications;\n });\n\n // Finish Updating State\n this.#setIsUpdatingMetamaskNotifications(false);\n }\n\n /**\n * Deletes on-chain triggers associated with a specific account/s.\n * This method performs several key operations:\n * 1. Validates Auth\n * 2. Deletes accounts\n * (note) We do not need to look through push notifications as we've deleted triggers\n *\n * **Action** - When a user disables notifications for a given account in settings.\n *\n * @param accounts - The account for which on-chain triggers are to be deleted.\n * @returns A promise that resolves to void or an object containing a success message.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async disableAccounts(accounts: string[]): Promise<void> {\n try {\n this.#updateUpdatingAccountsState(accounts);\n // Get and Validate BearerToken and User Storage Key\n const { bearerToken } = await this.#getBearerToken();\n\n // Delete these UUIDs (Mutates User Storage)\n await OnChainNotifications.updateOnChainNotifications(\n bearerToken,\n accounts.map((address) => ({ address, enabled: false })),\n );\n } catch (err) {\n log.error('Failed to delete OnChain triggers', err);\n throw new Error('Failed to delete OnChain triggers');\n } finally {\n this.#clearUpdatingAccountsState(accounts);\n }\n }\n\n /**\n * Updates/Creates on-chain triggers for a specific account.\n *\n * This method performs several key operations:\n * 1. Validates Auth & Storage\n * 2. Finds and creates any missing triggers associated with the account\n * 3. Enables any related push notifications\n * 4. Updates Storage to reflect new state.\n *\n * **Action** - When a user enables notifications for an account\n *\n * @param accounts - List of accounts you want to update.\n * @returns A promise that resolves to the updated user storage.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async enableAccounts(accounts: string[]): Promise<void> {\n try {\n this.#updateUpdatingAccountsState(accounts);\n\n const { bearerToken } = await this.#getBearerToken();\n await OnChainNotifications.updateOnChainNotifications(\n bearerToken,\n accounts.map((address) => ({ address, enabled: true })),\n );\n } catch (err) {\n log.error('Failed to update OnChain triggers', err);\n throw new Error('Failed to update OnChain triggers');\n } finally {\n this.#clearUpdatingAccountsState(accounts);\n }\n }\n\n /**\n * Fetches the list of metamask notifications.\n * This includes OnChain notifications; Feature Announcements; and Snap Notifications.\n *\n * **Action** - When a user views the notification list page/dropdown\n *\n * @param previewToken - the preview token to use if needed\n * @returns A promise that resolves to the list of notifications.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async fetchAndUpdateMetamaskNotifications(\n previewToken?: string,\n ): Promise<INotification[]> {\n try {\n this.#setIsFetchingMetamaskNotifications(true);\n\n // This is used by Feature Announcement & On Chain\n // Not used by Snaps\n const isGlobalNotifsEnabled = this.state.isNotificationServicesEnabled;\n\n // Raw Feature Notifications\n const rawAnnouncements =\n isGlobalNotifsEnabled && this.state.isFeatureAnnouncementsEnabled\n ? await FeatureNotifications.getFeatureAnnouncementNotifications(\n this.#featureAnnouncementEnv,\n previewToken,\n ).catch(() => [])\n : [];\n\n // Raw On Chain Notifications\n const rawOnChainNotifications: OnChainRawNotification[] = [];\n if (isGlobalNotifsEnabled) {\n try {\n const { bearerToken } = await this.#getBearerToken();\n const { accounts } = this.#accounts.listAccounts();\n const addressesWithNotifications = (\n await OnChainNotifications.getOnChainNotificationsConfigCached(\n bearerToken,\n accounts,\n )\n )\n .filter((a) => Boolean(a.enabled))\n .map((a) => a.address);\n const notifications =\n await OnChainNotifications.getOnChainNotifications(\n bearerToken,\n addressesWithNotifications,\n ).catch(() => []);\n rawOnChainNotifications.push(...notifications);\n } catch {\n // Do nothing\n }\n }\n\n // Snap Notifications (original)\n // We do not want to remove them\n const snapNotifications = this.state.metamaskNotificationsList.filter(\n (notification) => notification.type === TRIGGER_TYPES.SNAP,\n );\n\n const readIds = this.state.metamaskNotificationsReadList;\n\n // Combine Notifications\n const metamaskNotifications: INotification[] = [\n ...processAndFilterNotifications(rawAnnouncements, readIds),\n ...processAndFilterNotifications(rawOnChainNotifications, readIds),\n ...snapNotifications,\n ];\n\n // Sort Notifications\n metamaskNotifications.sort(\n (a, b) =>\n new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),\n );\n\n // Update State\n this.update((state) => {\n state.metamaskNotificationsList = metamaskNotifications;\n });\n\n this.messagingSystem.publish(\n `${controllerName}:notificationsListUpdated`,\n this.state.metamaskNotificationsList,\n );\n\n this.#setIsFetchingMetamaskNotifications(false);\n return metamaskNotifications;\n } catch (err) {\n this.#setIsFetchingMetamaskNotifications(false);\n log.error('Failed to fetch notifications', err);\n throw new Error('Failed to fetch notifications');\n }\n }\n\n /**\n * Gets the specified type of notifications from state.\n *\n * @param type - The trigger type.\n * @returns An array of notifications of the passed in type.\n * @throws Throws an error if an invalid trigger type is passed.\n */\n public getNotificationsByType(type: TRIGGER_TYPES) {\n assert(\n Object.values(TRIGGER_TYPES).includes(type),\n 'Invalid trigger type.',\n );\n return this.state.metamaskNotificationsList.filter(\n (notification) => notification.type === type,\n );\n }\n\n /**\n * Used to delete a notification by id.\n *\n * Note: This function should only be used for notifications that are stored\n * in this controller directly, currently only snaps notifications.\n *\n * @param id - The id of the notification to delete.\n */\n public async deleteNotificationById(id: string) {\n const fetchedNotification = this.state.metamaskNotificationsList.find(\n (notification) => notification.id === id,\n );\n\n assert(\n fetchedNotification,\n 'The notification to be deleted does not exist.',\n );\n\n assert(\n locallyPersistedNotificationTypes.has(fetchedNotification.type),\n `The notification type of \"${\n // notifications are guaranteed to have type properties which equate to strings\n fetchedNotification.type as string\n }\" is not locally persisted, only the following types can use this function: ${[\n ...locallyPersistedNotificationTypes,\n ].join(', ')}.`,\n );\n\n const newList = this.state.metamaskNotificationsList.filter(\n (notification) => notification.id !== id,\n );\n\n this.update((state) => {\n state.metamaskNotificationsList = newList;\n });\n }\n\n /**\n * Used to batch delete notifications by id.\n *\n * Note: This function should only be used for notifications that are stored\n * in this controller directly, currently only snaps notifications.\n *\n * @param ids - The ids of the notifications to delete.\n */\n public async deleteNotificationsById(ids: string[]) {\n for (const id of ids) {\n await this.deleteNotificationById(id);\n }\n\n this.messagingSystem.publish(\n `${controllerName}:notificationsListUpdated`,\n this.state.metamaskNotificationsList,\n );\n }\n\n /**\n * Marks specified metamask notifications as read.\n *\n * @param notifications - An array of notifications to be marked as read. Each notification should include its type and read status.\n * @returns A promise that resolves when the operation is complete.\n */\n public async markMetamaskNotificationsAsRead(\n notifications: MarkAsReadNotificationsParam,\n ): Promise<void> {\n let onchainNotificationIds: string[] = [];\n let featureAnnouncementNotificationIds: string[] = [];\n let snapNotificationIds: string[] = [];\n\n try {\n const [\n onChainNotifications,\n featureAnnouncementNotifications,\n snapNotifications,\n ] = notifications.reduce<\n [\n MarkAsReadNotificationsParam,\n MarkAsReadNotificationsParam,\n MarkAsReadNotificationsParam,\n ]\n >(\n (allNotifications, notification) => {\n if (!notification.isRead) {\n switch (notification.type) {\n case TRIGGER_TYPES.FEATURES_ANNOUNCEMENT:\n allNotifications[1].push(notification);\n break;\n case TRIGGER_TYPES.SNAP:\n allNotifications[2].push(notification);\n break;\n default:\n allNotifications[0].push(notification);\n }\n }\n return allNotifications;\n },\n [[], [], []],\n );\n\n // Mark On-Chain Notifications as Read\n if (onChainNotifications.length > 0) {\n const bearerToken = await this.#auth.getBearerToken();\n\n if (bearerToken) {\n onchainNotificationIds = onChainNotifications.map(\n (notification) => notification.id,\n );\n await OnChainNotifications.markNotificationsAsRead(\n bearerToken,\n onchainNotificationIds,\n ).catch(() => {\n onchainNotificationIds = [];\n log.warn('Unable to mark onchain notifications as read');\n });\n }\n }\n\n // Mark Off-Chain notifications as Read\n if (featureAnnouncementNotifications.length > 0) {\n featureAnnouncementNotificationIds =\n featureAnnouncementNotifications.map(\n (notification) => notification.id,\n );\n }\n\n if (snapNotifications.length > 0) {\n snapNotificationIds = snapNotifications.map(\n (notification) => notification.id,\n );\n }\n } catch (err) {\n log.warn('Something failed when marking notifications as read', err);\n }\n\n // Update the state (state is also used on counter & badge)\n this.update((state) => {\n const currentReadList = state.metamaskNotificationsReadList;\n const newReadIds = [\n ...featureAnnouncementNotificationIds,\n ...snapNotificationIds,\n ];\n state.metamaskNotificationsReadList = [\n ...new Set([...currentReadList, ...newReadIds]),\n ];\n\n state.metamaskNotificationsList = state.metamaskNotificationsList.map(\n (notification: INotification) => {\n if (\n newReadIds.includes(notification.id) ||\n onchainNotificationIds.includes(notification.id)\n ) {\n if (notification.type === TRIGGER_TYPES.SNAP) {\n return {\n ...notification,\n isRead: true,\n readDate: new Date().toISOString(),\n };\n }\n return { ...notification, isRead: true };\n }\n return notification;\n },\n );\n });\n\n this.messagingSystem.publish(\n `${controllerName}:markNotificationsAsRead`,\n this.state.metamaskNotificationsList,\n );\n }\n\n /**\n * Updates the list of MetaMask notifications by adding a new notification at the beginning of the list.\n * This method ensures that the most recent notification is displayed first in the UI.\n *\n * @param notification - The new notification object to be added to the list.\n * @returns A promise that resolves when the notification list has been successfully updated.\n */\n public async updateMetamaskNotificationsList(\n notification: INotification,\n ): Promise<void> {\n if (\n this.state.metamaskNotificationsList.some((n) => n.id === notification.id)\n ) {\n return;\n }\n\n const processedNotification = safeProcessNotification(notification);\n\n if (processedNotification) {\n this.update((state) => {\n const existingNotificationIds = new Set(\n state.metamaskNotificationsList.map((n) => n.id),\n );\n // Add the new notification only if its ID is not already present in the list\n if (!existingNotificationIds.has(processedNotification.id)) {\n state.metamaskNotificationsList = [\n processedNotification,\n ...state.metamaskNotificationsList,\n ];\n }\n });\n\n this.messagingSystem.publish(\n `${controllerName}:notificationsListUpdated`,\n this.state.metamaskNotificationsList,\n );\n }\n }\n\n /**\n * Creates an perp order notification subscription.\n * Requires notifications and auth to be enabled to start receiving this notifications\n *\n * @param input perp input\n */\n public async sendPerpPlaceOrderNotification(input: OrderInput) {\n try {\n const { bearerToken } = await this.#getBearerToken();\n await createPerpOrderNotification(bearerToken, input);\n } catch {\n // Do Nothing\n }\n }\n}\n"]}
1
+ {"version":3,"file":"NotificationServicesController.mjs","sourceRoot":"","sources":["../../src/NotificationServicesController/NotificationServicesController.ts"],"names":[],"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AM,cAAc,GAAG,IAAI,GAAG,CAAC;YAC7B,GAAG,KAAK,CAAC,sCAAsC;YAC/C,GAAG,QAAQ;SACZ,CAAC,CAAC;QACH,KAAK,CAAC,sCAAsC,GAAG,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,mIAO2B,QAAkB;IAC5C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,KAAK,CAAC,sCAAsC;YAC1C,KAAK,CAAC,sCAAsC,CAAC,MAAM,CACjD,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,CACzD,CAAC;IACN,CAAC,CAAC,CAAC;AACL,CAAC;eA5ZkB,8BAA8B","sourcesContent":["import type {\n RestrictedMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n isValidHexAddress,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport {\n type KeyringControllerStateChangeEvent,\n type KeyringControllerGetStateAction,\n type KeyringControllerLockEvent,\n type KeyringControllerUnlockEvent,\n KeyringTypes,\n type KeyringControllerState,\n} from '@metamask/keyring-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport { assert } from '@metamask/utils';\nimport log from 'loglevel';\n\nimport { TRIGGER_TYPES } from './constants/notification-schema';\nimport {\n processAndFilterNotifications,\n safeProcessNotification,\n} from './processors/process-notifications';\nimport * as FeatureNotifications from './services/feature-announcements';\nimport * as OnChainNotifications from './services/onchain-notifications';\nimport { createPerpOrderNotification } from './services/perp-notifications';\nimport type {\n INotification,\n MarkAsReadNotificationsParam,\n} from './types/notification/notification';\nimport type { OnChainRawNotification } from './types/on-chain-notification/on-chain-notification';\nimport type { OrderInput } from './types/perps';\nimport type {\n NotificationServicesPushControllerEnablePushNotificationsAction,\n NotificationServicesPushControllerDisablePushNotificationsAction,\n NotificationServicesPushControllerSubscribeToNotificationsAction,\n NotificationServicesPushControllerStateChangeEvent,\n NotificationServicesPushControllerOnNewNotificationEvent,\n} from '../NotificationServicesPushController';\n\n// Unique name for the controller\nconst controllerName = 'NotificationServicesController';\n\n/**\n * State shape for NotificationServicesController\n */\nexport type NotificationServicesControllerState = {\n /**\n * We store and manage accounts that have been seen/visted through the\n * account subscription. This allows us to track and add notifications for new accounts and not previous accounts added.\n */\n subscriptionAccountsSeen: string[];\n\n /**\n * Flag that indicates if the metamask notifications feature has been seen\n */\n isMetamaskNotificationsFeatureSeen: boolean;\n\n /**\n * Flag that indicates if the metamask notifications are enabled\n */\n isNotificationServicesEnabled: boolean;\n\n /**\n * Flag that indicates if the feature announcements are enabled\n */\n isFeatureAnnouncementsEnabled: boolean;\n\n /**\n * List of metamask notifications\n */\n metamaskNotificationsList: INotification[];\n\n /**\n * List of read metamask notifications\n */\n metamaskNotificationsReadList: string[];\n /**\n * Flag that indicates that the creating notifications is in progress\n */\n isUpdatingMetamaskNotifications: boolean;\n /**\n * Flag that indicates that the fetching notifications is in progress\n * This is used to show a loading spinner in the UI\n * when fetching notifications\n */\n isFetchingMetamaskNotifications: boolean;\n /**\n * Flag that indicates that the updating notifications for a specific address is in progress\n */\n isUpdatingMetamaskNotificationsAccount: string[];\n /**\n * Flag that indicates that the checking accounts presence is in progress\n */\n isCheckingAccountsPresence: boolean;\n};\n\nconst metadata: StateMetadata<NotificationServicesControllerState> = {\n subscriptionAccountsSeen: {\n includeInStateLogs: true,\n persist: true,\n anonymous: true,\n usedInUi: true,\n },\n\n isMetamaskNotificationsFeatureSeen: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n isNotificationServicesEnabled: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n isFeatureAnnouncementsEnabled: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n metamaskNotificationsList: {\n includeInStateLogs: true,\n persist: true,\n anonymous: true,\n usedInUi: true,\n },\n metamaskNotificationsReadList: {\n includeInStateLogs: false,\n persist: true,\n anonymous: true,\n usedInUi: true,\n },\n isUpdatingMetamaskNotifications: {\n includeInStateLogs: false,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n isFetchingMetamaskNotifications: {\n includeInStateLogs: false,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n isUpdatingMetamaskNotificationsAccount: {\n includeInStateLogs: false,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n isCheckingAccountsPresence: {\n includeInStateLogs: false,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n};\nexport const defaultState: NotificationServicesControllerState = {\n subscriptionAccountsSeen: [],\n isMetamaskNotificationsFeatureSeen: false,\n isNotificationServicesEnabled: false,\n isFeatureAnnouncementsEnabled: false,\n metamaskNotificationsList: [],\n metamaskNotificationsReadList: [],\n isUpdatingMetamaskNotifications: false,\n isFetchingMetamaskNotifications: false,\n isUpdatingMetamaskNotificationsAccount: [],\n isCheckingAccountsPresence: false,\n};\n\nconst locallyPersistedNotificationTypes = new Set<TRIGGER_TYPES>([\n TRIGGER_TYPES.SNAP,\n]);\n\nexport type NotificationServicesControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesControllerState\n >;\n\nexport type NotificationServicesControllerUpdateMetamaskNotificationsList = {\n type: `${typeof controllerName}:updateMetamaskNotificationsList`;\n handler: NotificationServicesController['updateMetamaskNotificationsList'];\n};\n\nexport type NotificationServicesControllerDisableNotificationServices = {\n type: `${typeof controllerName}:disableNotificationServices`;\n handler: NotificationServicesController['disableNotificationServices'];\n};\n\nexport type NotificationServicesControllerGetNotificationsByType = {\n type: `${typeof controllerName}:getNotificationsByType`;\n handler: NotificationServicesController['getNotificationsByType'];\n};\n\nexport type NotificationServicesControllerDeleteNotificationsById = {\n type: `${typeof controllerName}:deleteNotificationsById`;\n handler: NotificationServicesController['deleteNotificationsById'];\n};\n\n// Messenger Actions\nexport type Actions =\n | NotificationServicesControllerGetStateAction\n | NotificationServicesControllerUpdateMetamaskNotificationsList\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerGetNotificationsByType\n | NotificationServicesControllerDeleteNotificationsById;\n\n// Allowed Actions\nexport type AllowedActions =\n // Keyring Controller Requests\n | KeyringControllerGetStateAction\n // Auth Controller Requests\n | AuthenticationController.AuthenticationControllerGetBearerToken\n | AuthenticationController.AuthenticationControllerIsSignedIn\n | AuthenticationController.AuthenticationControllerPerformSignIn\n // Push Notifications Controller Requests\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerSubscribeToNotificationsAction;\n\n// Events\nexport type NotificationServicesControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesControllerState\n >;\n\nexport type NotificationListUpdatedEvent = {\n type: `${typeof controllerName}:notificationsListUpdated`;\n payload: [INotification[]];\n};\n\nexport type MarkNotificationsAsReadEvent = {\n type: `${typeof controllerName}:markNotificationsAsRead`;\n payload: [INotification[]];\n};\n\n// Events\nexport type Events =\n | NotificationServicesControllerStateChangeEvent\n | NotificationListUpdatedEvent\n | MarkNotificationsAsReadEvent;\n\n// Allowed Events\nexport type AllowedEvents =\n // Keyring Events\n | KeyringControllerStateChangeEvent\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n // Push Notification Events\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerStateChangeEvent;\n\n// Type for the messenger of NotificationServicesController\nexport type NotificationServicesControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\ntype FeatureAnnouncementEnv = {\n spaceId: string;\n accessToken: string;\n platform: 'extension' | 'mobile';\n platformVersion?: string;\n};\n\n/**\n * Controller that enables wallet notifications and feature announcements\n */\nexport default class NotificationServicesController extends BaseController<\n typeof controllerName,\n NotificationServicesControllerState,\n NotificationServicesControllerMessenger\n> {\n readonly #keyringController = {\n isUnlocked: false,\n\n setupLockedStateSubscriptions: (onUnlock: () => Promise<void>) => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#keyringController.isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#keyringController.isUnlocked = true;\n // messaging system cannot await promises\n // we don't need to wait for a result on this.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n onUnlock();\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#keyringController.isUnlocked = false;\n });\n },\n };\n\n readonly #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n isSignedIn: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n };\n\n readonly #pushNotifications = {\n // Flag to check is notifications have been setup when the browser/extension is initialized.\n // We want to re-initialize push notifications when the browser/extension is refreshed\n // To ensure we subscribe to the most up-to-date notifications\n isSetup: false,\n\n subscribeToPushNotifications: async () => {\n await this.messagingSystem.call(\n 'NotificationServicesPushController:subscribeToPushNotifications',\n );\n },\n enablePushNotifications: async (addresses: string[]) => {\n try {\n await this.messagingSystem.call(\n 'NotificationServicesPushController:enablePushNotifications',\n addresses,\n );\n } catch (e) {\n log.error('Silently failed to enable push notifications', e);\n }\n },\n disablePushNotifications: async () => {\n try {\n await this.messagingSystem.call(\n 'NotificationServicesPushController:disablePushNotifications',\n );\n } catch (e) {\n log.error('Silently failed to disable push notifications', e);\n }\n },\n subscribe: () => {\n this.messagingSystem.subscribe(\n 'NotificationServicesPushController:onNewNotifications',\n (notification) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.updateMetamaskNotificationsList(notification);\n },\n );\n },\n initializePushNotifications: async () => {\n if (!this.state.isNotificationServicesEnabled) {\n return;\n }\n if (this.#pushNotifications.isSetup) {\n return;\n }\n\n // If wallet is unlocked, we can create a fresh push subscription\n // Otherwise we can subscribe to original subscription\n try {\n if (!this.#keyringController.isUnlocked) {\n throw new Error('Keyring is locked');\n }\n await this.enablePushNotifications();\n this.#pushNotifications.isSetup = true;\n } catch {\n await this.#pushNotifications\n .subscribeToPushNotifications()\n .catch(() => {\n // do nothing\n });\n }\n },\n };\n\n readonly #accounts = {\n // Flag to ensure we only setup once\n isNotificationAccountsSetup: false,\n\n getNotificationAccounts: () => {\n const { keyrings } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n const firstHDKeyring = keyrings.find(\n (k) => k.type === KeyringTypes.hd.toString(),\n );\n const keyringAccounts = firstHDKeyring?.accounts ?? null;\n return keyringAccounts;\n },\n\n /**\n * Used to get list of addresses from keyring (wallet addresses)\n *\n * @returns addresses removed, added, and latest list of addresses\n */\n listAccounts: () => {\n // Get previous and current account sets\n const nonChecksumAccounts = this.#accounts.getNotificationAccounts();\n if (!nonChecksumAccounts) {\n return {\n accountsAdded: [],\n accountsRemoved: [],\n accounts: [],\n };\n }\n\n const accounts = nonChecksumAccounts\n .map((a) => toChecksumHexAddress(a))\n .filter((a) => isValidHexAddress(a));\n const currentAccountsSet = new Set(accounts);\n const prevAccountsSet = new Set(this.state.subscriptionAccountsSeen);\n\n // Invalid value you cannot have zero accounts\n // Only occurs when the Accounts controller is initializing.\n if (accounts.length === 0) {\n return {\n accountsAdded: [],\n accountsRemoved: [],\n accounts: [],\n };\n }\n\n // Calculate added and removed addresses\n const accountsAdded = accounts.filter((a) => !prevAccountsSet.has(a));\n const accountsRemoved = [...prevAccountsSet.values()].filter(\n (a) => !currentAccountsSet.has(a),\n );\n\n // Update accounts seen\n this.update((state) => {\n state.subscriptionAccountsSeen = [...currentAccountsSet];\n });\n\n return {\n accountsAdded,\n accountsRemoved,\n accounts,\n };\n },\n\n /**\n * Initializes the cache/previous list. This is handy so we have an accurate in-mem state of the previous list of accounts.\n */\n initialize: (): void => {\n if (\n this.#keyringController.isUnlocked &&\n !this.#accounts.isNotificationAccountsSetup\n ) {\n this.#accounts.listAccounts();\n this.#accounts.isNotificationAccountsSetup = true;\n }\n },\n\n /**\n * Subscription to any state change in the keyring controller (aka wallet accounts).\n * We can call the `listAccounts` defined above to find out about any accounts added, removed\n * And call effects to subscribe/unsubscribe to notifications.\n */\n subscribe: () => {\n this.messagingSystem.subscribe(\n 'KeyringController:stateChange',\n\n async (totalAccounts, prevTotalAccounts) => {\n const hasTotalAccountsChanged = totalAccounts !== prevTotalAccounts;\n if (\n !this.state.isNotificationServicesEnabled ||\n !hasTotalAccountsChanged\n ) {\n return;\n }\n\n const { accountsAdded, accountsRemoved } =\n this.#accounts.listAccounts();\n\n const promises: Promise<unknown>[] = [];\n if (accountsAdded.length > 0) {\n promises.push(this.enableAccounts(accountsAdded));\n }\n if (accountsRemoved.length > 0) {\n promises.push(this.disableAccounts(accountsRemoved));\n }\n await Promise.allSettled(promises);\n },\n (state: KeyringControllerState) => {\n return (\n state?.keyrings?.flatMap?.((keyring) => keyring.accounts)?.length ??\n 0\n );\n },\n );\n },\n };\n\n readonly #featureAnnouncementEnv: FeatureAnnouncementEnv;\n\n /**\n * Creates a NotificationServicesController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n * @param args.env - environment variables for a given controller.\n * @param args.env.featureAnnouncements - env variables for feature announcements.\n * @param args.env.isPushIntegrated - toggle push notifications on/off if client has integrated them.\n */\n constructor({\n messenger,\n state,\n env,\n }: {\n messenger: NotificationServicesControllerMessenger;\n state?: Partial<NotificationServicesControllerState>;\n env: {\n featureAnnouncements: FeatureAnnouncementEnv;\n isPushIntegrated?: boolean;\n };\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#featureAnnouncementEnv = env.featureAnnouncements;\n this.#registerMessageHandlers();\n this.#clearLoadingStates();\n }\n\n init() {\n this.#keyringController.setupLockedStateSubscriptions(async () => {\n this.#accounts.initialize();\n await this.#pushNotifications.initializePushNotifications();\n });\n\n this.#accounts.initialize();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#pushNotifications.initializePushNotifications();\n this.#accounts.subscribe();\n this.#pushNotifications.subscribe();\n }\n\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateMetamaskNotificationsList`,\n this.updateMetamaskNotificationsList.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:disableNotificationServices`,\n this.disableNotificationServices.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getNotificationsByType`,\n this.getNotificationsByType.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:deleteNotificationsById`,\n this.deleteNotificationsById.bind(this),\n );\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingMetamaskNotifications = false;\n state.isCheckingAccountsPresence = false;\n state.isFetchingMetamaskNotifications = false;\n state.isUpdatingMetamaskNotificationsAccount = [];\n });\n }\n\n #assertAuthEnabled() {\n if (!this.#auth.isSignedIn()) {\n this.update((state) => {\n state.isNotificationServicesEnabled = false;\n });\n throw new Error('User is not signed in.');\n }\n }\n\n async #enableAuth() {\n const isSignedIn = this.#auth.isSignedIn();\n if (!isSignedIn) {\n await this.#auth.signIn();\n }\n }\n\n async #getBearerToken() {\n this.#assertAuthEnabled();\n\n const bearerToken = await this.#auth.getBearerToken();\n\n if (!bearerToken) {\n throw new Error('Missing BearerToken');\n }\n\n return { bearerToken };\n }\n\n /**\n * Sets the state of notification creation process.\n *\n * This method updates the `isUpdatingMetamaskNotifications` state, which can be used to indicate\n * whether the notification creation process is currently active or not. This is useful\n * for UI elements that need to reflect the state of ongoing operations, such as loading\n * indicators or disabled buttons during processing.\n *\n * @param isUpdatingMetamaskNotifications - A boolean value representing the new state of the notification creation process.\n */\n #setIsUpdatingMetamaskNotifications(\n isUpdatingMetamaskNotifications: boolean,\n ) {\n this.update((state) => {\n state.isUpdatingMetamaskNotifications = isUpdatingMetamaskNotifications;\n });\n }\n\n /**\n * Updates the state to indicate whether fetching of MetaMask notifications is in progress.\n *\n * This method is used to set the `isFetchingMetamaskNotifications` state, which can be utilized\n * to show or hide loading indicators in the UI when notifications are being fetched.\n *\n * @param isFetchingMetamaskNotifications - A boolean value representing the fetching state.\n */\n #setIsFetchingMetamaskNotifications(\n isFetchingMetamaskNotifications: boolean,\n ) {\n this.update((state) => {\n state.isFetchingMetamaskNotifications = isFetchingMetamaskNotifications;\n });\n }\n\n /**\n * Updates the state to indicate that the checking of accounts presence is in progress.\n *\n * This method modifies the `isCheckingAccountsPresence` state, which can be used to manage UI elements\n * that depend on the status of account presence checks, such as displaying loading indicators or disabling\n * buttons while the check is ongoing.\n *\n * @param isCheckingAccountsPresence - A boolean value indicating whether the account presence check is currently active.\n */\n #setIsCheckingAccountsPresence(isCheckingAccountsPresence: boolean) {\n this.update((state) => {\n state.isCheckingAccountsPresence = isCheckingAccountsPresence;\n });\n }\n\n /**\n * Updates the state to indicate that account updates are in progress.\n * Removes duplicate accounts before updating the state.\n *\n * @param accounts - The accounts being updated.\n */\n #updateUpdatingAccountsState(accounts: string[]) {\n this.update((state) => {\n const uniqueAccounts = new Set([\n ...state.isUpdatingMetamaskNotificationsAccount,\n ...accounts,\n ]);\n state.isUpdatingMetamaskNotificationsAccount = Array.from(uniqueAccounts);\n });\n }\n\n /**\n * Clears the state indicating that account updates are complete.\n *\n * @param accounts - The accounts that have finished updating.\n */\n #clearUpdatingAccountsState(accounts: string[]) {\n this.update((state) => {\n state.isUpdatingMetamaskNotificationsAccount =\n state.isUpdatingMetamaskNotificationsAccount.filter(\n (existingAccount) => !accounts.includes(existingAccount),\n );\n });\n }\n\n /**\n * Public method to expose enabling push notifications\n */\n public async enablePushNotifications() {\n try {\n const { bearerToken } = await this.#getBearerToken();\n const { accounts } = this.#accounts.listAccounts();\n const addressesWithNotifications =\n await OnChainNotifications.getOnChainNotificationsConfigCached(\n bearerToken,\n accounts,\n );\n const addresses = addressesWithNotifications\n .filter((a) => Boolean(a.enabled))\n .map((a) => a.address);\n if (addresses.length > 0) {\n await this.#pushNotifications.enablePushNotifications(addresses);\n }\n } catch (e) {\n log.error('Failed to enable push notifications', e);\n }\n }\n\n /**\n * Public method to expose disabling push notifications\n */\n public async disablePushNotifications() {\n await this.#pushNotifications.disablePushNotifications();\n }\n\n public async checkAccountsPresence(\n accounts: string[],\n ): Promise<Record<string, boolean>> {\n try {\n this.#setIsCheckingAccountsPresence(true);\n\n // Retrieve user storage\n const { bearerToken } = await this.#getBearerToken();\n const addressesWithNotifications =\n await OnChainNotifications.getOnChainNotificationsConfigCached(\n bearerToken,\n accounts,\n );\n\n const result: Record<string, boolean> = {};\n addressesWithNotifications.forEach((a) => {\n result[a.address] = a.enabled;\n });\n return result;\n } catch (error) {\n log.error('Failed to check accounts presence', error);\n throw error;\n } finally {\n this.#setIsCheckingAccountsPresence(false);\n }\n }\n\n /**\n * Sets the enabled state of feature announcements.\n *\n * **Action** - used in the notification settings to enable/disable feature announcements.\n *\n * @param featureAnnouncementsEnabled - A boolean value indicating the desired enabled state of the feature announcements.\n * @async\n * @throws {Error} If fails to update\n */\n public async setFeatureAnnouncementsEnabled(\n featureAnnouncementsEnabled: boolean,\n ) {\n try {\n this.update((s) => {\n s.isFeatureAnnouncementsEnabled = featureAnnouncementsEnabled;\n });\n } catch (e) {\n log.error('Unable to toggle feature announcements', e);\n throw new Error('Unable to toggle feature announcements');\n }\n }\n\n /**\n * This creates/re-creates on-chain triggers defined in User Storage.\n *\n * **Action** - Used during Sign In / Enabling of notifications.\n *\n * @param opts - optional options to mutate this functionality\n * @param opts.resetNotifications - this will not use the users stored preferences, and instead re-create notification triggers\n * It will help in case uses get into a corrupted state or wants to wipe their notifications.\n * @returns The updated or newly created user storage.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async createOnChainTriggers(opts?: {\n resetNotifications?: boolean;\n }): Promise<void> {\n try {\n this.#setIsUpdatingMetamaskNotifications(true);\n\n const { bearerToken } = await this.#getBearerToken();\n\n const { accounts } = this.#accounts.listAccounts();\n\n // 1. See if has enabled notifications before\n const addressesWithNotifications =\n await OnChainNotifications.getOnChainNotificationsConfigCached(\n bearerToken,\n accounts,\n );\n\n // Notifications API can return array with addresses set to false\n // So assert that at least one address is enabled\n let accountsWithNotifications = addressesWithNotifications\n .filter((a) => Boolean(a.enabled))\n .map((a) => a.address);\n\n // 2. Enable Notifications (if no accounts subscribed or we are resetting)\n if (accountsWithNotifications.length === 0 || opts?.resetNotifications) {\n await OnChainNotifications.updateOnChainNotifications(\n bearerToken,\n accounts.map((address) => ({ address, enabled: true })),\n );\n accountsWithNotifications = accounts;\n }\n\n // 3. Lazily enable push notifications (FCM may take some time, so keeps UI unblocked)\n this.#pushNotifications\n .enablePushNotifications(accountsWithNotifications)\n .catch(() => {\n // Do Nothing\n });\n\n // Update the state of the controller\n this.update((state) => {\n state.isNotificationServicesEnabled = true;\n state.isFeatureAnnouncementsEnabled = true;\n state.isMetamaskNotificationsFeatureSeen = true;\n });\n } catch (err) {\n log.error('Failed to create On Chain triggers', err);\n throw new Error('Failed to create On Chain triggers');\n } finally {\n this.#setIsUpdatingMetamaskNotifications(false);\n }\n }\n\n /**\n * Enables all MetaMask notifications for the user.\n * This is identical flow when initializing notifications for the first time.\n *\n * @throws {Error} If there is an error during the process of enabling notifications.\n */\n public async enableMetamaskNotifications() {\n try {\n this.#setIsUpdatingMetamaskNotifications(true);\n await this.#enableAuth();\n await this.createOnChainTriggers();\n } catch (e) {\n log.error('Unable to enable notifications', e);\n throw new Error('Unable to enable notifications');\n } finally {\n this.#setIsUpdatingMetamaskNotifications(false);\n }\n }\n\n /**\n * Disables all MetaMask notifications for the user.\n * This method ensures that the user is authenticated, retrieves all linked accounts,\n * and disables on-chain triggers for each account. It also sets the global notification\n * settings for MetaMask, feature announcements to false.\n *\n * @throws {Error} If the user is not authenticated or if there is an error during the process.\n */\n public async disableNotificationServices() {\n this.#setIsUpdatingMetamaskNotifications(true);\n\n // Attempt Disable Push Notifications\n try {\n await this.#pushNotifications.disablePushNotifications();\n } catch {\n // Do nothing\n }\n\n // Update State: remove non-permitted notifications & disable flags\n const snapNotifications = this.state.metamaskNotificationsList.filter(\n (notification) => notification.type === TRIGGER_TYPES.SNAP,\n );\n this.update((state) => {\n state.isNotificationServicesEnabled = false;\n state.isFeatureAnnouncementsEnabled = false;\n // reassigning the notifications list with just snaps\n // since the disable shouldn't affect snaps notifications\n state.metamaskNotificationsList = snapNotifications;\n });\n\n // Finish Updating State\n this.#setIsUpdatingMetamaskNotifications(false);\n }\n\n /**\n * Deletes on-chain triggers associated with a specific account/s.\n * This method performs several key operations:\n * 1. Validates Auth\n * 2. Deletes accounts\n * (note) We do not need to look through push notifications as we've deleted triggers\n *\n * **Action** - When a user disables notifications for a given account in settings.\n *\n * @param accounts - The account for which on-chain triggers are to be deleted.\n * @returns A promise that resolves to void or an object containing a success message.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async disableAccounts(accounts: string[]): Promise<void> {\n try {\n this.#updateUpdatingAccountsState(accounts);\n // Get and Validate BearerToken and User Storage Key\n const { bearerToken } = await this.#getBearerToken();\n\n // Delete these UUIDs (Mutates User Storage)\n await OnChainNotifications.updateOnChainNotifications(\n bearerToken,\n accounts.map((address) => ({ address, enabled: false })),\n );\n } catch (err) {\n log.error('Failed to delete OnChain triggers', err);\n throw new Error('Failed to delete OnChain triggers');\n } finally {\n this.#clearUpdatingAccountsState(accounts);\n }\n }\n\n /**\n * Updates/Creates on-chain triggers for a specific account.\n *\n * This method performs several key operations:\n * 1. Validates Auth & Storage\n * 2. Finds and creates any missing triggers associated with the account\n * 3. Enables any related push notifications\n * 4. Updates Storage to reflect new state.\n *\n * **Action** - When a user enables notifications for an account\n *\n * @param accounts - List of accounts you want to update.\n * @returns A promise that resolves to the updated user storage.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async enableAccounts(accounts: string[]): Promise<void> {\n try {\n this.#updateUpdatingAccountsState(accounts);\n\n const { bearerToken } = await this.#getBearerToken();\n await OnChainNotifications.updateOnChainNotifications(\n bearerToken,\n accounts.map((address) => ({ address, enabled: true })),\n );\n } catch (err) {\n log.error('Failed to update OnChain triggers', err);\n throw new Error('Failed to update OnChain triggers');\n } finally {\n this.#clearUpdatingAccountsState(accounts);\n }\n }\n\n /**\n * Fetches the list of metamask notifications.\n * This includes OnChain notifications; Feature Announcements; and Snap Notifications.\n *\n * **Action** - When a user views the notification list page/dropdown\n *\n * @param previewToken - the preview token to use if needed\n * @returns A promise that resolves to the list of notifications.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async fetchAndUpdateMetamaskNotifications(\n previewToken?: string,\n ): Promise<INotification[]> {\n try {\n this.#setIsFetchingMetamaskNotifications(true);\n\n // This is used by Feature Announcement & On Chain\n // Not used by Snaps\n const isGlobalNotifsEnabled = this.state.isNotificationServicesEnabled;\n\n // Raw Feature Notifications\n const rawAnnouncements =\n isGlobalNotifsEnabled && this.state.isFeatureAnnouncementsEnabled\n ? await FeatureNotifications.getFeatureAnnouncementNotifications(\n this.#featureAnnouncementEnv,\n previewToken,\n ).catch(() => [])\n : [];\n\n // Raw On Chain Notifications\n const rawOnChainNotifications: OnChainRawNotification[] = [];\n if (isGlobalNotifsEnabled) {\n try {\n const { bearerToken } = await this.#getBearerToken();\n const { accounts } = this.#accounts.listAccounts();\n const addressesWithNotifications = (\n await OnChainNotifications.getOnChainNotificationsConfigCached(\n bearerToken,\n accounts,\n )\n )\n .filter((a) => Boolean(a.enabled))\n .map((a) => a.address);\n const notifications =\n await OnChainNotifications.getOnChainNotifications(\n bearerToken,\n addressesWithNotifications,\n ).catch(() => []);\n rawOnChainNotifications.push(...notifications);\n } catch {\n // Do nothing\n }\n }\n\n // Snap Notifications (original)\n // We do not want to remove them\n const snapNotifications = this.state.metamaskNotificationsList.filter(\n (notification) => notification.type === TRIGGER_TYPES.SNAP,\n );\n\n const readIds = this.state.metamaskNotificationsReadList;\n\n // Combine Notifications\n const metamaskNotifications: INotification[] = [\n ...processAndFilterNotifications(rawAnnouncements, readIds),\n ...processAndFilterNotifications(rawOnChainNotifications, readIds),\n ...snapNotifications,\n ];\n\n // Sort Notifications\n metamaskNotifications.sort(\n (a, b) =>\n new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),\n );\n\n // Update State\n this.update((state) => {\n state.metamaskNotificationsList = metamaskNotifications;\n });\n\n this.messagingSystem.publish(\n `${controllerName}:notificationsListUpdated`,\n this.state.metamaskNotificationsList,\n );\n\n this.#setIsFetchingMetamaskNotifications(false);\n return metamaskNotifications;\n } catch (err) {\n this.#setIsFetchingMetamaskNotifications(false);\n log.error('Failed to fetch notifications', err);\n throw new Error('Failed to fetch notifications');\n }\n }\n\n /**\n * Gets the specified type of notifications from state.\n *\n * @param type - The trigger type.\n * @returns An array of notifications of the passed in type.\n * @throws Throws an error if an invalid trigger type is passed.\n */\n public getNotificationsByType(type: TRIGGER_TYPES) {\n assert(\n Object.values(TRIGGER_TYPES).includes(type),\n 'Invalid trigger type.',\n );\n return this.state.metamaskNotificationsList.filter(\n (notification) => notification.type === type,\n );\n }\n\n /**\n * Used to delete a notification by id.\n *\n * Note: This function should only be used for notifications that are stored\n * in this controller directly, currently only snaps notifications.\n *\n * @param id - The id of the notification to delete.\n */\n public async deleteNotificationById(id: string) {\n const fetchedNotification = this.state.metamaskNotificationsList.find(\n (notification) => notification.id === id,\n );\n\n assert(\n fetchedNotification,\n 'The notification to be deleted does not exist.',\n );\n\n assert(\n locallyPersistedNotificationTypes.has(fetchedNotification.type),\n `The notification type of \"${\n // notifications are guaranteed to have type properties which equate to strings\n fetchedNotification.type as string\n }\" is not locally persisted, only the following types can use this function: ${[\n ...locallyPersistedNotificationTypes,\n ].join(', ')}.`,\n );\n\n const newList = this.state.metamaskNotificationsList.filter(\n (notification) => notification.id !== id,\n );\n\n this.update((state) => {\n state.metamaskNotificationsList = newList;\n });\n }\n\n /**\n * Used to batch delete notifications by id.\n *\n * Note: This function should only be used for notifications that are stored\n * in this controller directly, currently only snaps notifications.\n *\n * @param ids - The ids of the notifications to delete.\n */\n public async deleteNotificationsById(ids: string[]) {\n for (const id of ids) {\n await this.deleteNotificationById(id);\n }\n\n this.messagingSystem.publish(\n `${controllerName}:notificationsListUpdated`,\n this.state.metamaskNotificationsList,\n );\n }\n\n /**\n * Marks specified metamask notifications as read.\n *\n * @param notifications - An array of notifications to be marked as read. Each notification should include its type and read status.\n * @returns A promise that resolves when the operation is complete.\n */\n public async markMetamaskNotificationsAsRead(\n notifications: MarkAsReadNotificationsParam,\n ): Promise<void> {\n let onchainNotificationIds: string[] = [];\n let featureAnnouncementNotificationIds: string[] = [];\n let snapNotificationIds: string[] = [];\n\n try {\n const [\n onChainNotifications,\n featureAnnouncementNotifications,\n snapNotifications,\n ] = notifications.reduce<\n [\n MarkAsReadNotificationsParam,\n MarkAsReadNotificationsParam,\n MarkAsReadNotificationsParam,\n ]\n >(\n (allNotifications, notification) => {\n if (!notification.isRead) {\n switch (notification.type) {\n case TRIGGER_TYPES.FEATURES_ANNOUNCEMENT:\n allNotifications[1].push(notification);\n break;\n case TRIGGER_TYPES.SNAP:\n allNotifications[2].push(notification);\n break;\n default:\n allNotifications[0].push(notification);\n }\n }\n return allNotifications;\n },\n [[], [], []],\n );\n\n // Mark On-Chain Notifications as Read\n if (onChainNotifications.length > 0) {\n const bearerToken = await this.#auth.getBearerToken();\n\n if (bearerToken) {\n onchainNotificationIds = onChainNotifications.map(\n (notification) => notification.id,\n );\n await OnChainNotifications.markNotificationsAsRead(\n bearerToken,\n onchainNotificationIds,\n ).catch(() => {\n onchainNotificationIds = [];\n log.warn('Unable to mark onchain notifications as read');\n });\n }\n }\n\n // Mark Off-Chain notifications as Read\n if (featureAnnouncementNotifications.length > 0) {\n featureAnnouncementNotificationIds =\n featureAnnouncementNotifications.map(\n (notification) => notification.id,\n );\n }\n\n if (snapNotifications.length > 0) {\n snapNotificationIds = snapNotifications.map(\n (notification) => notification.id,\n );\n }\n } catch (err) {\n log.warn('Something failed when marking notifications as read', err);\n }\n\n // Update the state (state is also used on counter & badge)\n this.update((state) => {\n const currentReadList = state.metamaskNotificationsReadList;\n const newReadIds = [\n ...featureAnnouncementNotificationIds,\n ...snapNotificationIds,\n ];\n state.metamaskNotificationsReadList = [\n ...new Set([...currentReadList, ...newReadIds]),\n ];\n\n state.metamaskNotificationsList = state.metamaskNotificationsList.map(\n (notification: INotification) => {\n if (\n newReadIds.includes(notification.id) ||\n onchainNotificationIds.includes(notification.id)\n ) {\n if (notification.type === TRIGGER_TYPES.SNAP) {\n return {\n ...notification,\n isRead: true,\n readDate: new Date().toISOString(),\n };\n }\n return { ...notification, isRead: true };\n }\n return notification;\n },\n );\n });\n\n this.messagingSystem.publish(\n `${controllerName}:markNotificationsAsRead`,\n this.state.metamaskNotificationsList,\n );\n }\n\n /**\n * Updates the list of MetaMask notifications by adding a new notification at the beginning of the list.\n * This method ensures that the most recent notification is displayed first in the UI.\n *\n * @param notification - The new notification object to be added to the list.\n * @returns A promise that resolves when the notification list has been successfully updated.\n */\n public async updateMetamaskNotificationsList(\n notification: INotification,\n ): Promise<void> {\n if (\n this.state.metamaskNotificationsList.some((n) => n.id === notification.id)\n ) {\n return;\n }\n\n const processedNotification = safeProcessNotification(notification);\n\n if (processedNotification) {\n this.update((state) => {\n const existingNotificationIds = new Set(\n state.metamaskNotificationsList.map((n) => n.id),\n );\n // Add the new notification only if its ID is not already present in the list\n if (!existingNotificationIds.has(processedNotification.id)) {\n state.metamaskNotificationsList = [\n processedNotification,\n ...state.metamaskNotificationsList,\n ];\n }\n });\n\n this.messagingSystem.publish(\n `${controllerName}:notificationsListUpdated`,\n this.state.metamaskNotificationsList,\n );\n }\n }\n\n /**\n * Creates an perp order notification subscription.\n * Requires notifications and auth to be enabled to start receiving this notifications\n *\n * @param input perp input\n */\n public async sendPerpPlaceOrderNotification(input: OrderInput) {\n try {\n const { bearerToken } = await this.#getBearerToken();\n await createPerpOrderNotification(bearerToken, input);\n } catch {\n // Do Nothing\n }\n }\n}\n"]}
@@ -25,6 +25,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
25
25
  isRead: boolean;
26
26
  } | {
27
27
  id: string;
28
+ address: string;
28
29
  trigger_id: string;
29
30
  chain_id: number;
30
31
  block_number: number;
@@ -32,7 +33,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
32
33
  tx_hash: string;
33
34
  unread: boolean;
34
35
  created_at: string;
35
- address: string;
36
36
  type: TRIGGER_TYPES.METAMASK_SWAP_COMPLETED;
37
37
  data: {
38
38
  kind: "metamask_swap_completed";
@@ -64,6 +64,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
64
64
  isRead: boolean;
65
65
  } | {
66
66
  id: string;
67
+ address: string;
67
68
  trigger_id: string;
68
69
  chain_id: number;
69
70
  block_number: number;
@@ -71,7 +72,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
71
72
  tx_hash: string;
72
73
  unread: boolean;
73
74
  created_at: string;
74
- address: string;
75
75
  type: TRIGGER_TYPES.ERC20_SENT;
76
76
  data: {
77
77
  kind: "erc20_sent";
@@ -95,6 +95,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
95
95
  isRead: boolean;
96
96
  } | {
97
97
  id: string;
98
+ address: string;
98
99
  trigger_id: string;
99
100
  chain_id: number;
100
101
  block_number: number;
@@ -102,7 +103,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
102
103
  tx_hash: string;
103
104
  unread: boolean;
104
105
  created_at: string;
105
- address: string;
106
106
  type: TRIGGER_TYPES.ERC20_RECEIVED;
107
107
  data: {
108
108
  kind: "erc20_received";
@@ -126,6 +126,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
126
126
  isRead: boolean;
127
127
  } | {
128
128
  id: string;
129
+ address: string;
129
130
  trigger_id: string;
130
131
  chain_id: number;
131
132
  block_number: number;
@@ -133,7 +134,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
133
134
  tx_hash: string;
134
135
  unread: boolean;
135
136
  created_at: string;
136
- address: string;
137
137
  type: TRIGGER_TYPES.ETH_SENT;
138
138
  data: {
139
139
  kind: "eth_sent";
@@ -152,6 +152,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
152
152
  isRead: boolean;
153
153
  } | {
154
154
  id: string;
155
+ address: string;
155
156
  trigger_id: string;
156
157
  chain_id: number;
157
158
  block_number: number;
@@ -159,7 +160,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
159
160
  tx_hash: string;
160
161
  unread: boolean;
161
162
  created_at: string;
162
- address: string;
163
163
  type: TRIGGER_TYPES.ETH_RECEIVED;
164
164
  data: {
165
165
  kind: "eth_received";
@@ -178,6 +178,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
178
178
  isRead: boolean;
179
179
  } | {
180
180
  id: string;
181
+ address: string;
181
182
  trigger_id: string;
182
183
  chain_id: number;
183
184
  block_number: number;
@@ -185,7 +186,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
185
186
  tx_hash: string;
186
187
  unread: boolean;
187
188
  created_at: string;
188
- address: string;
189
189
  type: TRIGGER_TYPES.ROCKETPOOL_STAKE_COMPLETED;
190
190
  data: {
191
191
  kind: "rocketpool_stake_completed";
@@ -216,6 +216,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
216
216
  isRead: boolean;
217
217
  } | {
218
218
  id: string;
219
+ address: string;
219
220
  trigger_id: string;
220
221
  chain_id: number;
221
222
  block_number: number;
@@ -223,7 +224,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
223
224
  tx_hash: string;
224
225
  unread: boolean;
225
226
  created_at: string;
226
- address: string;
227
227
  type: TRIGGER_TYPES.ROCKETPOOL_UNSTAKE_COMPLETED;
228
228
  data: {
229
229
  kind: "rocketpool_unstake_completed";
@@ -254,6 +254,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
254
254
  isRead: boolean;
255
255
  } | {
256
256
  id: string;
257
+ address: string;
257
258
  trigger_id: string;
258
259
  chain_id: number;
259
260
  block_number: number;
@@ -261,7 +262,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
261
262
  tx_hash: string;
262
263
  unread: boolean;
263
264
  created_at: string;
264
- address: string;
265
265
  type: TRIGGER_TYPES.LIDO_STAKE_COMPLETED;
266
266
  data: {
267
267
  kind: "lido_stake_completed";
@@ -292,6 +292,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
292
292
  isRead: boolean;
293
293
  } | {
294
294
  id: string;
295
+ address: string;
295
296
  trigger_id: string;
296
297
  chain_id: number;
297
298
  block_number: number;
@@ -299,7 +300,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
299
300
  tx_hash: string;
300
301
  unread: boolean;
301
302
  created_at: string;
302
- address: string;
303
303
  type: TRIGGER_TYPES.LIDO_WITHDRAWAL_REQUESTED;
304
304
  data: {
305
305
  kind: "lido_withdrawal_requested";
@@ -330,6 +330,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
330
330
  isRead: boolean;
331
331
  } | {
332
332
  id: string;
333
+ address: string;
333
334
  trigger_id: string;
334
335
  chain_id: number;
335
336
  block_number: number;
@@ -337,7 +338,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
337
338
  tx_hash: string;
338
339
  unread: boolean;
339
340
  created_at: string;
340
- address: string;
341
341
  type: TRIGGER_TYPES.LIDO_WITHDRAWAL_COMPLETED;
342
342
  data: {
343
343
  kind: "lido_withdrawal_completed";
@@ -368,6 +368,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
368
368
  isRead: boolean;
369
369
  } | {
370
370
  id: string;
371
+ address: string;
371
372
  trigger_id: string;
372
373
  chain_id: number;
373
374
  block_number: number;
@@ -375,7 +376,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
375
376
  tx_hash: string;
376
377
  unread: boolean;
377
378
  created_at: string;
378
- address: string;
379
379
  type: TRIGGER_TYPES.LIDO_STAKE_READY_TO_BE_WITHDRAWN;
380
380
  data: {
381
381
  kind: "lido_stake_ready_to_be_withdrawn";
@@ -394,6 +394,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
394
394
  isRead: boolean;
395
395
  } | {
396
396
  id: string;
397
+ address: string;
397
398
  trigger_id: string;
398
399
  chain_id: number;
399
400
  block_number: number;
@@ -401,7 +402,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
401
402
  tx_hash: string;
402
403
  unread: boolean;
403
404
  created_at: string;
404
- address: string;
405
405
  type: TRIGGER_TYPES.ERC721_SENT;
406
406
  data: {
407
407
  kind: "erc721_sent";
@@ -427,6 +427,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
427
427
  isRead: boolean;
428
428
  } | {
429
429
  id: string;
430
+ address: string;
430
431
  trigger_id: string;
431
432
  chain_id: number;
432
433
  block_number: number;
@@ -434,7 +435,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
434
435
  tx_hash: string;
435
436
  unread: boolean;
436
437
  created_at: string;
437
- address: string;
438
438
  type: TRIGGER_TYPES.ERC721_RECEIVED;
439
439
  data: {
440
440
  kind: "erc721_received";
@@ -460,6 +460,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
460
460
  isRead: boolean;
461
461
  } | {
462
462
  id: string;
463
+ address: string;
463
464
  trigger_id: string;
464
465
  chain_id: number;
465
466
  block_number: number;
@@ -467,7 +468,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
467
468
  tx_hash: string;
468
469
  unread: boolean;
469
470
  created_at: string;
470
- address: string;
471
471
  type: TRIGGER_TYPES.ERC1155_SENT;
472
472
  data: {
473
473
  kind: "erc1155_sent";
@@ -493,6 +493,7 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
493
493
  isRead: boolean;
494
494
  } | {
495
495
  id: string;
496
+ address: string;
496
497
  trigger_id: string;
497
498
  chain_id: number;
498
499
  block_number: number;
@@ -500,7 +501,6 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
500
501
  tx_hash: string;
501
502
  unread: boolean;
502
503
  created_at: string;
503
- address: string;
504
504
  type: TRIGGER_TYPES.ERC1155_RECEIVED;
505
505
  data: {
506
506
  kind: "erc1155_received";
@@ -526,11 +526,11 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
526
526
  isRead: boolean;
527
527
  } | {
528
528
  id: string;
529
+ address: string;
529
530
  trigger_id: string;
530
531
  chain_id: number;
531
532
  unread: boolean;
532
533
  created_at: string;
533
- address: string;
534
534
  type: TRIGGER_TYPES.AAVE_V3_HEALTH_FACTOR;
535
535
  data: {
536
536
  kind: "aave_v3_health_factor";
@@ -542,11 +542,11 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
542
542
  isRead: boolean;
543
543
  } | {
544
544
  id: string;
545
+ address: string;
545
546
  trigger_id: string;
546
547
  chain_id: number;
547
548
  unread: boolean;
548
549
  created_at: string;
549
- address: string;
550
550
  type: TRIGGER_TYPES.ENS_EXPIRATION;
551
551
  data: {
552
552
  kind: "ens_expiration";
@@ -559,11 +559,11 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
559
559
  isRead: boolean;
560
560
  } | {
561
561
  id: string;
562
+ address: string;
562
563
  trigger_id: string;
563
564
  chain_id: number;
564
565
  unread: boolean;
565
566
  created_at: string;
566
- address: string;
567
567
  type: TRIGGER_TYPES.LIDO_STAKING_REWARDS;
568
568
  data: {
569
569
  kind: "lido_staking_rewards";
@@ -578,11 +578,11 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
578
578
  isRead: boolean;
579
579
  } | {
580
580
  id: string;
581
+ address: string;
581
582
  trigger_id: string;
582
583
  chain_id: number;
583
584
  unread: boolean;
584
585
  created_at: string;
585
- address: string;
586
586
  type: TRIGGER_TYPES.ROCKETPOOL_STAKING_REWARDS;
587
587
  data: {
588
588
  kind: "rocketpool_staking_rewards";
@@ -597,11 +597,11 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
597
597
  isRead: boolean;
598
598
  } | {
599
599
  id: string;
600
+ address: string;
600
601
  trigger_id: string;
601
602
  chain_id: number;
602
603
  unread: boolean;
603
604
  created_at: string;
604
- address: string;
605
605
  type: TRIGGER_TYPES.NOTIONAL_LOAN_EXPIRATION;
606
606
  data: {
607
607
  kind: "notional_loan_expiration";
@@ -617,11 +617,11 @@ export declare const processAndFilterNotifications: (ns: RawNotificationUnion[],
617
617
  isRead: boolean;
618
618
  } | {
619
619
  id: string;
620
+ address: string;
620
621
  trigger_id: string;
621
622
  chain_id: number;
622
623
  unread: boolean;
623
624
  created_at: string;
624
- address: string;
625
625
  type: TRIGGER_TYPES.SPARK_FI_HEALTH_FACTOR;
626
626
  data: {
627
627
  kind: "spark_fi_health_factor";