@metamask/notification-services-controller 21.0.0 → 22.1.0

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 (193) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +56 -42
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts +3 -2
  5. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts +3 -2
  7. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/NotificationServicesController.mjs +56 -41
  9. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  10. package/dist/NotificationServicesController/constants/notification-schema.cjs +4 -12
  11. package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
  12. package/dist/NotificationServicesController/constants/notification-schema.d.cts +0 -12
  13. package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
  14. package/dist/NotificationServicesController/constants/notification-schema.d.mts +0 -12
  15. package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
  16. package/dist/NotificationServicesController/constants/notification-schema.mjs +3 -11
  17. package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
  18. package/dist/NotificationServicesController/index.cjs +1 -2
  19. package/dist/NotificationServicesController/index.cjs.map +1 -1
  20. package/dist/NotificationServicesController/index.d.cts +0 -1
  21. package/dist/NotificationServicesController/index.d.cts.map +1 -1
  22. package/dist/NotificationServicesController/index.d.mts +0 -1
  23. package/dist/NotificationServicesController/index.d.mts.map +1 -1
  24. package/dist/NotificationServicesController/index.mjs +0 -1
  25. package/dist/NotificationServicesController/index.mjs.map +1 -1
  26. package/dist/NotificationServicesController/mocks/mock-feature-announcements.cjs +2 -2
  27. package/dist/NotificationServicesController/mocks/mock-feature-announcements.cjs.map +1 -1
  28. package/dist/NotificationServicesController/mocks/mock-feature-announcements.d.cts.map +1 -1
  29. package/dist/NotificationServicesController/mocks/mock-feature-announcements.d.mts.map +1 -1
  30. package/dist/NotificationServicesController/mocks/mock-feature-announcements.mjs +2 -2
  31. package/dist/NotificationServicesController/mocks/mock-feature-announcements.mjs.map +1 -1
  32. package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs +120 -0
  33. package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs.map +1 -1
  34. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts.map +1 -1
  35. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts.map +1 -1
  36. package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs +120 -0
  37. package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs.map +1 -1
  38. package/dist/NotificationServicesController/mocks/mock-snap-notification.cjs.map +1 -1
  39. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.cts +1 -1
  40. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.cts.map +1 -1
  41. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.mts +1 -1
  42. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.mts.map +1 -1
  43. package/dist/NotificationServicesController/mocks/mock-snap-notification.mjs.map +1 -1
  44. package/dist/NotificationServicesController/mocks/mockResponses.cjs +6 -0
  45. package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
  46. package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
  47. package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
  48. package/dist/NotificationServicesController/mocks/mockResponses.mjs +6 -0
  49. package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
  50. package/dist/NotificationServicesController/processors/process-notifications.cjs +11 -9
  51. package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
  52. package/dist/NotificationServicesController/processors/process-notifications.d.cts +1 -563
  53. package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
  54. package/dist/NotificationServicesController/processors/process-notifications.d.mts +1 -563
  55. package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
  56. package/dist/NotificationServicesController/processors/process-notifications.mjs +11 -9
  57. package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
  58. package/dist/NotificationServicesController/processors/process-snap-notifications.cjs.map +1 -1
  59. package/dist/NotificationServicesController/processors/process-snap-notifications.d.cts +1 -1
  60. package/dist/NotificationServicesController/processors/process-snap-notifications.d.cts.map +1 -1
  61. package/dist/NotificationServicesController/processors/process-snap-notifications.d.mts +1 -1
  62. package/dist/NotificationServicesController/processors/process-snap-notifications.d.mts.map +1 -1
  63. package/dist/NotificationServicesController/processors/process-snap-notifications.mjs.map +1 -1
  64. package/dist/NotificationServicesController/services/api-notifications.cjs +21 -21
  65. package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
  66. package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -1
  67. package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -1
  68. package/dist/NotificationServicesController/services/api-notifications.mjs +21 -21
  69. package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
  70. package/dist/NotificationServicesController/services/feature-announcements.cjs +19 -10
  71. package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
  72. package/dist/NotificationServicesController/services/feature-announcements.d.cts.map +1 -1
  73. package/dist/NotificationServicesController/services/feature-announcements.d.mts.map +1 -1
  74. package/dist/NotificationServicesController/services/feature-announcements.mjs +19 -10
  75. package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
  76. package/dist/NotificationServicesController/services/notification-config-cache.cjs +4 -4
  77. package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -1
  78. package/dist/NotificationServicesController/services/notification-config-cache.mjs +4 -4
  79. package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -1
  80. package/dist/NotificationServicesController/services/perp-notifications.cjs +2 -2
  81. package/dist/NotificationServicesController/services/perp-notifications.cjs.map +1 -1
  82. package/dist/NotificationServicesController/services/perp-notifications.d.cts.map +1 -1
  83. package/dist/NotificationServicesController/services/perp-notifications.d.mts.map +1 -1
  84. package/dist/NotificationServicesController/services/perp-notifications.mjs +2 -2
  85. package/dist/NotificationServicesController/services/perp-notifications.mjs.map +1 -1
  86. package/dist/NotificationServicesController/types/notification-api/notification-api.cjs.map +1 -1
  87. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts +2 -0
  88. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts.map +1 -1
  89. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts +2 -0
  90. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts.map +1 -1
  91. package/dist/NotificationServicesController/types/notification-api/notification-api.mjs.map +1 -1
  92. package/dist/NotificationServicesController/types/notification-api/schema.cjs +2 -0
  93. package/dist/NotificationServicesController/types/notification-api/schema.cjs.map +1 -1
  94. package/dist/NotificationServicesController/types/notification-api/schema.d.cts +23 -0
  95. package/dist/NotificationServicesController/types/notification-api/schema.d.cts.map +1 -1
  96. package/dist/NotificationServicesController/types/notification-api/schema.d.mts +23 -0
  97. package/dist/NotificationServicesController/types/notification-api/schema.d.mts.map +1 -1
  98. package/dist/NotificationServicesController/types/notification-api/schema.mjs +2 -0
  99. package/dist/NotificationServicesController/types/notification-api/schema.mjs.map +1 -1
  100. package/dist/NotificationServicesController/types/perps/schema.cjs +2 -0
  101. package/dist/NotificationServicesController/types/perps/schema.cjs.map +1 -1
  102. package/dist/NotificationServicesController/types/perps/schema.d.cts.map +1 -1
  103. package/dist/NotificationServicesController/types/perps/schema.d.mts.map +1 -1
  104. package/dist/NotificationServicesController/types/perps/schema.mjs +2 -0
  105. package/dist/NotificationServicesController/types/perps/schema.mjs.map +1 -1
  106. package/dist/NotificationServicesController/utils/isVersionInBounds.cjs.map +1 -1
  107. package/dist/NotificationServicesController/utils/isVersionInBounds.d.cts.map +1 -1
  108. package/dist/NotificationServicesController/utils/isVersionInBounds.d.mts.map +1 -1
  109. package/dist/NotificationServicesController/utils/isVersionInBounds.mjs.map +1 -1
  110. package/dist/NotificationServicesController/utils/should-auto-expire.cjs.map +1 -1
  111. package/dist/NotificationServicesController/utils/should-auto-expire.d.cts.map +1 -1
  112. package/dist/NotificationServicesController/utils/should-auto-expire.d.mts.map +1 -1
  113. package/dist/NotificationServicesController/utils/should-auto-expire.mjs.map +1 -1
  114. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +0 -1
  115. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  116. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +1 -1
  117. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  118. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +1 -1
  119. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  120. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +0 -1
  121. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  122. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
  123. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +9 -24
  124. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
  125. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +9 -24
  126. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
  127. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
  128. package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
  129. package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
  130. package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
  131. package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
  132. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  133. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  134. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  135. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  136. package/dist/NotificationServicesPushController/utils/get-notification-data.cjs +4 -4
  137. package/dist/NotificationServicesPushController/utils/get-notification-data.cjs.map +1 -1
  138. package/dist/NotificationServicesPushController/utils/get-notification-data.d.cts +2 -2
  139. package/dist/NotificationServicesPushController/utils/get-notification-data.d.cts.map +1 -1
  140. package/dist/NotificationServicesPushController/utils/get-notification-data.d.mts +2 -2
  141. package/dist/NotificationServicesPushController/utils/get-notification-data.d.mts.map +1 -1
  142. package/dist/NotificationServicesPushController/utils/get-notification-data.mjs +4 -4
  143. package/dist/NotificationServicesPushController/utils/get-notification-data.mjs.map +1 -1
  144. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +62 -71
  145. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
  146. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +9 -9
  147. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
  148. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +9 -9
  149. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
  150. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +62 -71
  151. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
  152. package/dist/NotificationServicesPushController/web/push-utils.cjs +15 -7
  153. package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -1
  154. package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -1
  155. package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -1
  156. package/dist/NotificationServicesPushController/web/push-utils.mjs +16 -8
  157. package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -1
  158. package/dist/shared/is-onchain-notification.cjs +3 -3
  159. package/dist/shared/is-onchain-notification.cjs.map +1 -1
  160. package/dist/shared/is-onchain-notification.d.cts +2 -2
  161. package/dist/shared/is-onchain-notification.d.cts.map +1 -1
  162. package/dist/shared/is-onchain-notification.d.mts +2 -2
  163. package/dist/shared/is-onchain-notification.d.mts.map +1 -1
  164. package/dist/shared/is-onchain-notification.mjs +3 -3
  165. package/dist/shared/is-onchain-notification.mjs.map +1 -1
  166. package/dist/shared/to-raw-notification.cjs.map +1 -1
  167. package/dist/shared/to-raw-notification.mjs.map +1 -1
  168. package/package.json +12 -25
  169. package/dist/NotificationServicesController/ui/constants.cjs +0 -75
  170. package/dist/NotificationServicesController/ui/constants.cjs.map +0 -1
  171. package/dist/NotificationServicesController/ui/constants.d.cts +0 -66
  172. package/dist/NotificationServicesController/ui/constants.d.cts.map +0 -1
  173. package/dist/NotificationServicesController/ui/constants.d.mts +0 -66
  174. package/dist/NotificationServicesController/ui/constants.d.mts.map +0 -1
  175. package/dist/NotificationServicesController/ui/constants.mjs +0 -71
  176. package/dist/NotificationServicesController/ui/constants.mjs.map +0 -1
  177. package/dist/NotificationServicesController/ui/index.cjs +0 -18
  178. package/dist/NotificationServicesController/ui/index.cjs.map +0 -1
  179. package/dist/NotificationServicesController/ui/index.d.cts +0 -2
  180. package/dist/NotificationServicesController/ui/index.d.cts.map +0 -1
  181. package/dist/NotificationServicesController/ui/index.d.mts +0 -2
  182. package/dist/NotificationServicesController/ui/index.d.mts.map +0 -1
  183. package/dist/NotificationServicesController/ui/index.mjs +0 -2
  184. package/dist/NotificationServicesController/ui/index.mjs.map +0 -1
  185. package/dist/NotificationServicesPushController/services/push/push-web.cjs +0 -145
  186. package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +0 -1
  187. package/dist/NotificationServicesPushController/services/push/push-web.d.cts +0 -34
  188. package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +0 -1
  189. package/dist/NotificationServicesPushController/services/push/push-web.d.mts +0 -34
  190. package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +0 -1
  191. package/dist/NotificationServicesPushController/services/push/push-web.mjs +0 -142
  192. package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +0 -1
  193. package/notification-services/ui/package.json +0 -9
@@ -1 +1 @@
1
- {"version":3,"file":"get-notification-message.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAMlE,0EAA+F;AAoD/F;;;;;;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,GAAG,EAAE,CAAC,CAAC,CAAC,yCAAyC,CAAC;YACzD,kBAAkB,EAAE,GAAG,EAAE,CACvB,CAAC,CAAC,sDAAsD,CAAC;YAC3D,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;gBACpB,MAAM,MAAM,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBAC/C,MAAM,WAAW,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBACpD,MAAM,aAAa,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC;gBACxD,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,IAAI,CAAC,aAAa,EAAE,CAAC;oBAC9C,OAAO,IAAI,CAAC;gBACd,CAAC;gBAED,MAAM,MAAM,GAAG,IAAA,iCAAS,EAAC,WAAW,EAAE,aAAa,EAAE;oBACnD,aAAa,EAAE,IAAI;iBACpB,CAAC,CAAC;gBACH,OAAO,CAAC,CACN,+C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IAED,OAAO;QACL,8DAA8D;QAC9D,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAAC,CAAQ,CAAC,IAAI,EAAE,EAAE,kCAAkC;QACvF,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,mCAAmC;KACpE,CAAC;AACJ,CAAC;AAhCD,oFAgCC","sourcesContent":["import { getAmount, formatAmount } from './get-notification-data';\nimport type {\n NOTIFICATION_CHAINS_IDS,\n Types,\n} from '../../NotificationServicesController';\nimport type { Constants } from '../../NotificationServicesController';\nimport { NOTIFICATION_NETWORK_CURRENCY_SYMBOL } from '../../NotificationServicesController/ui';\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 ctaLink?: string;\n};\n\ntype NotificationMessage<N extends Types.INotification> = {\n title: (n: N) => string | null;\n defaultDescription: (n: N) => string | null;\n getDescription?: (n: N) => string | null;\n link?: (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: () =>\n t('pushPlatformNotificationsFundsSentDescriptionDefault'),\n getDescription: (n) => {\n const symbol = n?.payload?.data?.token?.symbol;\n const tokenAmount = n?.payload?.data?.token?.amount;\n const tokenDecimals = n?.payload?.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: () =>\n t('pushPlatformNotificationsFundsSentDescriptionDefault'),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.payload?.chain_id);\n const tokenAmount = n?.payload?.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: () =>\n t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n getDescription: (n) => {\n const symbol = n?.payload?.data?.token?.symbol;\n const tokenAmount = n?.payload?.data?.token?.amount;\n const tokenDecimals = n?.payload?.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: () =>\n t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.payload?.chain_id);\n const tokenAmount = n?.payload?.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: () =>\n t('pushPlatformNotificationsSwapCompletedDescription'),\n },\n erc721_sent: {\n title: () => t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: () => t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: () => t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: () => t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: () =>\n t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),\n defaultDescription: () =>\n t(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: () =>\n t('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle'),\n defaultDescription: () =>\n t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: () => t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsStakingLidoStakeCompletedDescription'),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: () =>\n t('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle'),\n defaultDescription: () =>\n t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: () =>\n t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription'),\n },\n lido_withdrawal_completed: {\n title: () =>\n t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription'),\n },\n platform: {\n title: (n) => n.template.title,\n defaultDescription: (n) => n.template.body,\n getDescription: (n) => n.template.body,\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 (\n NOTIFICATION_NETWORK_CURRENCY_SYMBOL[\n chainId.toString() as NOTIFICATION_CHAINS_IDS\n ] ?? null\n );\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage.defaultDescription?.(n as any) ??\n null;\n } catch {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n description = notificationMessage.defaultDescription?.(n as any) ?? null;\n }\n\n return {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n title: notificationMessage?.title?.(n as any) ?? '', // 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;AAsDlE;;;;;;GAMG;AACI,MAAM,qCAAqC,GAAG,CACnD,eAAgC,EACP,EAAE;IAI3B,MAAM,SAAS,GAAkB,CAAC,GAAG,IAAI,EAAE,EAAE;QAC3C,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,GAAkB,EAAE,CACzB,SAAS,CAAC,yCAA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ACvB,IAAA,6CAAqC,EAAC,YAAY,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEzE,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,WAAW,GAAkB,IAAI,CAAC;IACtC,IAAI,CAAC;QACH,WAAW;YACT,8DAA8D;YAC9D,mBAAmB,EAAE,cAAc,EAAE,CAAC,YAAmB,CAAC;gBAC1D,8DAA8D;gBAC9D,mBAAmB,CAAC,kBAAkB,EAAE,CAAC,YAAmB,CAAC;gBAC7D,IAAI,CAAC;IACT,CAAC;IAAC,MAAM,CAAC;QACP,WAAW;YACT,8DAA8D;YAC9D,mBAAmB,CAAC,kBAAkB,EAAE,CAAC,YAAmB,CAAC,IAAI,IAAI,CAAC;IAC1E,CAAC;IAED,OAAO;QACL,8DAA8D;QAC9D,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAAC,YAAmB,CAAC,IAAI,EAAE,EAAE,kCAAkC;QAClG,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,mCAAmC;KACpE,CAAC;AACJ,CAAC;AAjCD,oFAiCC","sourcesContent":["import { getAmount, formatAmount } from './get-notification-data';\nimport type { Types } from '../../NotificationServicesController';\nimport type { 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 ctaLink?: string;\n};\n\ntype NotificationMessage<TNotification extends Types.INotification> = {\n title: (notification: TNotification) => string | null;\n defaultDescription: (notification: TNotification) => string | null;\n getDescription?: (notification: TNotification) => string | null;\n link?: (notification: TNotification) => string | null;\n};\n\ntype NotificationMessageDict = {\n [TriggerType in Constants.TRIGGER_TYPES]?: NotificationMessage<\n Extract<Types.INotification, { type: TriggerType }>\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 = <TKey extends keyof TranslationKeys>(\n ...args: [TKey, ...Parameters<TranslationKeys[TKey]>]\n ) => string;\n const translate: 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: (): string | null =>\n translate('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsFundsSentDescriptionDefault'),\n getDescription: (notification): string | null => {\n const symbol = notification?.payload?.data?.token?.symbol;\n const tokenAmount = notification?.payload?.data?.token?.amount;\n const tokenDecimals = notification?.payload?.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 translate(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n eth_sent: {\n title: (): string | null =>\n translate('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsFundsSentDescriptionDefault'),\n getDescription: (notification): string | null => {\n const symbol = notification?.payload?.network?.native_symbol;\n const tokenAmount = notification?.payload?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return translate(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n erc20_received: {\n title: (): string | null =>\n translate('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n getDescription: (notification): string | null => {\n const symbol = notification?.payload?.data?.token?.symbol;\n const tokenAmount = notification?.payload?.data?.token?.amount;\n const tokenDecimals = notification?.payload?.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 translate(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n eth_received: {\n title: (): string | null =>\n translate('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n getDescription: (notification): string | null => {\n const symbol = notification?.payload?.network?.native_symbol;\n const tokenAmount = notification?.payload?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return translate(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n metamask_swap_completed: {\n title: (): string | null =>\n translate('pushPlatformNotificationsSwapCompletedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsSwapCompletedDescription'),\n },\n erc721_sent: {\n title: (): string | null =>\n translate('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: (): string | null =>\n translate('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: (): string | null =>\n translate('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: (): string | null =>\n translate('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: (): string | null =>\n translate('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoStakeCompletedDescription',\n ),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription',\n ),\n },\n lido_withdrawal_completed: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription',\n ),\n },\n platform: {\n title: (notification): string | null => notification.template.title,\n defaultDescription: (notification): string | null =>\n notification.template.body,\n getDescription: (notification): string | null =>\n notification.template.body,\n },\n };\n};\n\n/**\n * Creates a push notification message based on the given on-chain raw notification.\n *\n * @param notification - 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 notification: Types.INotification,\n translations: TranslationKeys,\n): PushNotificationMessage | null {\n if (!notification?.type) {\n return null;\n }\n const notificationMessage =\n createOnChainPushNotificationMessages(translations)[notification.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?.(notification as any) ??\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage.defaultDescription?.(notification as any) ??\n null;\n } catch {\n description =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage.defaultDescription?.(notification as any) ?? null;\n }\n\n return {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n title: notificationMessage?.title?.(notification as any) ?? '', // Ensure title is always a string\n description: description ?? '', // Fallback to empty string if null\n };\n}\n"]}
@@ -31,15 +31,15 @@ type PushNotificationMessage = {
31
31
  description: string;
32
32
  ctaLink?: string;
33
33
  };
34
- type NotificationMessage<N extends Types.INotification> = {
35
- title: (n: N) => string | null;
36
- defaultDescription: (n: N) => string | null;
37
- getDescription?: (n: N) => string | null;
38
- link?: (n: N) => string | null;
34
+ type NotificationMessage<TNotification extends Types.INotification> = {
35
+ title: (notification: TNotification) => string | null;
36
+ defaultDescription: (notification: TNotification) => string | null;
37
+ getDescription?: (notification: TNotification) => string | null;
38
+ link?: (notification: TNotification) => string | null;
39
39
  };
40
40
  type NotificationMessageDict = {
41
- [K in Constants.TRIGGER_TYPES]?: NotificationMessage<Extract<Types.INotification, {
42
- type: K;
41
+ [TriggerType in Constants.TRIGGER_TYPES]?: NotificationMessage<Extract<Types.INotification, {
42
+ type: TriggerType;
43
43
  }>>;
44
44
  };
45
45
  /**
@@ -53,10 +53,10 @@ export declare const createOnChainPushNotificationMessages: (translationKeys: Tr
53
53
  /**
54
54
  * Creates a push notification message based on the given on-chain raw notification.
55
55
  *
56
- * @param n - processed notification.
56
+ * @param notification - processed notification.
57
57
  * @param translations - translates keys into text
58
58
  * @returns The push notification message object, or null if the notification is invalid.
59
59
  */
60
- export declare function createOnChainPushNotificationMessage(n: Types.INotification, translations: TranslationKeys): PushNotificationMessage | null;
60
+ export declare function createOnChainPushNotificationMessage(notification: Types.INotification, translations: TranslationKeys): PushNotificationMessage | null;
61
61
  export {};
62
62
  //# sourceMappingURL=get-notification-message.d.cts.map
@@ -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,EAEV,KAAK,EACN,uDAA6C;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,uDAA6C;AAGtE,MAAM,MAAM,eAAe,GAAG;IAC5B,uCAAuC,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a,IAAI;IACxD,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;IAC/B,kBAAkB,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;IAC5C,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;IACzC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;CAChC,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,uBA4KF,CAAC;AAgBF;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,CAAC,EAAE,KAAK,CAAC,aAAa,EACtB,YAAY,EAAE,eAAe,GAC5B,uBAAuB,GAAG,IAAI,CA6BhC"}
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,KAAK,EAAE,SAAS,EAAE,uDAA6C;AAEtE,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,GA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YAAY,EAAE,aAAa,KAAK,MAAM,GAAG,IAAI,CAAC;CACvD,CAAC;AAEF,KAAK,uBAAuB,GAAG;KAC5B,WAAW,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,mBAAmB,CAC5D,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CACpD;CACF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qCAAqC,oBAC/B,eAAe,KAC/B,uBAwMF,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,YAAY,EAAE,KAAK,CAAC,aAAa,EACjC,YAAY,EAAE,eAAe,GAC5B,uBAAuB,GAAG,IAAI,CA8BhC"}
@@ -31,15 +31,15 @@ type PushNotificationMessage = {
31
31
  description: string;
32
32
  ctaLink?: string;
33
33
  };
34
- type NotificationMessage<N extends Types.INotification> = {
35
- title: (n: N) => string | null;
36
- defaultDescription: (n: N) => string | null;
37
- getDescription?: (n: N) => string | null;
38
- link?: (n: N) => string | null;
34
+ type NotificationMessage<TNotification extends Types.INotification> = {
35
+ title: (notification: TNotification) => string | null;
36
+ defaultDescription: (notification: TNotification) => string | null;
37
+ getDescription?: (notification: TNotification) => string | null;
38
+ link?: (notification: TNotification) => string | null;
39
39
  };
40
40
  type NotificationMessageDict = {
41
- [K in Constants.TRIGGER_TYPES]?: NotificationMessage<Extract<Types.INotification, {
42
- type: K;
41
+ [TriggerType in Constants.TRIGGER_TYPES]?: NotificationMessage<Extract<Types.INotification, {
42
+ type: TriggerType;
43
43
  }>>;
44
44
  };
45
45
  /**
@@ -53,10 +53,10 @@ export declare const createOnChainPushNotificationMessages: (translationKeys: Tr
53
53
  /**
54
54
  * Creates a push notification message based on the given on-chain raw notification.
55
55
  *
56
- * @param n - processed notification.
56
+ * @param notification - processed notification.
57
57
  * @param translations - translates keys into text
58
58
  * @returns The push notification message object, or null if the notification is invalid.
59
59
  */
60
- export declare function createOnChainPushNotificationMessage(n: Types.INotification, translations: TranslationKeys): PushNotificationMessage | null;
60
+ export declare function createOnChainPushNotificationMessage(notification: Types.INotification, translations: TranslationKeys): PushNotificationMessage | null;
61
61
  export {};
62
62
  //# sourceMappingURL=get-notification-message.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-notification-message.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,KAAK,EACN,uDAA6C;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,uDAA6C;AAGtE,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;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,mBAAmB,CAAC,CAAC,SAAS,KAAK,CAAC,aAAa,IAAI;IACxD,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;IAC/B,kBAAkB,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;IAC5C,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;IACzC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;CAChC,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,uBA4KF,CAAC;AAgBF;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,CAAC,EAAE,KAAK,CAAC,aAAa,EACtB,YAAY,EAAE,eAAe,GAC5B,uBAAuB,GAAG,IAAI,CA6BhC"}
1
+ {"version":3,"file":"get-notification-message.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],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AAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,mBAAmB,CAAC,aAAa,SAAS,KAAK,CAAC,aAAa,IAAI;IACpE,KAAK,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,MAAM,GAAG,IAAI,CAAC;IACtD,kBAAkB,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,MAAM,GAAG,IAAI,CAAC;IACnE,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,MAAM,GAAG,IAAI,CAAC;IAChE,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,MAAM,GAAG,IAAI,CAAC;CACvD,CAAC;AAEF,KAAK,uBAAuB,GAAG;KAC5B,WAAW,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,mBAAmB,CAC5D,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CACpD;CACF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qCAAqC,oBAC/B,eAAe,KAC/B,uBAwMF,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,YAAY,EAAE,KAAK,CAAC,aAAa,EACjC,YAAY,EAAE,eAAe,GAC5B,uBAAuB,GAAG,IAAI,CA8BhC"}
@@ -1,5 +1,4 @@
1
1
  import { getAmount, formatAmount } from "./get-notification-data.mjs";
2
- import { NOTIFICATION_NETWORK_CURRENCY_SYMBOL } from "../../NotificationServicesController/ui/index.mjs";
3
2
  /**
4
3
  * On Chain Push Notification Messages.
5
4
  * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension
@@ -8,7 +7,7 @@ import { NOTIFICATION_NETWORK_CURRENCY_SYMBOL } from "../../NotificationServices
8
7
  * @returns A translation push message object.
9
8
  */
10
9
  export const createOnChainPushNotificationMessages = (translationKeys) => {
11
- const t = (...args) => {
10
+ const translate = (...args) => {
12
11
  const [key, ...otherArgs] = args;
13
12
  // Coerce types for the translation function
14
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -17,139 +16,130 @@ export const createOnChainPushNotificationMessages = (translationKeys) => {
17
16
  };
18
17
  return {
19
18
  erc20_sent: {
20
- title: () => t('pushPlatformNotificationsFundsSentTitle'),
21
- defaultDescription: () => t('pushPlatformNotificationsFundsSentDescriptionDefault'),
22
- getDescription: (n) => {
23
- const symbol = n?.payload?.data?.token?.symbol;
24
- const tokenAmount = n?.payload?.data?.token?.amount;
25
- const tokenDecimals = n?.payload?.data?.token?.decimals;
19
+ title: () => translate('pushPlatformNotificationsFundsSentTitle'),
20
+ defaultDescription: () => translate('pushPlatformNotificationsFundsSentDescriptionDefault'),
21
+ getDescription: (notification) => {
22
+ const symbol = notification?.payload?.data?.token?.symbol;
23
+ const tokenAmount = notification?.payload?.data?.token?.amount;
24
+ const tokenDecimals = notification?.payload?.data?.token?.decimals;
26
25
  if (!symbol || !tokenAmount || !tokenDecimals) {
27
26
  return null;
28
27
  }
29
28
  const amount = getAmount(tokenAmount, tokenDecimals, {
30
29
  shouldEllipse: true,
31
30
  });
32
- return t('pushPlatformNotificationsFundsSentDescription', amount, symbol);
31
+ return translate('pushPlatformNotificationsFundsSentDescription', amount, symbol);
33
32
  },
34
33
  },
35
34
  eth_sent: {
36
- title: () => t('pushPlatformNotificationsFundsSentTitle'),
37
- defaultDescription: () => t('pushPlatformNotificationsFundsSentDescriptionDefault'),
38
- getDescription: (n) => {
39
- const symbol = getChainSymbol(n?.payload?.chain_id);
40
- const tokenAmount = n?.payload?.data?.amount?.eth;
35
+ title: () => translate('pushPlatformNotificationsFundsSentTitle'),
36
+ defaultDescription: () => translate('pushPlatformNotificationsFundsSentDescriptionDefault'),
37
+ getDescription: (notification) => {
38
+ const symbol = notification?.payload?.network?.native_symbol;
39
+ const tokenAmount = notification?.payload?.data?.amount?.eth;
41
40
  if (!symbol || !tokenAmount) {
42
41
  return null;
43
42
  }
44
43
  const amount = formatAmount(parseFloat(tokenAmount), {
45
44
  shouldEllipse: true,
46
45
  });
47
- return t('pushPlatformNotificationsFundsSentDescription', amount, symbol);
46
+ return translate('pushPlatformNotificationsFundsSentDescription', amount, symbol);
48
47
  },
49
48
  },
50
49
  erc20_received: {
51
- title: () => t('pushPlatformNotificationsFundsReceivedTitle'),
52
- defaultDescription: () => t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
53
- getDescription: (n) => {
54
- const symbol = n?.payload?.data?.token?.symbol;
55
- const tokenAmount = n?.payload?.data?.token?.amount;
56
- const tokenDecimals = n?.payload?.data?.token?.decimals;
50
+ title: () => translate('pushPlatformNotificationsFundsReceivedTitle'),
51
+ defaultDescription: () => translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
52
+ getDescription: (notification) => {
53
+ const symbol = notification?.payload?.data?.token?.symbol;
54
+ const tokenAmount = notification?.payload?.data?.token?.amount;
55
+ const tokenDecimals = notification?.payload?.data?.token?.decimals;
57
56
  if (!symbol || !tokenAmount || !tokenDecimals) {
58
57
  return null;
59
58
  }
60
59
  const amount = getAmount(tokenAmount, tokenDecimals, {
61
60
  shouldEllipse: true,
62
61
  });
63
- return t('pushPlatformNotificationsFundsReceivedDescription', amount, symbol);
62
+ return translate('pushPlatformNotificationsFundsReceivedDescription', amount, symbol);
64
63
  },
65
64
  },
66
65
  eth_received: {
67
- title: () => t('pushPlatformNotificationsFundsReceivedTitle'),
68
- defaultDescription: () => t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
69
- getDescription: (n) => {
70
- const symbol = getChainSymbol(n?.payload?.chain_id);
71
- const tokenAmount = n?.payload?.data?.amount?.eth;
66
+ title: () => translate('pushPlatformNotificationsFundsReceivedTitle'),
67
+ defaultDescription: () => translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
68
+ getDescription: (notification) => {
69
+ const symbol = notification?.payload?.network?.native_symbol;
70
+ const tokenAmount = notification?.payload?.data?.amount?.eth;
72
71
  if (!symbol || !tokenAmount) {
73
72
  return null;
74
73
  }
75
74
  const amount = formatAmount(parseFloat(tokenAmount), {
76
75
  shouldEllipse: true,
77
76
  });
78
- return t('pushPlatformNotificationsFundsReceivedDescription', amount, symbol);
77
+ return translate('pushPlatformNotificationsFundsReceivedDescription', amount, symbol);
79
78
  },
80
79
  },
81
80
  metamask_swap_completed: {
82
- title: () => t('pushPlatformNotificationsSwapCompletedTitle'),
83
- defaultDescription: () => t('pushPlatformNotificationsSwapCompletedDescription'),
81
+ title: () => translate('pushPlatformNotificationsSwapCompletedTitle'),
82
+ defaultDescription: () => translate('pushPlatformNotificationsSwapCompletedDescription'),
84
83
  },
85
84
  erc721_sent: {
86
- title: () => t('pushPlatformNotificationsNftSentTitle'),
87
- defaultDescription: () => t('pushPlatformNotificationsNftSentDescription'),
85
+ title: () => translate('pushPlatformNotificationsNftSentTitle'),
86
+ defaultDescription: () => translate('pushPlatformNotificationsNftSentDescription'),
88
87
  },
89
88
  erc1155_sent: {
90
- title: () => t('pushPlatformNotificationsNftSentTitle'),
91
- defaultDescription: () => t('pushPlatformNotificationsNftSentDescription'),
89
+ title: () => translate('pushPlatformNotificationsNftSentTitle'),
90
+ defaultDescription: () => translate('pushPlatformNotificationsNftSentDescription'),
92
91
  },
93
92
  erc721_received: {
94
- title: () => t('pushPlatformNotificationsNftReceivedTitle'),
95
- defaultDescription: () => t('pushPlatformNotificationsNftReceivedDescription'),
93
+ title: () => translate('pushPlatformNotificationsNftReceivedTitle'),
94
+ defaultDescription: () => translate('pushPlatformNotificationsNftReceivedDescription'),
96
95
  },
97
96
  erc1155_received: {
98
- title: () => t('pushPlatformNotificationsNftReceivedTitle'),
99
- defaultDescription: () => t('pushPlatformNotificationsNftReceivedDescription'),
97
+ title: () => translate('pushPlatformNotificationsNftReceivedTitle'),
98
+ defaultDescription: () => translate('pushPlatformNotificationsNftReceivedDescription'),
100
99
  },
101
100
  rocketpool_stake_completed: {
102
- title: () => t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),
103
- defaultDescription: () => t('pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription'),
101
+ title: () => translate('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),
102
+ defaultDescription: () => translate('pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription'),
104
103
  },
105
104
  rocketpool_unstake_completed: {
106
- title: () => t('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle'),
107
- defaultDescription: () => t('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription'),
105
+ title: () => translate('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle'),
106
+ defaultDescription: () => translate('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription'),
108
107
  },
109
108
  lido_stake_completed: {
110
- title: () => t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),
111
- defaultDescription: () => t('pushPlatformNotificationsStakingLidoStakeCompletedDescription'),
109
+ title: () => translate('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),
110
+ defaultDescription: () => translate('pushPlatformNotificationsStakingLidoStakeCompletedDescription'),
112
111
  },
113
112
  lido_stake_ready_to_be_withdrawn: {
114
- title: () => t('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle'),
115
- defaultDescription: () => t('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription'),
113
+ title: () => translate('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle'),
114
+ defaultDescription: () => translate('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription'),
116
115
  },
117
116
  lido_withdrawal_requested: {
118
- title: () => t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),
119
- defaultDescription: () => t('pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription'),
117
+ title: () => translate('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),
118
+ defaultDescription: () => translate('pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription'),
120
119
  },
121
120
  lido_withdrawal_completed: {
122
- title: () => t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),
123
- defaultDescription: () => t('pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription'),
121
+ title: () => translate('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),
122
+ defaultDescription: () => translate('pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription'),
124
123
  },
125
124
  platform: {
126
- title: (n) => n.template.title,
127
- defaultDescription: (n) => n.template.body,
128
- getDescription: (n) => n.template.body,
125
+ title: (notification) => notification.template.title,
126
+ defaultDescription: (notification) => notification.template.body,
127
+ getDescription: (notification) => notification.template.body,
129
128
  },
130
129
  };
131
130
  };
132
- /**
133
- * Retrieves the symbol associated with a given chain ID.
134
- *
135
- * @param chainId - The ID of the chain.
136
- * @returns The symbol associated with the chain ID, or null if not found.
137
- */
138
- function getChainSymbol(chainId) {
139
- return (NOTIFICATION_NETWORK_CURRENCY_SYMBOL[chainId.toString()] ?? null);
140
- }
141
131
  /**
142
132
  * Creates a push notification message based on the given on-chain raw notification.
143
133
  *
144
- * @param n - processed notification.
134
+ * @param notification - processed notification.
145
135
  * @param translations - translates keys into text
146
136
  * @returns The push notification message object, or null if the notification is invalid.
147
137
  */
148
- export function createOnChainPushNotificationMessage(n, translations) {
149
- if (!n?.type) {
138
+ export function createOnChainPushNotificationMessage(notification, translations) {
139
+ if (!notification?.type) {
150
140
  return null;
151
141
  }
152
- const notificationMessage = createOnChainPushNotificationMessages(translations)[n.type];
142
+ const notificationMessage = createOnChainPushNotificationMessages(translations)[notification.type];
153
143
  if (!notificationMessage) {
154
144
  return null;
155
145
  }
@@ -157,18 +147,19 @@ export function createOnChainPushNotificationMessage(n, translations) {
157
147
  try {
158
148
  description =
159
149
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
160
- notificationMessage?.getDescription?.(n) ??
150
+ notificationMessage?.getDescription?.(notification) ??
161
151
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
- notificationMessage.defaultDescription?.(n) ??
152
+ notificationMessage.defaultDescription?.(notification) ??
163
153
  null;
164
154
  }
165
155
  catch {
166
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
167
- description = notificationMessage.defaultDescription?.(n) ?? null;
156
+ description =
157
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
+ notificationMessage.defaultDescription?.(notification) ?? null;
168
159
  }
169
160
  return {
170
161
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
- title: notificationMessage?.title?.(n) ?? '', // Ensure title is always a string
162
+ title: notificationMessage?.title?.(notification) ?? '', // Ensure title is always a string
172
163
  description: description ?? '', // Fallback to empty string if null
173
164
  };
174
165
  }
@@ -1 +1 @@
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;AAMlE,OAAO,EAAE,oCAAoC,EAAE,0DAAgD;AAoD/F;;;;;;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,GAAG,EAAE,CAAC,CAAC,CAAC,yCAAyC,CAAC;YACzD,kBAAkB,EAAE,GAAG,EAAE,CACvB,CAAC,CAAC,sDAAsD,CAAC;YAC3D,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;gBACpB,MAAM,MAAM,GAAG,CAAC,EA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,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,WAAW,GAAkB,IAAI,CAAC;IACtC,IAAI,CAAC;QACH,WAAW;YACT,8DAA8D;YAC9D,mBAAmB,EAAE,cAAc,EAAE,CAAC,CAAQ,CAAC;gBAC/C,8DAA8D;gBAC9D,mBAAmB,CAAC,kBAAkB,EAAE,CAAC,CAAQ,CAAC;gBAClD,IAAI,CAAC;IACT,CAAC;IAAC,MAAM,CAAC;QACP,8DAA8D;QAC9D,WAAW,GAAG,mBAAmB,CAAC,kBAAkB,EAAE,CAAC,CAAQ,CAAC,IAAI,IAAI,CAAC;IAC3E,CAAC;IAED,OAAO;QACL,8DAA8D;QAC9D,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAAC,CAAQ,CAAC,IAAI,EAAE,EAAE,kCAAkC;QACvF,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,mCAAmC;KACpE,CAAC;AACJ,CAAC","sourcesContent":["import { getAmount, formatAmount } from './get-notification-data';\nimport type {\n NOTIFICATION_CHAINS_IDS,\n Types,\n} from '../../NotificationServicesController';\nimport type { Constants } from '../../NotificationServicesController';\nimport { NOTIFICATION_NETWORK_CURRENCY_SYMBOL } from '../../NotificationServicesController/ui';\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 ctaLink?: string;\n};\n\ntype NotificationMessage<N extends Types.INotification> = {\n title: (n: N) => string | null;\n defaultDescription: (n: N) => string | null;\n getDescription?: (n: N) => string | null;\n link?: (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: () =>\n t('pushPlatformNotificationsFundsSentDescriptionDefault'),\n getDescription: (n) => {\n const symbol = n?.payload?.data?.token?.symbol;\n const tokenAmount = n?.payload?.data?.token?.amount;\n const tokenDecimals = n?.payload?.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: () =>\n t('pushPlatformNotificationsFundsSentDescriptionDefault'),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.payload?.chain_id);\n const tokenAmount = n?.payload?.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: () =>\n t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n getDescription: (n) => {\n const symbol = n?.payload?.data?.token?.symbol;\n const tokenAmount = n?.payload?.data?.token?.amount;\n const tokenDecimals = n?.payload?.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: () =>\n t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.payload?.chain_id);\n const tokenAmount = n?.payload?.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: () =>\n t('pushPlatformNotificationsSwapCompletedDescription'),\n },\n erc721_sent: {\n title: () => t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: () => t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: () => t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: () => t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: () =>\n t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),\n defaultDescription: () =>\n t(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: () =>\n t('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle'),\n defaultDescription: () =>\n t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: () => t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsStakingLidoStakeCompletedDescription'),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: () =>\n t('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle'),\n defaultDescription: () =>\n t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: () =>\n t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription'),\n },\n lido_withdrawal_completed: {\n title: () =>\n t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),\n defaultDescription: () =>\n t('pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription'),\n },\n platform: {\n title: (n) => n.template.title,\n defaultDescription: (n) => n.template.body,\n getDescription: (n) => n.template.body,\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 (\n NOTIFICATION_NETWORK_CURRENCY_SYMBOL[\n chainId.toString() as NOTIFICATION_CHAINS_IDS\n ] ?? null\n );\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage.defaultDescription?.(n as any) ??\n null;\n } catch {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n description = notificationMessage.defaultDescription?.(n as any) ?? null;\n }\n\n return {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n title: notificationMessage?.title?.(n as any) ?? '', // 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;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AAC,KAAK;YACnE,kBAAkB,EAAE,CAAC,YAAY,EAAiB,EAAE,CAClD,YAAY,CAAC,QAAQ,CAAC,IAAI;YAC5B,cAAc,EAAE,CAAC,YAAY,EAAiB,EAAE,CAC9C,YAAY,CAAC,QAAQ,CAAC,IAAI;SAC7B;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,oCAAoC,CAClD,YAAiC,EACjC,YAA6B;IAE7B,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,mBAAmB,GACvB,qCAAqC,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEzE,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,WAAW,GAAkB,IAAI,CAAC;IACtC,IAAI,CAAC;QACH,WAAW;YACT,8DAA8D;YAC9D,mBAAmB,EAAE,cAAc,EAAE,CAAC,YAAmB,CAAC;gBAC1D,8DAA8D;gBAC9D,mBAAmB,CAAC,kBAAkB,EAAE,CAAC,YAAmB,CAAC;gBAC7D,IAAI,CAAC;IACT,CAAC;IAAC,MAAM,CAAC;QACP,WAAW;YACT,8DAA8D;YAC9D,mBAAmB,CAAC,kBAAkB,EAAE,CAAC,YAAmB,CAAC,IAAI,IAAI,CAAC;IAC1E,CAAC;IAED,OAAO;QACL,8DAA8D;QAC9D,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAAC,YAAmB,CAAC,IAAI,EAAE,EAAE,kCAAkC;QAClG,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 type { 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 ctaLink?: string;\n};\n\ntype NotificationMessage<TNotification extends Types.INotification> = {\n title: (notification: TNotification) => string | null;\n defaultDescription: (notification: TNotification) => string | null;\n getDescription?: (notification: TNotification) => string | null;\n link?: (notification: TNotification) => string | null;\n};\n\ntype NotificationMessageDict = {\n [TriggerType in Constants.TRIGGER_TYPES]?: NotificationMessage<\n Extract<Types.INotification, { type: TriggerType }>\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 = <TKey extends keyof TranslationKeys>(\n ...args: [TKey, ...Parameters<TranslationKeys[TKey]>]\n ) => string;\n const translate: 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: (): string | null =>\n translate('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsFundsSentDescriptionDefault'),\n getDescription: (notification): string | null => {\n const symbol = notification?.payload?.data?.token?.symbol;\n const tokenAmount = notification?.payload?.data?.token?.amount;\n const tokenDecimals = notification?.payload?.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 translate(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n eth_sent: {\n title: (): string | null =>\n translate('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsFundsSentDescriptionDefault'),\n getDescription: (notification): string | null => {\n const symbol = notification?.payload?.network?.native_symbol;\n const tokenAmount = notification?.payload?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return translate(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n erc20_received: {\n title: (): string | null =>\n translate('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n getDescription: (notification): string | null => {\n const symbol = notification?.payload?.data?.token?.symbol;\n const tokenAmount = notification?.payload?.data?.token?.amount;\n const tokenDecimals = notification?.payload?.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 translate(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n eth_received: {\n title: (): string | null =>\n translate('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n getDescription: (notification): string | null => {\n const symbol = notification?.payload?.network?.native_symbol;\n const tokenAmount = notification?.payload?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return translate(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n metamask_swap_completed: {\n title: (): string | null =>\n translate('pushPlatformNotificationsSwapCompletedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsSwapCompletedDescription'),\n },\n erc721_sent: {\n title: (): string | null =>\n translate('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: (): string | null =>\n translate('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: (): string | null =>\n translate('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: (): string | null =>\n translate('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: (): string | null =>\n translate('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: (): string | null =>\n translate('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoStakeCompletedDescription',\n ),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription',\n ),\n },\n lido_withdrawal_completed: {\n title: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle',\n ),\n defaultDescription: (): string | null =>\n translate(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription',\n ),\n },\n platform: {\n title: (notification): string | null => notification.template.title,\n defaultDescription: (notification): string | null =>\n notification.template.body,\n getDescription: (notification): string | null =>\n notification.template.body,\n },\n };\n};\n\n/**\n * Creates a push notification message based on the given on-chain raw notification.\n *\n * @param notification - 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 notification: Types.INotification,\n translations: TranslationKeys,\n): PushNotificationMessage | null {\n if (!notification?.type) {\n return null;\n }\n const notificationMessage =\n createOnChainPushNotificationMessages(translations)[notification.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?.(notification as any) ??\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage.defaultDescription?.(notification as any) ??\n null;\n } catch {\n description =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage.defaultDescription?.(notification as any) ?? null;\n }\n\n return {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n title: notificationMessage?.title?.(notification as any) ?? '', // Ensure title is always a string\n description: description ?? '', // Fallback to empty string if null\n };\n}\n"]}
@@ -14,6 +14,9 @@ const to_raw_notification_1 = require("../../shared/to-raw-notification.cjs");
14
14
  // eslint-disable-next-line import-x/no-mutable-exports
15
15
  exports.supportedCache = null;
16
16
  const getPushAvailability = async () => {
17
+ // Race condition is acceptable here - worst case is isSupported() is called
18
+ // multiple times during initialization, which is harmless for caching a boolean
19
+ // eslint-disable-next-line require-atomic-updates
17
20
  exports.supportedCache ?? (exports.supportedCache = await (0, sw_1.isSupported)());
18
21
  return exports.supportedCache;
19
22
  };
@@ -101,16 +104,22 @@ async function listenToPushNotificationsReceived(env, handler) {
101
104
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
102
105
  async (payload) => {
103
106
  try {
104
- const data = payload?.data
105
- ?.data
106
- ? JSON.parse(payload?.data?.data)
107
- : undefined;
107
+ // MessagePayload shapes are not known
108
+ // TODO - provide open-api unfied backend/frontend types
109
+ // TODO - we will replace the underlying Data payload with the same Notification payload used by mobile
110
+ const data = JSON.parse(payload?.data?.data ?? 'null');
108
111
  if (!data) {
109
112
  return;
110
113
  }
114
+ if (!(0, NotificationServicesController_1.isOnChainRawNotification)(data)) {
115
+ return;
116
+ }
111
117
  const notificationData = (0, to_raw_notification_1.toRawAPINotification)(data);
112
- const notification = NotificationServicesController_1.Processors.processNotification(notificationData);
113
- await handler(notification);
118
+ const notification = (0, NotificationServicesController_1.safeProcessNotification)(notificationData);
119
+ if (!notification) {
120
+ return;
121
+ }
122
+ await handler?.(notification);
114
123
  }
115
124
  catch (error) {
116
125
  // Do Nothing, cannot parse a bad notification
@@ -118,7 +127,6 @@ async function listenToPushNotificationsReceived(env, handler) {
118
127
  notification: payload?.data?.data,
119
128
  error,
120
129
  });
121
- throw new Error('Unable to send push notification');
122
130
  }
123
131
  });
124
132
  const unsubscribe = () => unsubscribePushNotifications();
@@ -1 +1 @@
1
- {"version":3,"file":"push-utils.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/push-utils.ts"],"names":[],"mappings":";;;;;;AAIA,sCAAqD;AACrD,kDAA2D;AAC3D,8CAI+B;AAE/B,wDAA2B;AAG3B,mGAAkE;AAClE,8EAAwE;AAMxE,2BAA2B;AAC3B,uDAAuD;AAC5C,QAAA,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,sBAAc,KAAd,sBAAc,GAAK,MAAM,IAAA,gBAAW,GAAE,EAAC;IACvC,OAAO,sBAAc,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,EAC7B,GAAwB,EACF,EAAE;IACxB,IAAI,CAAC;QACH,OAAO,IAAA,YAAM,GAAE,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,cAAc,GAAG;YACrB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,aAAa,EAAE,GAAG,CAAC,aAAa;YAChC,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;YACxC,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,aAAa,EAAE,GAAG,CAAC,aAAa;SACjC,CAAC;QACF,OAAO,IAAA,mBAAa,EAAC,cAAc,CAAC,CAAC;IACvC,CAAC;AACH,CAAC,CAAC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B,CAAC,CAAC;IAEF,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,kCAAkC,CAAC,KASlD;IACC,OAAO,KAAK,WAAW,GAAwB;QAC7C,MAAM,sBAAsB,GAAG,MAAM,iCAAiC,CACpE,GAAG,EACH,KAAK,EAAE,YAAY,EAAE,EAAE;YACrB,KAAK,CAAC,SAAS,CAAC,OAAO,CACrB,uDAAuD,EACvD,YAAY,CACb,CAAC;YACF,MAAM,KAAK,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAC9C,CAAC,CACF,CAAC;QACF,MAAM,UAAU,GAAG,gCAAgC,CACjD,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;YACtB,KAAK,CAAC,SAAS,CAAC,OAAO,CACrB,4DAA4D,EAC5D,YAAY,CACb,CAAC;YACF,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAC5C,CAAC,CACF,CAAC;QAEF,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,sBAAsB,EAAE,EAAE,CAAC;YAC3B,UAAU,EAAE,CAAC;QACf,CAAC,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAtCD,gFAsCC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../NotificationServicesController';\nimport { Processors } from '../../NotificationServicesController';\nimport { toRawAPINotification } from '../../shared/to-raw-notification';\nimport type { NotificationServicesPushControllerMessenger } from '../NotificationServicesPushController';\nimport type { PushNotificationEnv } from '../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async () => {\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n *\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVIDED\n * @returns unsubscribe handler\n */\nasync function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const data: Types.UnprocessedRawNotification | undefined = payload?.data\n ?.data\n ? JSON.parse(payload?.data?.data)\n : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawAPINotification(data);\n const notification = Processors.processNotification(notificationData);\n await handler(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n throw new Error('Unable to send push notification');\n }\n },\n );\n\n const unsubscribe = () => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nfunction listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification: Types.INotification) => void,\n) {\n const clickHandler = (event: NotificationEvent) => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n\n/**\n * A creator function that assists creating web-specific push notification subscription:\n * 1. Creates subscriptions for receiving and clicking notifications\n * 2. Creates click events when a notification is clicked\n * 3. Publishes controller messenger events\n *\n * @param props - props for this creator function.\n * @param props.onReceivedHandler - allows the developer to handle showing a notification\n * @param props.onClickHandler - allows the developer to handle clicking the notification\n * @param props.messenger - the controller messenger to publish the `onNewNotifications` and `pushNotificationsClicked` events\n * @returns a function that can be used by the controller\n */\nexport function createSubscribeToPushNotifications(props: {\n onReceivedHandler: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n onClickHandler: (\n e: NotificationEvent,\n notification: Types.INotification,\n ) => void;\n messenger: NotificationServicesPushControllerMessenger;\n}) {\n return async function (env: PushNotificationEnv) {\n const onBackgroundMessageSub = await listenToPushNotificationsReceived(\n env,\n async (notification) => {\n props.messenger.publish(\n 'NotificationServicesPushController:onNewNotifications',\n notification,\n );\n await props.onReceivedHandler(notification);\n },\n );\n const onClickSub = listenToPushNotificationsClicked(\n (event, notification) => {\n props.messenger.publish(\n 'NotificationServicesPushController:pushNotificationClicked',\n notification,\n );\n props.onClickHandler(event, notification);\n },\n );\n\n const unsubscribe = () => {\n onBackgroundMessageSub?.();\n onClickSub();\n };\n\n return unsubscribe;\n };\n}\n"]}
1
+ {"version":3,"file":"push-utils.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/web/push-utils.ts"],"names":[],"mappings":";;;;;;AAIA,sCAAqD;AACrD,kDAA2D;AAC3D,8CAI+B;AAE/B,wDAA2B;AAG3B,mGAG8C;AAC9C,8EAAwE;AAMxE,2BAA2B;AAC3B,uDAAuD;AAC5C,QAAA,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB,GAAG,KAAK,IAAsB,EAAE;IACvD,4EAA4E;IAC5E,gFAAgF;IAChF,kDAAkD;IAClD,sBAAc,KAAd,sBAAc,GAAK,MAAM,IAAA,gBAAW,GAAE,EAAC;IACvC,OAAO,sBAAc,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,EAC7B,GAAwB,EACF,EAAE;IACxB,IAAI,CAAC;QACH,OAAO,IAAA,YAAM,GAAE,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,cAAc,GAAG;YACrB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,aAAa,EAAE,GAAG,CAAC,aAA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B,CAAC,CAAC;AACJ,CAAC;AAtCD,gFAsCC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../NotificationServicesController';\nimport {\n isOnChainRawNotification,\n safeProcessNotification,\n} from '../../NotificationServicesController';\nimport { toRawAPINotification } from '../../shared/to-raw-notification';\nimport type { NotificationServicesPushControllerMessenger } from '../NotificationServicesPushController';\nimport type { PushNotificationEnv } from '../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async (): Promise<boolean> => {\n // Race condition is acceptable here - worst case is isSupported() is called\n // multiple times during initialization, which is harmless for caching a boolean\n // eslint-disable-next-line require-atomic-updates\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n *\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVIDED\n * @returns unsubscribe handler\n */\nasync function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler?: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload): Promise<void> => {\n try {\n // MessagePayload shapes are not known\n // TODO - provide open-api unfied backend/frontend types\n // TODO - we will replace the underlying Data payload with the same Notification payload used by mobile\n const data: unknown | null = JSON.parse(payload?.data?.data ?? 'null');\n\n if (!data) {\n return;\n }\n\n if (!isOnChainRawNotification(data)) {\n return;\n }\n\n const notificationData = toRawAPINotification(data);\n const notification = safeProcessNotification(notificationData);\n\n if (!notification) {\n return;\n }\n\n await handler?.(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n }\n },\n );\n\n const unsubscribe = (): void => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nfunction listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification: Types.INotification) => void,\n): () => void {\n const clickHandler = (event: NotificationEvent): void => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = (): void =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n\n/**\n * A creator function that assists creating web-specific push notification subscription:\n * 1. Creates subscriptions for receiving and clicking notifications\n * 2. Creates click events when a notification is clicked\n * 3. Publishes controller messenger events\n *\n * @param props - props for this creator function.\n * @param props.onReceivedHandler - allows the developer to handle showing a notification\n * @param props.onClickHandler - allows the developer to handle clicking the notification\n * @param props.messenger - the controller messenger to publish the `onNewNotifications` and `pushNotificationsClicked` events\n * @returns a function that can be used by the controller\n */\nexport function createSubscribeToPushNotifications(props: {\n onReceivedHandler: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n onClickHandler: (\n e: NotificationEvent,\n notification: Types.INotification,\n ) => void;\n messenger: NotificationServicesPushControllerMessenger;\n}): (env: PushNotificationEnv) => Promise<() => void> {\n return async function (env: PushNotificationEnv): Promise<() => void> {\n const onBackgroundMessageSub = await listenToPushNotificationsReceived(\n env,\n async (notification): Promise<void> => {\n props.messenger.publish(\n 'NotificationServicesPushController:onNewNotifications',\n notification,\n );\n await props.onReceivedHandler(notification);\n },\n );\n const onClickSub = listenToPushNotificationsClicked(\n (event, notification): void => {\n props.messenger.publish(\n 'NotificationServicesPushController:pushNotificationClicked',\n notification,\n );\n props.onClickHandler(event, notification);\n },\n );\n\n const unsubscribe = (): void => {\n onBackgroundMessageSub?.();\n onClickSub();\n };\n\n return unsubscribe;\n };\n}\n"]}