@metamask-previews/notification-services-controller 0.21.0-preview-5575cd05 → 0.21.0-preview-a1eb992b
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.
- package/dist/NotificationServicesController/NotificationServicesController.cjs +74 -62
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +34 -10
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +34 -10
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +74 -62
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/index.cjs +0 -1
- package/dist/NotificationServicesController/index.cjs.map +1 -1
- package/dist/NotificationServicesController/index.d.cts +0 -1
- package/dist/NotificationServicesController/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/index.d.mts +0 -1
- package/dist/NotificationServicesController/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/index.mjs +0 -1
- package/dist/NotificationServicesController/index.mjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +56 -56
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +24 -18
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +24 -18
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +57 -57
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs +13 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs +12 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs.map +1 -1
- package/dist/NotificationServicesPushController/constants.cjs +14 -0
- package/dist/NotificationServicesPushController/constants.cjs.map +1 -0
- package/dist/NotificationServicesPushController/constants.d.cts +11 -0
- package/dist/NotificationServicesPushController/constants.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/constants.d.mts +11 -0
- package/dist/NotificationServicesPushController/constants.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/constants.mjs +11 -0
- package/dist/NotificationServicesPushController/constants.mjs.map +1 -0
- package/dist/NotificationServicesPushController/{types/push-service-interface.cjs → services/push/index.cjs} +1 -1
- package/dist/NotificationServicesPushController/services/push/index.cjs.map +1 -0
- package/dist/NotificationServicesPushController/services/push/index.d.cts +6 -0
- package/dist/NotificationServicesPushController/services/push/index.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/services/push/index.d.mts +6 -0
- package/dist/NotificationServicesPushController/services/push/index.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/services/push/index.mjs +2 -0
- package/dist/NotificationServicesPushController/services/push/index.mjs.map +1 -0
- package/dist/NotificationServicesPushController/services/services.cjs +93 -15
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts +27 -4
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts +27 -4
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs +94 -14
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/dist/NotificationServicesPushController/types/index.cjs.map +1 -1
- package/dist/NotificationServicesPushController/types/index.d.cts +0 -1
- package/dist/NotificationServicesPushController/types/index.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/types/index.d.mts +0 -1
- package/dist/NotificationServicesPushController/types/index.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/types/index.mjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +19 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +7 -0
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +7 -0
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +17 -0
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
- package/package.json +1 -11
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs +0 -14
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs.map +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts +0 -3
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts +0 -3
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs +0 -10
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs.map +0 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.cjs.map +0 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.d.cts +0 -30
- package/dist/NotificationServicesPushController/types/push-service-interface.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.d.mts +0 -30
- package/dist/NotificationServicesPushController/types/push-service-interface.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.mjs +0 -2
- package/dist/NotificationServicesPushController/types/push-service-interface.mjs.map +0 -1
- package/dist/NotificationServicesPushController/web/index.cjs +0 -8
- package/dist/NotificationServicesPushController/web/index.cjs.map +0 -1
- package/dist/NotificationServicesPushController/web/index.d.cts +0 -2
- package/dist/NotificationServicesPushController/web/index.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/web/index.d.mts +0 -2
- package/dist/NotificationServicesPushController/web/index.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/web/index.mjs +0 -2
- package/dist/NotificationServicesPushController/web/index.mjs.map +0 -1
- package/dist/NotificationServicesPushController/web/push-utils.cjs +0 -170
- package/dist/NotificationServicesPushController/web/push-utils.cjs.map +0 -1
- package/dist/NotificationServicesPushController/web/push-utils.d.cts +0 -37
- package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/web/push-utils.d.mts +0 -37
- package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/web/push-utils.mjs +0 -168
- package/dist/NotificationServicesPushController/web/push-utils.mjs.map +0 -1
- package/dist/shared/index.cjs +0 -19
- package/dist/shared/index.cjs.map +0 -1
- package/dist/shared/index.d.cts +0 -3
- package/dist/shared/index.d.cts.map +0 -1
- package/dist/shared/index.d.mts +0 -3
- package/dist/shared/index.d.mts.map +0 -1
- package/dist/shared/index.mjs +0 -3
- package/dist/shared/index.mjs.map +0 -1
- package/dist/shared/is-onchain-notification.cjs +0 -22
- package/dist/shared/is-onchain-notification.cjs.map +0 -1
- package/dist/shared/is-onchain-notification.d.cts +0 -9
- package/dist/shared/is-onchain-notification.d.cts.map +0 -1
- package/dist/shared/is-onchain-notification.d.mts +0 -9
- package/dist/shared/is-onchain-notification.d.mts.map +0 -1
- package/dist/shared/is-onchain-notification.mjs +0 -18
- package/dist/shared/is-onchain-notification.mjs.map +0 -1
- package/push-services/web/package.json +0 -150
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-notification-message.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAElE,mGAAiE;AAkDjE;;;;;;GAMG;AACI,MAAM,qCAAqC,GAAG,CACnD,eAAgC,EACP,EAAE;IAI3B,MAAM,CAAC,GAAkB,CAAC,GAAG,IAAI,EAAE,EAAE;QACnC,MAAM,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;QAEjC,4CAA4C;QAC5C,8DAA8D;QAC9D,MAAM,EAAE,GAAQ,eAAe,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE;YACV,KAAK,EAAE,CAAC,CAAC,yCAAyC,CAAC;YACnD,kBAAkB,EAAE,CAAC,CACnB,sDAAsD,CACvD;YACD,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;gBACpB,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBACtC,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBAC3C,MAAM,aAAa,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC;gBAC/C,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,IAAI,CAAC,aAAa,EAAE;oBAC7C,OAAO,IAAI,CAAC;iBACb;gBAED,MAAM,MAAM,GAAG,IAAA,iCAAS,EAAC,WAAW,EAAE,aAAa,EAAE;oBACnD,aAAa,EAAE,IAAI;iBACpB,CAAC,CAAC;gBACH,OAAO,CAAC,CACN,+CAA+C,EAC/C,MAAM,EACN,MAAM,CACP,CAAC;YACJ,CAAC;SACF;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,CAAC,CAAC,yCAAyC,CAAC;YACnD,kBAAkB,EAAE,CAAC,CACnB,sDAAsD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AAI,CAAC;KAC9D;IAED,OAAO;QACL,KAAK,EAAE,mBAAmB,CAAC,KAAK,IAAI,EAAE;QACtC,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,mCAAmC;KACpE,CAAC;AACJ,CAAC;AA7BD,oFA6BC","sourcesContent":["import { getAmount, formatAmount } from './get-notification-data';\nimport type { Types } from '../../NotificationServicesController';\nimport { Constants } from '../../NotificationServicesController';\n\nexport type TranslationKeys = {\n pushPlatformNotificationsFundsSentTitle: () => string;\n pushPlatformNotificationsFundsSentDescriptionDefault: () => string;\n pushPlatformNotificationsFundsSentDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsFundsReceivedTitle: () => string;\n pushPlatformNotificationsFundsReceivedDescriptionDefault: () => string;\n pushPlatformNotificationsFundsReceivedDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsSwapCompletedTitle: () => string;\n pushPlatformNotificationsSwapCompletedDescription: () => string;\n pushPlatformNotificationsNftSentTitle: () => string;\n pushPlatformNotificationsNftSentDescription: () => string;\n pushPlatformNotificationsNftReceivedTitle: () => string;\n pushPlatformNotificationsNftReceivedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription: () => string;\n};\n\ntype PushNotificationMessage = {\n title: string;\n description: string;\n};\n\ntype NotificationMessage<N extends Types.INotification> = {\n title: string | null;\n defaultDescription: string | null;\n getDescription?: (n: N) => string | null;\n};\n\ntype NotificationMessageDict = {\n [K in Constants.TRIGGER_TYPES]?: NotificationMessage<\n Extract<Types.INotification, { type: K }>\n >;\n};\n\n/**\n * On Chain Push Notification Messages.\n * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension\n *\n * @param translationKeys - all translations supported\n * @returns A translation push message object.\n */\nexport const createOnChainPushNotificationMessages = (\n translationKeys: TranslationKeys,\n): NotificationMessageDict => {\n type TranslationFn = <K extends keyof TranslationKeys>(\n ...args: [K, ...Parameters<TranslationKeys[K]>]\n ) => string;\n const t: TranslationFn = (...args) => {\n const [key, ...otherArgs] = args;\n\n // Coerce types for the translation function\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const fn: any = translationKeys[key];\n return fn(...otherArgs);\n };\n\n return {\n erc20_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n eth_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n erc20_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n eth_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n metamask_swap_completed: {\n title: t('pushPlatformNotificationsSwapCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsSwapCompletedDescription',\n ),\n },\n erc721_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeCompletedDescription',\n ),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription',\n ),\n },\n lido_withdrawal_completed: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription',\n ),\n },\n };\n};\n\n/**\n * Retrieves the symbol associated with a given chain ID.\n *\n * @param chainId - The ID of the chain.\n * @returns The symbol associated with the chain ID, or null if not found.\n */\nfunction getChainSymbol(chainId: number) {\n return Constants.CHAIN_SYMBOLS[chainId] ?? null;\n}\n\n/**\n * Creates a push notification message based on the given on-chain raw notification.\n *\n * @param n - processed notification.\n * @param translations - translates keys into text\n * @returns The push notification message object, or null if the notification is invalid.\n */\nexport function createOnChainPushNotificationMessage(\n n: Types.INotification,\n translations: TranslationKeys,\n): PushNotificationMessage | null {\n if (!n?.type) {\n return null;\n }\n const notificationMessage =\n createOnChainPushNotificationMessages(translations)[n.type];\n\n if (!notificationMessage) {\n return null;\n }\n\n let description: string | null = null;\n try {\n description =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage?.getDescription?.(n as any) ??\n notificationMessage.defaultDescription ??\n null;\n } catch {\n description = notificationMessage.defaultDescription ?? null;\n }\n\n return {\n title: notificationMessage.title ?? '', // Ensure title is always a string\n description: description ?? '', // Fallback to empty string if null\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"get-notification-message.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAElE,mGAAiE;AAkDjE;;;;;;GAMG;AACI,MAAM,qCAAqC,GAAG,CACnD,eAAgC,EACP,EAAE;IAI3B,MAAM,CAAC,GAAkB,CAAC,GAAG,IAAI,EAAE,EAAE;QACnC,MAAM,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;QAEjC,4CAA4C;QAC5C,8DAA8D;QAC9D,MAAM,EAAE,GAAQ,eAAe,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE;YACV,KAAK,EAAE,CAAC,CAAC,yCAAyC,CAAC;YACnD,kBAAkB,EAAE,CAAC,CACnB,sDAAsD,CACvD;YACD,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;gBACpB,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBACtC,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBAC3C,MAAM,aAAa,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC;gBAC/C,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,IAAI,CAAC,aAAa,EAAE;oBAC7C,OAAO,IAAI,CAAC;iBACb;gBAED,MAAM,MAAM,GAAG,IAAA,iCAAS,EAAC,WAAW,EAAE,aAAa,EAAE;oBACnD,aAAa,EAAE,IAAI;iBACpB,CAAC,CAAC;gBACH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;;;;;;GAMG;AACH,SAAgB,oCAAoC,CAClD,CAAsB,EACtB,YAA6B;IAE7B,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IACD,MAAM,mBAAmB,GACvB,IAAA,6CAAqC,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE9D,IAAI,CAAC,mBAAmB,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,WAAW,GAAkB,IAAI,CAAC;IACtC,IAAI;QACF,WAAW;YACT,8DAA8D;YAC9D,mBAAmB,EAAE,cAAc,EAAE,CAAC,CAAQ,CAAC;gBAC/C,mBAAmB,CAAC,kBAAkB;gBACtC,IAAI,CAAC;KACR;IAAC,MAAM;QACN,WAAW,GAAG,mBAAmB,CAAC,kBAAkB,IAAI,IAAI,CAAC;KAC9D;IAED,OAAO;QACL,KAAK,EAAE,mBAAmB,CAAC,KAAK,IAAI,EAAE;QACtC,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,mCAAmC;KACpE,CAAC;AACJ,CAAC;AA7BD,oFA6BC","sourcesContent":["import { getAmount, formatAmount } from './get-notification-data';\nimport type { Types } from '../../NotificationServicesController';\nimport { Constants } from '../../NotificationServicesController';\n\nexport type TranslationKeys = {\n pushPlatformNotificationsFundsSentTitle: () => string;\n pushPlatformNotificationsFundsSentDescriptionDefault: () => string;\n pushPlatformNotificationsFundsSentDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsFundsReceivedTitle: () => string;\n pushPlatformNotificationsFundsReceivedDescriptionDefault: () => string;\n pushPlatformNotificationsFundsReceivedDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsSwapCompletedTitle: () => string;\n pushPlatformNotificationsSwapCompletedDescription: () => string;\n pushPlatformNotificationsNftSentTitle: () => string;\n pushPlatformNotificationsNftSentDescription: () => string;\n pushPlatformNotificationsNftReceivedTitle: () => string;\n pushPlatformNotificationsNftReceivedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription: () => string;\n};\n\ntype PushNotificationMessage = {\n title: string;\n description: string;\n};\n\ntype NotificationMessage<N extends Types.INotification> = {\n title: string | null;\n defaultDescription: string | null;\n getDescription?: (n: N) => string | null;\n};\n\ntype NotificationMessageDict = {\n [K in Constants.TRIGGER_TYPES]?: NotificationMessage<\n Extract<Types.INotification, { type: K }>\n >;\n};\n\n/**\n * On Chain Push Notification Messages.\n * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension\n *\n * @param translationKeys - all translations supported\n * @returns A translation push message object.\n */\nexport const createOnChainPushNotificationMessages = (\n translationKeys: TranslationKeys,\n): NotificationMessageDict => {\n type TranslationFn = <K extends keyof TranslationKeys>(\n ...args: [K, ...Parameters<TranslationKeys[K]>]\n ) => string;\n const t: TranslationFn = (...args) => {\n const [key, ...otherArgs] = args;\n\n // Coerce types for the translation function\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const fn: any = translationKeys[key];\n return fn(...otherArgs);\n };\n\n return {\n erc20_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n eth_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n erc20_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n eth_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n metamask_swap_completed: {\n title: t('pushPlatformNotificationsSwapCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsSwapCompletedDescription',\n ),\n },\n erc721_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeCompletedDescription',\n ),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription',\n ),\n },\n lido_withdrawal_completed: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription',\n ),\n },\n };\n};\n\n/**\n * Retrieves the symbol associated with a given chain ID.\n *\n * @param chainId - The ID of the chain.\n * @returns The symbol associated with the chain ID, or null if not found.\n */\nfunction getChainSymbol(chainId: number) {\n return Constants.CHAIN_SYMBOLS[chainId] ?? null;\n}\n\n/**\n * Checks if the given value is an OnChainRawNotification object.\n *\n * @param n - The value to check.\n * @returns True if the value is an OnChainRawNotification object, false otherwise.\n */\nexport function isOnChainNotification(\n n: unknown,\n): n is Types.OnChainRawNotification {\n const assumed = n as Types.OnChainRawNotification;\n\n // We don't have a validation/parsing library to check all possible types of an on chain notification\n // It is safe enough just to check \"some\" fields, and catch any errors down the line if the shape is bad.\n const isValidEnoughToBeOnChainNotification = [\n assumed?.id,\n assumed?.data,\n assumed?.trigger_id,\n ].every((field) => field !== undefined);\n return isValidEnoughToBeOnChainNotification;\n}\n\n/**\n * Creates a push notification message based on the given on-chain raw notification.\n *\n * @param n - processed notification.\n * @param translations - translates keys into text\n * @returns The push notification message object, or null if the notification is invalid.\n */\nexport function createOnChainPushNotificationMessage(\n n: Types.INotification,\n translations: TranslationKeys,\n): PushNotificationMessage | null {\n if (!n?.type) {\n return null;\n }\n const notificationMessage =\n createOnChainPushNotificationMessages(translations)[n.type];\n\n if (!notificationMessage) {\n return null;\n }\n\n let description: string | null = null;\n try {\n description =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage?.getDescription?.(n as any) ??\n notificationMessage.defaultDescription ??\n null;\n } catch {\n description = notificationMessage.defaultDescription ?? null;\n }\n\n return {\n title: notificationMessage.title ?? '', // Ensure title is always a string\n description: description ?? '', // Fallback to empty string if null\n };\n}\n"]}
|
|
@@ -48,6 +48,13 @@ type NotificationMessageDict = {
|
|
|
48
48
|
* @returns A translation push message object.
|
|
49
49
|
*/
|
|
50
50
|
export declare const createOnChainPushNotificationMessages: (translationKeys: TranslationKeys) => NotificationMessageDict;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if the given value is an OnChainRawNotification object.
|
|
53
|
+
*
|
|
54
|
+
* @param n - The value to check.
|
|
55
|
+
* @returns True if the value is an OnChainRawNotification object, false otherwise.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isOnChainNotification(n: unknown): n is Types.OnChainRawNotification;
|
|
51
58
|
/**
|
|
52
59
|
* Creates a push notification message based on the given on-chain raw notification.
|
|
53
60
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-notification-message.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,uDAA6C;AAClE,OAAO,EAAE,SAAS,EAAE,uDAA6C;AAEjE,MAAM,MAAM,eAAe,GAAG;IAC5B,uCAAuC,EAAE,MAAM,MAAM,CAAC;IACtD,oDAAoD,EAAE,MAAM,MAAM,CAAC;IACnE,6CAA6C,EAAE,CAC7C,GAAG,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,KACtB,MAAM,CAAC;IACZ,2CAA2C,EAAE,MAAM,MAAM,CAAC;IAC1D,wDAAwD,EAAE,MAAM,MAAM,CAAC;IACvE,iDAAiD,EAAE,CACjD,GAAG,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,KACtB,MAAM,CAAC;IACZ,2CAA2C,EAAE,MAAM,MAAM,CAAC;IAC1D,iDAAiD,EAAE,MAAM,MAAM,CAAC;IAChE,qCAAqC,EAAE,MAAM,MAAM,CAAC;IACpD,2CAA2C,EAAE,MAAM,MAAM,CAAC;IAC1D,yCAAyC,EAAE,MAAM,MAAM,CAAC;IACxD,+CAA+C,EAAE,MAAM,MAAM,CAAC;IAC9D,6DAA6D,EAAE,MAAM,MAAM,CAAC;IAC5E,mEAAmE,EAAE,MAAM,MAAM,CAAC;IAClF,+DAA+D,EAAE,MAAM,MAAM,CAAC;IAC9E,qEAAqE,EAAE,MAAM,MAAM,CAAC;IACpF,uDAAuD,EAAE,MAAM,MAAM,CAAC;IACtE,6DAA6D,EAAE,MAAM,MAAM,CAAC;IAC5E,gEAAgE,EAAE,MAAM,MAAM,CAAC;IAC/E,sEAAsE,EAAE,MAAM,MAAM,CAAC;IACrF,4DAA4D,EAAE,MAAM,MAAM,CAAC;IAC3E,kEAAkE,EAAE,MAAM,MAAM,CAAC;IACjF,4DAA4D,EAAE,MAAM,MAAM,CAAC;IAC3E,kEAAkE,EAAE,MAAM,MAAM,CAAC;CAClF,CAAC;AAEF,KAAK,uBAAuB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,mBAAmB,CAAC,CAAC,SAAS,KAAK,CAAC,aAAa,IAAI;IACxD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;CAC1C,CAAC;AAEF,KAAK,uBAAuB,GAAG;KAC5B,CAAC,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,mBAAmB,CAClD,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAC1C;CACF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qCAAqC,oBAC/B,eAAe,KAC/B,uBAuKF,CAAC;AAYF;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,CAAC,EAAE,KAAK,CAAC,aAAa,EACtB,YAAY,EAAE,eAAe,GAC5B,uBAAuB,GAAG,IAAI,CA0BhC"}
|
|
1
|
+
{"version":3,"file":"get-notification-message.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,uDAA6C;AAClE,OAAO,EAAE,SAAS,EAAE,uDAA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AAK,CAAC,aAAa,IAAI;IACxD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;CAC1C,CAAC;AAEF,KAAK,uBAAuB,GAAG;KAC5B,CAAC,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,mBAAmB,CAClD,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAC1C;CACF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qCAAqC,oBAC/B,eAAe,KAC/B,uBAuKF,CAAC;AAYF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAWnC;AAED;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,CAAC,EAAE,KAAK,CAAC,aAAa,EACtB,YAAY,EAAE,eAAe,GAC5B,uBAAuB,GAAG,IAAI,CA0BhC"}
|
|
@@ -48,6 +48,13 @@ type NotificationMessageDict = {
|
|
|
48
48
|
* @returns A translation push message object.
|
|
49
49
|
*/
|
|
50
50
|
export declare const createOnChainPushNotificationMessages: (translationKeys: TranslationKeys) => NotificationMessageDict;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if the given value is an OnChainRawNotification object.
|
|
53
|
+
*
|
|
54
|
+
* @param n - The value to check.
|
|
55
|
+
* @returns True if the value is an OnChainRawNotification object, false otherwise.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isOnChainNotification(n: unknown): n is Types.OnChainRawNotification;
|
|
51
58
|
/**
|
|
52
59
|
* Creates a push notification message based on the given on-chain raw notification.
|
|
53
60
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-notification-message.d.mts","sourceRoot":"","sources":["../../../src/Not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,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,mBAAmB,CAAC,CAAC,SAAS,KAAK,CAAC,aAAa,IAAI;IACxD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;CAC1C,CAAC;AAEF,KAAK,uBAAuB,GAAG;KAC5B,CAAC,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,mBAAmB,CAClD,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAC1C;CACF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qCAAqC,oBAC/B,eAAe,KAC/B,uBAuKF,CAAC;AAYF;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,CAAC,EAAE,KAAK,CAAC,aAAa,EACtB,YAAY,EAAE,eAAe,GAC5B,uBAAuB,GAAG,IAAI,CA0BhC"}
|
|
1
|
+
{"version":3,"file":"get-notification-message.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,uDAA6C;AAClE,OAAO,EAAE,SAAS,EAAE,uDAA6C;AAEjE,MAAM,MAAM,eAAe,GAAG;IAC5B,uCAAuC,EAAE,MAAM,MAAM,CAAC;IACtD,oDAAoD,EAAE,MAAM,MAAM,CAAC;IACnE,6CAA6C,EAAE,CAC7C,GAAG,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,KACtB,MAAM,CAAC;IACZ,2CAA2C,EAAE,MAAM,MAAM,CAAC;IAC1D,wDAAwD,EAAE,MAAM,MAAM,CAAC;IACvE,iDAAiD,EAAE,CACjD,GAAG,IA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,aAAa,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAC1C;CACF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qCAAqC,oBAC/B,eAAe,KAC/B,uBAuKF,CAAC;AAYF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAWnC;AAED;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,CAAC,EAAE,KAAK,CAAC,aAAa,EACtB,YAAY,EAAE,eAAe,GAC5B,uBAAuB,GAAG,IAAI,CA0BhC"}
|
|
@@ -133,6 +133,23 @@ export const createOnChainPushNotificationMessages = (translationKeys) => {
|
|
|
133
133
|
function getChainSymbol(chainId) {
|
|
134
134
|
return Constants.CHAIN_SYMBOLS[chainId] ?? null;
|
|
135
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Checks if the given value is an OnChainRawNotification object.
|
|
138
|
+
*
|
|
139
|
+
* @param n - The value to check.
|
|
140
|
+
* @returns True if the value is an OnChainRawNotification object, false otherwise.
|
|
141
|
+
*/
|
|
142
|
+
export function isOnChainNotification(n) {
|
|
143
|
+
const assumed = n;
|
|
144
|
+
// We don't have a validation/parsing library to check all possible types of an on chain notification
|
|
145
|
+
// It is safe enough just to check "some" fields, and catch any errors down the line if the shape is bad.
|
|
146
|
+
const isValidEnoughToBeOnChainNotification = [
|
|
147
|
+
assumed?.id,
|
|
148
|
+
assumed?.data,
|
|
149
|
+
assumed?.trigger_id,
|
|
150
|
+
].every((field) => field !== undefined);
|
|
151
|
+
return isValidEnoughToBeOnChainNotification;
|
|
152
|
+
}
|
|
136
153
|
/**
|
|
137
154
|
* Creates a push notification message based on the given on-chain raw notification.
|
|
138
155
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-notification-message.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":"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IAAI,EAAE;QACtC,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,mCAAmC;KACpE,CAAC;AACJ,CAAC","sourcesContent":["import { getAmount, formatAmount } from './get-notification-data';\nimport type { Types } from '../../NotificationServicesController';\nimport { Constants } from '../../NotificationServicesController';\n\nexport type TranslationKeys = {\n pushPlatformNotificationsFundsSentTitle: () => string;\n pushPlatformNotificationsFundsSentDescriptionDefault: () => string;\n pushPlatformNotificationsFundsSentDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsFundsReceivedTitle: () => string;\n pushPlatformNotificationsFundsReceivedDescriptionDefault: () => string;\n pushPlatformNotificationsFundsReceivedDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsSwapCompletedTitle: () => string;\n pushPlatformNotificationsSwapCompletedDescription: () => string;\n pushPlatformNotificationsNftSentTitle: () => string;\n pushPlatformNotificationsNftSentDescription: () => string;\n pushPlatformNotificationsNftReceivedTitle: () => string;\n pushPlatformNotificationsNftReceivedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription: () => string;\n};\n\ntype PushNotificationMessage = {\n title: string;\n description: string;\n};\n\ntype NotificationMessage<N extends Types.INotification> = {\n title: string | null;\n defaultDescription: string | null;\n getDescription?: (n: N) => string | null;\n};\n\ntype NotificationMessageDict = {\n [K in Constants.TRIGGER_TYPES]?: NotificationMessage<\n Extract<Types.INotification, { type: K }>\n >;\n};\n\n/**\n * On Chain Push Notification Messages.\n * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension\n *\n * @param translationKeys - all translations supported\n * @returns A translation push message object.\n */\nexport const createOnChainPushNotificationMessages = (\n translationKeys: TranslationKeys,\n): NotificationMessageDict => {\n type TranslationFn = <K extends keyof TranslationKeys>(\n ...args: [K, ...Parameters<TranslationKeys[K]>]\n ) => string;\n const t: TranslationFn = (...args) => {\n const [key, ...otherArgs] = args;\n\n // Coerce types for the translation function\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const fn: any = translationKeys[key];\n return fn(...otherArgs);\n };\n\n return {\n erc20_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n eth_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n erc20_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n eth_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n metamask_swap_completed: {\n title: t('pushPlatformNotificationsSwapCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsSwapCompletedDescription',\n ),\n },\n erc721_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeCompletedDescription',\n ),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription',\n ),\n },\n lido_withdrawal_completed: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription',\n ),\n },\n };\n};\n\n/**\n * Retrieves the symbol associated with a given chain ID.\n *\n * @param chainId - The ID of the chain.\n * @returns The symbol associated with the chain ID, or null if not found.\n */\nfunction getChainSymbol(chainId: number) {\n return Constants.CHAIN_SYMBOLS[chainId] ?? null;\n}\n\n/**\n * Creates a push notification message based on the given on-chain raw notification.\n *\n * @param n - processed notification.\n * @param translations - translates keys into text\n * @returns The push notification message object, or null if the notification is invalid.\n */\nexport function createOnChainPushNotificationMessage(\n n: Types.INotification,\n translations: TranslationKeys,\n): PushNotificationMessage | null {\n if (!n?.type) {\n return null;\n }\n const notificationMessage =\n createOnChainPushNotificationMessages(translations)[n.type];\n\n if (!notificationMessage) {\n return null;\n }\n\n let description: string | null = null;\n try {\n description =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage?.getDescription?.(n as any) ??\n notificationMessage.defaultDescription ??\n null;\n } catch {\n description = notificationMessage.defaultDescription ?? null;\n }\n\n return {\n title: notificationMessage.title ?? '', // Ensure title is always a string\n description: description ?? '', // Fallback to empty string if null\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"get-notification-message.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,oCAAgC;AAElE,OAAO,EAAE,SAAS,EAAE,uDAA6C;AAkDjE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,CACnD,eAAgC,EACP,EAAE;IAI3B,MAAM,CAAC,GAAkB,CAAC,GAAG,IAAI,EAAE,EAAE;QACnC,MAAM,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;QAEjC,4CAA4C;QAC5C,8DAA8D;QAC9D,MAAM,EAAE,GAAQ,eAAe,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE;YACV,KAAK,EAAE,CAAC,CAAC,yCAAyC,CAAC;YACnD,kBAAkB,EAAE,CAAC,CACnB,sDAAsD,CACvD;YACD,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;gBACpB,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBACtC,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBAC3C,MAAM,aAAa,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC;gBAC/C,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,IAAI,CAAC,aAAa,EAAE;oBAC7C,OAAO,IAAI,CAAC;iBACb;gBAED,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,aAAa,EAAE;oBACnD,aAAa,EAAE,IAAI;iBACpB,CAAC,CAAC;gBACH,OAAO,CAAC,CACN,+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C,CAAC,EAAE,IAAI,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IACD,MAAM,mBAAmB,GACvB,qCAAqC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE9D,IAAI,CAAC,mBAAmB,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,WAAW,GAAkB,IAAI,CAAC;IACtC,IAAI;QACF,WAAW;YACT,8DAA8D;YAC9D,mBAAmB,EAAE,cAAc,EAAE,CAAC,CAAQ,CAAC;gBAC/C,mBAAmB,CAAC,kBAAkB;gBACtC,IAAI,CAAC;KACR;IAAC,MAAM;QACN,WAAW,GAAG,mBAAmB,CAAC,kBAAkB,IAAI,IAAI,CAAC;KAC9D;IAED,OAAO;QACL,KAAK,EAAE,mBAAmB,CAAC,KAAK,IAAI,EAAE;QACtC,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,mCAAmC;KACpE,CAAC;AACJ,CAAC","sourcesContent":["import { getAmount, formatAmount } from './get-notification-data';\nimport type { Types } from '../../NotificationServicesController';\nimport { Constants } from '../../NotificationServicesController';\n\nexport type TranslationKeys = {\n pushPlatformNotificationsFundsSentTitle: () => string;\n pushPlatformNotificationsFundsSentDescriptionDefault: () => string;\n pushPlatformNotificationsFundsSentDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsFundsReceivedTitle: () => string;\n pushPlatformNotificationsFundsReceivedDescriptionDefault: () => string;\n pushPlatformNotificationsFundsReceivedDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsSwapCompletedTitle: () => string;\n pushPlatformNotificationsSwapCompletedDescription: () => string;\n pushPlatformNotificationsNftSentTitle: () => string;\n pushPlatformNotificationsNftSentDescription: () => string;\n pushPlatformNotificationsNftReceivedTitle: () => string;\n pushPlatformNotificationsNftReceivedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription: () => string;\n};\n\ntype PushNotificationMessage = {\n title: string;\n description: string;\n};\n\ntype NotificationMessage<N extends Types.INotification> = {\n title: string | null;\n defaultDescription: string | null;\n getDescription?: (n: N) => string | null;\n};\n\ntype NotificationMessageDict = {\n [K in Constants.TRIGGER_TYPES]?: NotificationMessage<\n Extract<Types.INotification, { type: K }>\n >;\n};\n\n/**\n * On Chain Push Notification Messages.\n * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension\n *\n * @param translationKeys - all translations supported\n * @returns A translation push message object.\n */\nexport const createOnChainPushNotificationMessages = (\n translationKeys: TranslationKeys,\n): NotificationMessageDict => {\n type TranslationFn = <K extends keyof TranslationKeys>(\n ...args: [K, ...Parameters<TranslationKeys[K]>]\n ) => string;\n const t: TranslationFn = (...args) => {\n const [key, ...otherArgs] = args;\n\n // Coerce types for the translation function\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const fn: any = translationKeys[key];\n return fn(...otherArgs);\n };\n\n return {\n erc20_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n eth_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n erc20_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n eth_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n metamask_swap_completed: {\n title: t('pushPlatformNotificationsSwapCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsSwapCompletedDescription',\n ),\n },\n erc721_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeCompletedDescription',\n ),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription',\n ),\n },\n lido_withdrawal_completed: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription',\n ),\n },\n };\n};\n\n/**\n * Retrieves the symbol associated with a given chain ID.\n *\n * @param chainId - The ID of the chain.\n * @returns The symbol associated with the chain ID, or null if not found.\n */\nfunction getChainSymbol(chainId: number) {\n return Constants.CHAIN_SYMBOLS[chainId] ?? null;\n}\n\n/**\n * Checks if the given value is an OnChainRawNotification object.\n *\n * @param n - The value to check.\n * @returns True if the value is an OnChainRawNotification object, false otherwise.\n */\nexport function isOnChainNotification(\n n: unknown,\n): n is Types.OnChainRawNotification {\n const assumed = n as Types.OnChainRawNotification;\n\n // We don't have a validation/parsing library to check all possible types of an on chain notification\n // It is safe enough just to check \"some\" fields, and catch any errors down the line if the shape is bad.\n const isValidEnoughToBeOnChainNotification = [\n assumed?.id,\n assumed?.data,\n assumed?.trigger_id,\n ].every((field) => field !== undefined);\n return isValidEnoughToBeOnChainNotification;\n}\n\n/**\n * Creates a push notification message based on the given on-chain raw notification.\n *\n * @param n - processed notification.\n * @param translations - translates keys into text\n * @returns The push notification message object, or null if the notification is invalid.\n */\nexport function createOnChainPushNotificationMessage(\n n: Types.INotification,\n translations: TranslationKeys,\n): PushNotificationMessage | null {\n if (!n?.type) {\n return null;\n }\n const notificationMessage =\n createOnChainPushNotificationMessages(translations)[n.type];\n\n if (!notificationMessage) {\n return null;\n }\n\n let description: string | null = null;\n try {\n description =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage?.getDescription?.(n as any) ??\n notificationMessage.defaultDescription ??\n null;\n } catch {\n description = notificationMessage.defaultDescription ?? null;\n }\n\n return {\n title: notificationMessage.title ?? '', // Ensure title is always a string\n description: description ?? '', // Fallback to empty string if null\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/notification-services-controller",
|
|
3
|
-
"version": "0.21.0-preview-
|
|
3
|
+
"version": "0.21.0-preview-a1eb992b",
|
|
4
4
|
"description": "Manages New MetaMask decentralized Notification system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -67,16 +67,6 @@
|
|
|
67
67
|
"default": "./dist/NotificationServicesPushController/index.cjs"
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
|
-
"./push-services/web": {
|
|
71
|
-
"import": {
|
|
72
|
-
"types": "./dist/NotificationServicesPushController/web/index.d.mts",
|
|
73
|
-
"default": "./dist/NotificationServicesPushController/web/index.mjs"
|
|
74
|
-
},
|
|
75
|
-
"require": {
|
|
76
|
-
"types": "./dist/NotificationServicesPushController/web/index.d.cts",
|
|
77
|
-
"default": "./dist/NotificationServicesPushController/web/index.cjs"
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
70
|
"./push-services/mocks": {
|
|
81
71
|
"import": {
|
|
82
72
|
"types": "./dist/NotificationServicesPushController/__fixtures__/index.d.mts",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildPushPlatformNotificationsControllerMessenger = void 0;
|
|
4
|
-
const base_controller_1 = require("@metamask/base-controller");
|
|
5
|
-
const buildPushPlatformNotificationsControllerMessenger = () => {
|
|
6
|
-
const globalMessenger = new base_controller_1.Messenger();
|
|
7
|
-
return globalMessenger.getRestricted({
|
|
8
|
-
name: 'NotificationServicesPushController',
|
|
9
|
-
allowedActions: ['AuthenticationController:getBearerToken'],
|
|
10
|
-
allowedEvents: [],
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
exports.buildPushPlatformNotificationsControllerMessenger = buildPushPlatformNotificationsControllerMessenger;
|
|
14
|
-
//# sourceMappingURL=mockMessenger.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockMessenger.ts"],"names":[],"mappings":";;;AAAA,+DAAsD;AAQ/C,MAAM,iDAAiD,GAC5D,GAAgD,EAAE;IAChD,MAAM,eAAe,GAAG,IAAI,2BAAS,EAAiC,CAAC;IAEvE,OAAO,eAAe,CAAC,aAAa,CAGlC;QACA,IAAI,EAAE,oCAAoC;QAC1C,cAAc,EAAE,CAAC,yCAAyC,CAAC;QAC3D,aAAa,EAAE,EAAE;KAClB,CAAC,CAAC;AACL,CAAC,CAAC;AAZS,QAAA,iDAAiD,qDAY1D","sourcesContent":["import { Messenger } from '@metamask/base-controller';\n\nimport type {\n AllowedActions,\n AllowedEvents,\n NotificationServicesPushControllerMessenger,\n} from '..';\n\nexport const buildPushPlatformNotificationsControllerMessenger =\n (): NotificationServicesPushControllerMessenger => {\n const globalMessenger = new Messenger<AllowedActions, AllowedEvents>();\n\n return globalMessenger.getRestricted<\n 'NotificationServicesPushController',\n AllowedActions['type']\n >({\n name: 'NotificationServicesPushController',\n allowedActions: ['AuthenticationController:getBearerToken'],\n allowedEvents: [],\n });\n };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockMessenger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,2CAA2C,EAC5C,qBAAW;AAEZ,eAAO,MAAM,iDAAiD,mDAY3D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockMessenger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,2CAA2C,EAC5C,qBAAW;AAEZ,eAAO,MAAM,iDAAiD,mDAY3D,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Messenger } from "@metamask/base-controller";
|
|
2
|
-
export const buildPushPlatformNotificationsControllerMessenger = () => {
|
|
3
|
-
const globalMessenger = new Messenger();
|
|
4
|
-
return globalMessenger.getRestricted({
|
|
5
|
-
name: 'NotificationServicesPushController',
|
|
6
|
-
allowedActions: ['AuthenticationController:getBearerToken'],
|
|
7
|
-
allowedEvents: [],
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=mockMessenger.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockMessenger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAQtD,MAAM,CAAC,MAAM,iDAAiD,GAC5D,GAAgD,EAAE;IAChD,MAAM,eAAe,GAAG,IAAI,SAAS,EAAiC,CAAC;IAEvE,OAAO,eAAe,CAAC,aAAa,CAGlC;QACA,IAAI,EAAE,oCAAoC;QAC1C,cAAc,EAAE,CAAC,yCAAyC,CAAC;QAC3D,aAAa,EAAE,EAAE;KAClB,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { Messenger } from '@metamask/base-controller';\n\nimport type {\n AllowedActions,\n AllowedEvents,\n NotificationServicesPushControllerMessenger,\n} from '..';\n\nexport const buildPushPlatformNotificationsControllerMessenger =\n (): NotificationServicesPushControllerMessenger => {\n const globalMessenger = new Messenger<AllowedActions, AllowedEvents>();\n\n return globalMessenger.getRestricted<\n 'NotificationServicesPushController',\n AllowedActions['type']\n >({\n name: 'NotificationServicesPushController',\n allowedActions: ['AuthenticationController:getBearerToken'],\n allowedEvents: [],\n });\n };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-service-interface.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/push-service-interface.ts"],"names":[],"mappings":"","sourcesContent":["import type { PushNotificationEnv } from '.';\n\ntype Unsubscribe = () => void;\n\n/**\n * Firebase - allows creating of a registration token for push notifications\n */\nexport type CreateRegToken = (\n env: PushNotificationEnv,\n) => Promise<string | null>;\n\n/**\n * Firebase - allows deleting a reg token. Returns true if successful, otherwise false if failed\n */\nexport type DeleteRegToken = (env: PushNotificationEnv) => Promise<boolean>;\n\n/**\n * Firebase + Platform Specific Logic.\n * Will be used to subscribe to the `onMessage` and `onBackgroundMessage` handlers\n * But will also need client specific logic for showing a notification and clicking a notification\n * (browser APIs for web, and Notifee on mobile)\n *\n * We can either create \"creator\"/\"builder\" function in platform specific files (see push-web.ts),\n * Or the platform needs to correctly handle:\n * - subscriptions\n * - click events\n * - publishing PushController events using it's messenger\n */\nexport type SubscribeToPushNotifications = (\n env: PushNotificationEnv,\n) => Promise<Unsubscribe | null>;\n\nexport type PushService = {\n createRegToken: CreateRegToken;\n\n deleteRegToken: DeleteRegToken;\n\n subscribeToPushNotifications: SubscribeToPushNotifications;\n};\n"]}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { PushNotificationEnv } from "./index.cjs";
|
|
2
|
-
type Unsubscribe = () => void;
|
|
3
|
-
/**
|
|
4
|
-
* Firebase - allows creating of a registration token for push notifications
|
|
5
|
-
*/
|
|
6
|
-
export type CreateRegToken = (env: PushNotificationEnv) => Promise<string | null>;
|
|
7
|
-
/**
|
|
8
|
-
* Firebase - allows deleting a reg token. Returns true if successful, otherwise false if failed
|
|
9
|
-
*/
|
|
10
|
-
export type DeleteRegToken = (env: PushNotificationEnv) => Promise<boolean>;
|
|
11
|
-
/**
|
|
12
|
-
* Firebase + Platform Specific Logic.
|
|
13
|
-
* Will be used to subscribe to the `onMessage` and `onBackgroundMessage` handlers
|
|
14
|
-
* But will also need client specific logic for showing a notification and clicking a notification
|
|
15
|
-
* (browser APIs for web, and Notifee on mobile)
|
|
16
|
-
*
|
|
17
|
-
* We can either create "creator"/"builder" function in platform specific files (see push-web.ts),
|
|
18
|
-
* Or the platform needs to correctly handle:
|
|
19
|
-
* - subscriptions
|
|
20
|
-
* - click events
|
|
21
|
-
* - publishing PushController events using it's messenger
|
|
22
|
-
*/
|
|
23
|
-
export type SubscribeToPushNotifications = (env: PushNotificationEnv) => Promise<Unsubscribe | null>;
|
|
24
|
-
export type PushService = {
|
|
25
|
-
createRegToken: CreateRegToken;
|
|
26
|
-
deleteRegToken: DeleteRegToken;
|
|
27
|
-
subscribeToPushNotifications: SubscribeToPushNotifications;
|
|
28
|
-
};
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=push-service-interface.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-service-interface.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/push-service-interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAU;AAE7C,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,GAAG,EAAE,mBAAmB,KACrB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE5E;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4BAA4B,GAAG,CACzC,GAAG,EAAE,mBAAmB,KACrB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEjC,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,EAAE,cAAc,CAAC;IAE/B,cAAc,EAAE,cAAc,CAAC;IAE/B,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { PushNotificationEnv } from "./index.mjs";
|
|
2
|
-
type Unsubscribe = () => void;
|
|
3
|
-
/**
|
|
4
|
-
* Firebase - allows creating of a registration token for push notifications
|
|
5
|
-
*/
|
|
6
|
-
export type CreateRegToken = (env: PushNotificationEnv) => Promise<string | null>;
|
|
7
|
-
/**
|
|
8
|
-
* Firebase - allows deleting a reg token. Returns true if successful, otherwise false if failed
|
|
9
|
-
*/
|
|
10
|
-
export type DeleteRegToken = (env: PushNotificationEnv) => Promise<boolean>;
|
|
11
|
-
/**
|
|
12
|
-
* Firebase + Platform Specific Logic.
|
|
13
|
-
* Will be used to subscribe to the `onMessage` and `onBackgroundMessage` handlers
|
|
14
|
-
* But will also need client specific logic for showing a notification and clicking a notification
|
|
15
|
-
* (browser APIs for web, and Notifee on mobile)
|
|
16
|
-
*
|
|
17
|
-
* We can either create "creator"/"builder" function in platform specific files (see push-web.ts),
|
|
18
|
-
* Or the platform needs to correctly handle:
|
|
19
|
-
* - subscriptions
|
|
20
|
-
* - click events
|
|
21
|
-
* - publishing PushController events using it's messenger
|
|
22
|
-
*/
|
|
23
|
-
export type SubscribeToPushNotifications = (env: PushNotificationEnv) => Promise<Unsubscribe | null>;
|
|
24
|
-
export type PushService = {
|
|
25
|
-
createRegToken: CreateRegToken;
|
|
26
|
-
deleteRegToken: DeleteRegToken;
|
|
27
|
-
subscribeToPushNotifications: SubscribeToPushNotifications;
|
|
28
|
-
};
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=push-service-interface.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-service-interface.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/push-service-interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAU;AAE7C,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,GAAG,EAAE,mBAAmB,KACrB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE5E;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4BAA4B,GAAG,CACzC,GAAG,EAAE,mBAAmB,KACrB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEjC,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,EAAE,cAAc,CAAC;IAE/B,cAAc,EAAE,cAAc,CAAC;IAE/B,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-service-interface.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/push-service-interface.ts"],"names":[],"mappings":"","sourcesContent":["import type { PushNotificationEnv } from '.';\n\ntype Unsubscribe = () => void;\n\n/**\n * Firebase - allows creating of a registration token for push notifications\n */\nexport type CreateRegToken = (\n env: PushNotificationEnv,\n) => Promise<string | null>;\n\n/**\n * Firebase - allows deleting a reg token. Returns true if successful, otherwise false if failed\n */\nexport type DeleteRegToken = (env: PushNotificationEnv) => Promise<boolean>;\n\n/**\n * Firebase + Platform Specific Logic.\n * Will be used to subscribe to the `onMessage` and `onBackgroundMessage` handlers\n * But will also need client specific logic for showing a notification and clicking a notification\n * (browser APIs for web, and Notifee on mobile)\n *\n * We can either create \"creator\"/\"builder\" function in platform specific files (see push-web.ts),\n * Or the platform needs to correctly handle:\n * - subscriptions\n * - click events\n * - publishing PushController events using it's messenger\n */\nexport type SubscribeToPushNotifications = (\n env: PushNotificationEnv,\n) => Promise<Unsubscribe | null>;\n\nexport type PushService = {\n createRegToken: CreateRegToken;\n\n deleteRegToken: DeleteRegToken;\n\n subscribeToPushNotifications: SubscribeToPushNotifications;\n};\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSubscribeToPushNotifications = exports.deleteRegToken = exports.createRegToken = void 0;
|
|
4
|
-
var push_utils_1 = require("./push-utils.cjs");
|
|
5
|
-
Object.defineProperty(exports, "createRegToken", { enumerable: true, get: function () { return push_utils_1.createRegToken; } });
|
|
6
|
-
Object.defineProperty(exports, "deleteRegToken", { enumerable: true, get: function () { return push_utils_1.deleteRegToken; } });
|
|
7
|
-
Object.defineProperty(exports, "createSubscribeToPushNotifications", { enumerable: true, get: function () { return push_utils_1.createSubscribeToPushNotifications; } });
|
|
8
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/index.ts"],"names":[],"mappings":";;;AAAA,+CAIsB;AAHpB,4GAAA,cAAc,OAAA;AACd,4GAAA,cAAc,OAAA;AACd,gIAAA,kCAAkC,OAAA","sourcesContent":["export {\n createRegToken,\n deleteRegToken,\n createSubscribeToPushNotifications,\n} from './push-utils';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,kCAAkC,GACnC,yBAAqB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,kCAAkC,GACnC,yBAAqB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,kCAAkC,EACnC,yBAAqB","sourcesContent":["export {\n createRegToken,\n deleteRegToken,\n createSubscribeToPushNotifications,\n} from './push-utils';\n"]}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createSubscribeToPushNotifications = exports.deleteRegToken = exports.createRegToken = exports.supportedCache = void 0;
|
|
7
|
-
const app_1 = require("firebase/app");
|
|
8
|
-
const messaging_1 = require("firebase/messaging");
|
|
9
|
-
const sw_1 = require("firebase/messaging/sw");
|
|
10
|
-
const loglevel_1 = __importDefault(require("loglevel"));
|
|
11
|
-
const NotificationServicesController_1 = require("../../NotificationServicesController/index.cjs");
|
|
12
|
-
const to_raw_notification_1 = require("../../shared/to-raw-notification.cjs");
|
|
13
|
-
// Exported to help testing
|
|
14
|
-
// eslint-disable-next-line import-x/no-mutable-exports
|
|
15
|
-
exports.supportedCache = null;
|
|
16
|
-
const getPushAvailability = async () => {
|
|
17
|
-
exports.supportedCache ?? (exports.supportedCache = await (0, sw_1.isSupported)());
|
|
18
|
-
return exports.supportedCache;
|
|
19
|
-
};
|
|
20
|
-
const createFirebaseApp = async (env) => {
|
|
21
|
-
try {
|
|
22
|
-
return (0, app_1.getApp)();
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
const firebaseConfig = {
|
|
26
|
-
apiKey: env.apiKey,
|
|
27
|
-
authDomain: env.authDomain,
|
|
28
|
-
storageBucket: env.storageBucket,
|
|
29
|
-
projectId: env.projectId,
|
|
30
|
-
messagingSenderId: env.messagingSenderId,
|
|
31
|
-
appId: env.appId,
|
|
32
|
-
measurementId: env.measurementId,
|
|
33
|
-
};
|
|
34
|
-
return (0, app_1.initializeApp)(firebaseConfig);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const getFirebaseMessaging = async (env) => {
|
|
38
|
-
const supported = await getPushAvailability();
|
|
39
|
-
if (!supported) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
const app = await createFirebaseApp(env);
|
|
43
|
-
return (0, sw_1.getMessaging)(app);
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Creates a registration token for Firebase Cloud Messaging.
|
|
47
|
-
*
|
|
48
|
-
* @param env - env to configure push notifications
|
|
49
|
-
* @returns A promise that resolves with the registration token or null if an error occurs.
|
|
50
|
-
*/
|
|
51
|
-
async function createRegToken(env) {
|
|
52
|
-
try {
|
|
53
|
-
const messaging = await getFirebaseMessaging(env);
|
|
54
|
-
if (!messaging) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
const token = await (0, messaging_1.getToken)(messaging, {
|
|
58
|
-
serviceWorkerRegistration: self.registration,
|
|
59
|
-
vapidKey: env.vapidKey,
|
|
60
|
-
});
|
|
61
|
-
return token;
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.createRegToken = createRegToken;
|
|
68
|
-
/**
|
|
69
|
-
* Deletes the Firebase Cloud Messaging registration token.
|
|
70
|
-
*
|
|
71
|
-
* @param env - env to configure push notifications
|
|
72
|
-
* @returns A promise that resolves with true if the token was successfully deleted, false otherwise.
|
|
73
|
-
*/
|
|
74
|
-
async function deleteRegToken(env) {
|
|
75
|
-
try {
|
|
76
|
-
const messaging = await getFirebaseMessaging(env);
|
|
77
|
-
if (!messaging) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
await (0, messaging_1.deleteToken)(messaging);
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.deleteRegToken = deleteRegToken;
|
|
88
|
-
/**
|
|
89
|
-
* Service Worker Listener for when push notifications are received.
|
|
90
|
-
*
|
|
91
|
-
* @param env - push notification environment
|
|
92
|
-
* @param handler - handler to actually showing notification, MUST BE PROVIDED
|
|
93
|
-
* @returns unsubscribe handler
|
|
94
|
-
*/
|
|
95
|
-
async function listenToPushNotificationsReceived(env, handler) {
|
|
96
|
-
const messaging = await getFirebaseMessaging(env);
|
|
97
|
-
if (!messaging) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const unsubscribePushNotifications = (0, sw_1.onBackgroundMessage)(messaging,
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
102
|
-
async (payload) => {
|
|
103
|
-
try {
|
|
104
|
-
const data = payload?.data?.data ? JSON.parse(payload?.data?.data) : undefined;
|
|
105
|
-
if (!data) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const notificationData = (0, to_raw_notification_1.toRawOnChainNotification)(data);
|
|
109
|
-
const notification = NotificationServicesController_1.Processors.processNotification(notificationData);
|
|
110
|
-
await handler(notification);
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
// Do Nothing, cannot parse a bad notification
|
|
114
|
-
loglevel_1.default.error('Unable to send push notification:', {
|
|
115
|
-
notification: payload?.data?.data,
|
|
116
|
-
error,
|
|
117
|
-
});
|
|
118
|
-
throw new Error('Unable to send push notification');
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
const unsubscribe = () => unsubscribePushNotifications();
|
|
122
|
-
return unsubscribe;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Service Worker Listener for when a notification is clicked
|
|
126
|
-
*
|
|
127
|
-
* @param handler - listen to NotificationEvent from the service worker
|
|
128
|
-
* @returns unsubscribe handler
|
|
129
|
-
*/
|
|
130
|
-
function listenToPushNotificationsClicked(handler) {
|
|
131
|
-
const clickHandler = (event) => {
|
|
132
|
-
// Get Data
|
|
133
|
-
const data = event?.notification?.data;
|
|
134
|
-
handler(event, data);
|
|
135
|
-
};
|
|
136
|
-
self.addEventListener('notificationclick', clickHandler);
|
|
137
|
-
const unsubscribe = () => self.removeEventListener('notificationclick', clickHandler);
|
|
138
|
-
return unsubscribe;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* A creator function that assists creating web-specific push notification subscription:
|
|
142
|
-
* 1. Creates subscriptions for receiving and clicking notifications
|
|
143
|
-
* 2. Creates click events when a notification is clicked
|
|
144
|
-
* 3. Publishes controller messenger events
|
|
145
|
-
*
|
|
146
|
-
* @param props - props for this creator function.
|
|
147
|
-
* @param props.onReceivedHandler - allows the developer to handle showing a notification
|
|
148
|
-
* @param props.onClickHandler - allows the developer to handle clicking the notification
|
|
149
|
-
* @param props.messenger - the controller messenger to publish the `onNewNotifications` and `pushNotificationsClicked` events
|
|
150
|
-
* @returns a function that can be used by the controller
|
|
151
|
-
*/
|
|
152
|
-
function createSubscribeToPushNotifications(props) {
|
|
153
|
-
return async function (env) {
|
|
154
|
-
const onBackgroundMessageSub = await listenToPushNotificationsReceived(env, async (notification) => {
|
|
155
|
-
props.messenger.publish('NotificationServicesPushController:onNewNotifications', notification);
|
|
156
|
-
await props.onReceivedHandler(notification);
|
|
157
|
-
});
|
|
158
|
-
const onClickSub = listenToPushNotificationsClicked((event, notification) => {
|
|
159
|
-
props.messenger.publish('NotificationServicesPushController:pushNotificationClicked', notification);
|
|
160
|
-
props.onClickHandler(event, notification);
|
|
161
|
-
});
|
|
162
|
-
const unsubscribe = () => {
|
|
163
|
-
onBackgroundMessageSub?.();
|
|
164
|
-
onClickSub();
|
|
165
|
-
};
|
|
166
|
-
return unsubscribe;
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
exports.createSubscribeToPushNotifications = createSubscribeToPushNotifications;
|
|
170
|
-
//# sourceMappingURL=push-utils.cjs.map
|