@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,9 +1,10 @@
1
- export declare const MOCK_REG_TOKEN = "REG_TOKEN";
2
- export declare const getMockUpdatePushNotificationLinksResponse: () => {
3
- url: string;
4
- requestMethod: "POST";
5
- response: null;
1
+ type MockResponse = {
2
+ url: string | RegExp;
3
+ requestMethod: 'GET' | 'POST' | 'PUT';
4
+ response: unknown;
6
5
  };
6
+ export declare const MOCK_REG_TOKEN = "REG_TOKEN";
7
+ export declare const getMockUpdatePushNotificationLinksResponse: () => MockResponse;
7
8
  export declare const MOCK_FCM_RESPONSE: {
8
9
  name: string;
9
10
  token: string;
@@ -14,23 +15,7 @@ export declare const MOCK_FCM_RESPONSE: {
14
15
  applicationPubKey: string;
15
16
  };
16
17
  };
17
- export declare const getMockCreateFCMRegistrationTokenResponse: () => {
18
- url: RegExp;
19
- requestMethod: "POST";
20
- response: {
21
- name: string;
22
- token: string;
23
- web: {
24
- endpoint: string;
25
- p256dh: string;
26
- auth: string;
27
- applicationPubKey: string;
28
- };
29
- };
30
- };
31
- export declare const getMockDeleteFCMRegistrationTokenResponse: () => {
32
- url: RegExp;
33
- requestMethod: "POST";
34
- response: {};
35
- };
18
+ export declare const getMockCreateFCMRegistrationTokenResponse: () => MockResponse;
19
+ export declare const getMockDeleteFCMRegistrationTokenResponse: () => MockResponse;
20
+ export {};
36
21
  //# sourceMappingURL=mockResponse.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C;;;;CAMtD,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;;;;;;;;;;CAMrD,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;CAMrD,CAAC"}
1
+ {"version":3,"file":"mockResponse.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;IACtC,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C,QAAO,YAM7D,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC;AAEF,eAAO,MAAM,yCAAyC,QAAO,YAM5D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AAQrE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAG,EAAE;IAC7D,OAAO;QACL,GAAG,EAAE,4BAA4B,EAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,iBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = () => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
1
+ {"version":3,"file":"mockResponse.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AAQrE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAiB,EAAE;IAC3E,OAAO;QACL,GAAG,EAAE,4BAA4B,EAAE;QACnC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,iBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAiB,EAAE;IAC1E,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = (): MockResponse => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT(),\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = (): MockResponse => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":";;;AAEA,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,iCAAiC;CACT,CAAC;AAEzB,MAAM,QAAQ,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CAC3C,YAAY,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC;AAD3B,QAAA,QAAQ,YACmB;AAEjC,MAAM,4BAA4B,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CAC/D,GAAG,IAAA,gBAAQ,EAAC,GAAG,CAAC,eAAe,CAAC;AADrB,QAAA,4BAA4B,gCACP","sourcesContent":["export type ENV = 'prd' | 'uat' | 'dev';\n\nconst PUSH_API_ENV = {\n dev: 'https://push.dev-api.cx.metamask.io',\n uat: 'https://push.uat-api.cx.metamask.io',\n prd: 'https://push.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const PUSH_API = (env: ENV = 'prd') =>\n PUSH_API_ENV[env] ?? PUSH_API_ENV.prd;\n\nexport const REGISTRATION_TOKENS_ENDPOINT = (env: ENV = 'prd') =>\n `${PUSH_API(env)}/api/v2/token`;\n"]}
1
+ {"version":3,"file":"endpoints.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":";;;AAEA,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,iCAAiC;CACT,CAAC;AAEzB,MAAM,QAAQ,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CACnD,YAAY,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC;AAD3B,QAAA,QAAQ,YACmB;AAEjC,MAAM,4BAA4B,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CACvE,GAAG,IAAA,gBAAQ,EAAC,GAAG,CAAC,eAAe,CAAC;AADrB,QAAA,4BAA4B,gCACP","sourcesContent":["export type ENV = 'prd' | 'uat' | 'dev';\n\nconst PUSH_API_ENV = {\n dev: 'https://push.dev-api.cx.metamask.io',\n uat: 'https://push.uat-api.cx.metamask.io',\n prd: 'https://push.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const PUSH_API = (env: ENV = 'prd'): string =>\n PUSH_API_ENV[env] ?? PUSH_API_ENV.prd;\n\nexport const REGISTRATION_TOKENS_ENDPOINT = (env: ENV = 'prd'): string =>\n `${PUSH_API(env)}/api/v2/token`;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAQxC,eAAO,MAAM,QAAQ,SAAS,GAAG,WACM,CAAC;AAExC,eAAO,MAAM,4BAA4B,SAAS,GAAG,WACpB,CAAC"}
1
+ {"version":3,"file":"endpoints.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAQxC,eAAO,MAAM,QAAQ,SAAS,GAAG,KAAW,MACL,CAAC;AAExC,eAAO,MAAM,4BAA4B,SAAS,GAAG,KAAW,MAC/B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAQxC,eAAO,MAAM,QAAQ,SAAS,GAAG,WACM,CAAC;AAExC,eAAO,MAAM,4BAA4B,SAAS,GAAG,WACpB,CAAC"}
1
+ {"version":3,"file":"endpoints.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAQxC,eAAO,MAAM,QAAQ,SAAS,GAAG,KAAW,MACL,CAAC;AAExC,eAAO,MAAM,4BAA4B,SAAS,GAAG,KAAW,MAC/B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,iCAAiC;CACT,CAAC;AAEhC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CAC3C,YAAY,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC;AAExC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CAC/D,GAAG,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC","sourcesContent":["export type ENV = 'prd' | 'uat' | 'dev';\n\nconst PUSH_API_ENV = {\n dev: 'https://push.dev-api.cx.metamask.io',\n uat: 'https://push.uat-api.cx.metamask.io',\n prd: 'https://push.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const PUSH_API = (env: ENV = 'prd') =>\n PUSH_API_ENV[env] ?? PUSH_API_ENV.prd;\n\nexport const REGISTRATION_TOKENS_ENDPOINT = (env: ENV = 'prd') =>\n `${PUSH_API(env)}/api/v2/token`;\n"]}
1
+ {"version":3,"file":"endpoints.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,iCAAiC;CACT,CAAC;AAEhC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CACnD,YAAY,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC;AAExC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CACvE,GAAG,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC","sourcesContent":["export type ENV = 'prd' | 'uat' | 'dev';\n\nconst PUSH_API_ENV = {\n dev: 'https://push.dev-api.cx.metamask.io',\n uat: 'https://push.uat-api.cx.metamask.io',\n prd: 'https://push.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const PUSH_API = (env: ENV = 'prd'): string =>\n PUSH_API_ENV[env] ?? PUSH_API_ENV.prd;\n\nexport const REGISTRATION_TOKENS_ENDPOINT = (env: ENV = 'prd'): string =>\n `${PUSH_API(env)}/api/v2/token`;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2DAAyC;AAkCzC;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAAqB;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,kBAAkB,EAAE,MAAM,CAAC,QAAQ;SACpC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,SAAS,CAAC,4BAA4B,CAAC,MAAM,CAAC,GAAG,CAAC,EAClD;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,MAAM,CAAC,WAAW,EAAE;gBAC7C,cAAc,EAAE,kBAAkB;aACnC;YACD,IA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AK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAhBD,kEAgBC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2DAAyC;AAoCzC;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAAqB;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,kBAAkB,EAAE,MAAM,CAAC,QAAQ;SACpC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,SAAS,CAAC,4BAA4B,CAAC,MAAM,CAAC,GAAG,CAAC,EAClD;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,MAAM,CAAC,WAAW,EAAE;gBAC7C,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CACF,CA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,kEAgBC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n // API response uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,kBAAkB,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;QAC/C,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED,KAAK,+BAA+B,GAAG;IAErC,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
1
+ {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,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MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,kBAAkB,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;QAC/C,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED,KAAK,+BAA+B,GAAG;IAErC,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
1
+ {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACf,4CAAwC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;IAGpB,kBAAkB,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;QAC/C,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED,KAAK,+BAA+B,GAAG;IAErC,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,GAAG,CAAC;IAGpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBxB;AAED,KAAK,iCAAiC,GAAG;IAEvC,QAAQ,EAAE,MAAM,CAAC;IAGjB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,OAAO,CAAC,CAclB"}
@@ -1 +1 @@
1
- {"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,wBAAoB;AAkCzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,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M,CAAC,KAAK,UAAU,2BAA2B,CAC/C,MAAyC;IAEzC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;IAEjD,yDAAyD;IACzD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,qBAAqB,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,wBAAoB;AAoCzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,IAAI,GAAqB;YAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,kBAAkB,EAAE,MAAM,CAAC,QAAQ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AAE,cAAc,EAAE,GAAG,MAAM,CAAC;IAEjD,yDAAyD;IACzD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,qBAAqB,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { ENV } from './endpoints';\nimport * as endpoints from './endpoints';\nimport type { PushNotificationEnv } from '../types';\nimport type {\n CreateRegToken,\n DeleteRegToken,\n} from '../types/push-service-interface';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n};\n\n/**\n * Links API Response Shape\n */\nexport type PushTokenRequest = {\n addresses: string[];\n // API response uses snake_case for this property\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_token: {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n locale: string;\n oldToken?: string;\n };\n};\n\ntype UpdatePushTokenParams = {\n bearerToken: string;\n addresses: string[];\n regToken: RegToken;\n env?: ENV;\n};\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param params - params for invoking update reg token\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n params: UpdatePushTokenParams,\n): Promise<boolean> {\n try {\n const body: PushTokenRequest = {\n addresses: params.addresses,\n registration_token: params.regToken,\n };\n const response = await fetch(\n endpoints.REGISTRATION_TOKENS_ENDPOINT(params.env),\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${params.bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n },\n );\n return response.ok;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Create Push Token\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n controllerEnv?: ENV;\n\n // Other Request Parameters\n bearerToken: string;\n addresses: string[];\n regToken: Pick<RegToken, 'locale' | 'platform' | 'oldToken'>;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { env, createRegToken } = params;\n\n const regToken = await createRegToken(env).catch(() => null);\n if (!regToken) {\n return null;\n }\n\n await updateLinksAPI({\n bearerToken: params.bearerToken,\n addresses: params.addresses,\n regToken: {\n token: regToken,\n platform: params.regToken.platform,\n locale: params.regToken.locale,\n oldToken: params.regToken.oldToken,\n },\n env: params.controllerEnv,\n });\n\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token\n * We do not need to unlink triggers, and remove old reg tokens (this is cleaned up in the back-end)\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if push notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n"]}
@@ -25,14 +25,14 @@ exports.calcTokenAmount = calcTokenAmount;
25
25
  * fractional part of the number. This is useful for determining the precision
26
26
  * of very small numbers.
27
27
  *
28
- * @param num - The number to analyze, which can be in the form
28
+ * @param numericValue - The number to analyze, which can be in the form
29
29
  * of a number or a string.
30
30
  * @returns The count of leading zeros in the fractional part of the number.
31
31
  */
32
- const getLeadingZeroCount = (num) => {
33
- const numToString = new bignumber_js_1.BigNumber(num, 10).toString(10);
32
+ const getLeadingZeroCount = (numericValue) => {
33
+ const numToString = new bignumber_js_1.BigNumber(numericValue, 10).toString(10);
34
34
  const fractionalPart = numToString.split('.')[1] ?? '';
35
- return fractionalPart.match(/^0*/u)?.[0]?.length || 0;
35
+ return fractionalPart.match(/^0*/u)?.[0]?.length ?? 0;
36
36
  };
37
37
  exports.getLeadingZeroCount = getLeadingZeroCount;
38
38
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"get-notification-data.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAMzC,MAAM,oBAAoB,GAAG;IAC3B,aAAa,EAAE,CAAC;CACjB,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,KAAa,EAAE,QAAgB;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,IAAI,wBAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACtD,CAAC;AAHD,0CAGC;AAED;;;;;;;;;;;GAWG;AACI,MAAM,mBAAmB,GAAG,CAAC,GAAoB,EAAE,EAAE;IAC1D,MAAM,WAAW,GAAG,IAAI,wBAAS,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxD,MAAM,cAAc,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,OAAO,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;AACxD,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B;AAEF;;;;;;;;;;;GAWG;AACI,MAAM,YAAY,GAAG,CAAC,aAAqB,EAAE,IAAoB,EAAE,EAAE;IAC1E,+BAA+B;IAC/B,MAAM,OAAO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F,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,aAAa,GAAG,eAAe,CACnC,MAAM,EACN,UAAU,CAAC,QAAQ,CAAC,CACrB,CAAC,QAAQ,EAAE,CAAC;IAEb,OAAO,IAAA,oBAAY,EAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC,CAAC;AAfW,QAAA,SAAS,aAepB","sourcesContent":["import { BigNumber } from 'bignumber.js';\n\ntype FormatOptions = {\n decimalPlaces?: number;\n shouldEllipse?: boolean;\n};\nconst defaultFormatOptions = {\n decimalPlaces: 4,\n};\n\n/**\n * Calculates the token amount based on the given value and decimals.\n *\n * @param value - The value to calculate the token amount from.\n * @param decimals - The number of decimals to use for the calculation.\n * @returns The calculated token amount.\n */\nexport function calcTokenAmount(value: string, decimals: number) {\n const multiplier = Math.pow(10, Number(decimals || 0));\n return new BigNumber(String(value)).div(multiplier);\n}\n\n/**\n * Calculates the number of leading zeros in the fractional part of a number.\n *\n * This function converts a number or a string representation of a number into\n * its decimal form and then counts the number of leading zeros present in the\n * fractional part of the number. This is useful for determining the precision\n * of very small numbers.\n *\n * @param num - The number to analyze, which can be in the form\n * of a number or a string.\n * @returns The count of leading zeros in the fractional part of the number.\n */\nexport const getLeadingZeroCount = (num: number | string) => {\n const numToString = new BigNumber(num, 10).toString(10);\n const fractionalPart = numToString.split('.')[1] ?? '';\n return fractionalPart.match(/^0*/u)?.[0]?.length || 0;\n};\n\n/**\n * This formats a number using Intl\n * It abbreviates large numbers (using K, M, B, T)\n * And abbreviates small numbers in 2 ways:\n * - Will format to the given number of decimal places\n * - Will format up to 4 decimal places\n * - Will ellipse the number if longer than given decimal places\n *\n * @param numericAmount - The number to format\n * @param opts - The options to use when formatting\n * @returns The formatted number\n */\nexport const formatAmount = (numericAmount: number, opts?: FormatOptions) => {\n // create options with defaults\n const options = { ...defaultFormatOptions, ...opts };\n\n const leadingZeros = getLeadingZeroCount(numericAmount);\n const isDecimal = numericAmount.toString().includes('.') || leadingZeros > 0;\n const isLargeNumber = numericAmount > 999;\n\n const handleShouldEllipse = (decimalPlaces: number) =>\n Boolean(options?.shouldEllipse) && leadingZeros >= decimalPlaces;\n\n if (isLargeNumber) {\n return Intl.NumberFormat('en-US', {\n notation: 'compact',\n compactDisplay: 'short',\n maximumFractionDigits: 2,\n }).format(numericAmount);\n }\n\n if (isDecimal) {\n const ellipse = handleShouldEllipse(options.decimalPlaces);\n const formattedValue = Intl.NumberFormat('en-US', {\n minimumFractionDigits: ellipse ? options.decimalPlaces : undefined,\n maximumFractionDigits: options.decimalPlaces,\n }).format(numericAmount);\n\n return ellipse ? `${formattedValue}...` : formattedValue;\n }\n\n // Default to showing the raw amount\n return numericAmount.toString();\n};\n\nexport const getAmount = (\n amount: string,\n decimals: string,\n options?: FormatOptions,\n) => {\n if (!amount || !decimals) {\n return '';\n }\n\n const numericAmount = calcTokenAmount(\n amount,\n parseFloat(decimals),\n ).toNumber();\n\n return formatAmount(numericAmount, options);\n};\n"]}
1
+ {"version":3,"file":"get-notification-data.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAMzC,MAAM,oBAAoB,GAAG;IAC3B,aAAa,EAAE,CAAC;CACjB,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,KAAa,EAAE,QAAgB;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,IAAI,wBAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACtD,CAAC;AAHD,0CAGC;AAED;;;;;;;;;;;GAWG;AACI,MAAM,mBAAmB,GAAG,CAAC,YAA6B,EAAU,EAAE;IAC3E,MAAM,WAA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;YAChD,qBAAqB,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;YAClE,qBAAqB,EAAE,OAAO,CAAC,aAAa;SAC7C,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAEzB,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,cAAc,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC;IAC3D,CAAC;IAED,oCAAoC;IACpC,OAAO,aAAa,CAAC,QAAQ,EAAE,CAAC;AAClC,CAAC,CAAC;AAlCW,QAAA,YAAY,gBAkCvB;AAEK,MAAM,SAAS,GAAG,CACvB,MAAc,EACd,QAAgB,EAChB,OAAuB,EACf,EAAE;IACV,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,aAAa,GAAG,eAAe,CACnC,MAAM,EACN,UAAU,CAAC,QAAQ,CAAC,CACrB,CAAC,QAAQ,EAAE,CAAC;IAEb,OAAO,IAAA,oBAAY,EAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC,CAAC;AAfW,QAAA,SAAS,aAepB","sourcesContent":["import { BigNumber } from 'bignumber.js';\n\ntype FormatOptions = {\n decimalPlaces?: number;\n shouldEllipse?: boolean;\n};\nconst defaultFormatOptions = {\n decimalPlaces: 4,\n};\n\n/**\n * Calculates the token amount based on the given value and decimals.\n *\n * @param value - The value to calculate the token amount from.\n * @param decimals - The number of decimals to use for the calculation.\n * @returns The calculated token amount.\n */\nexport function calcTokenAmount(value: string, decimals: number): BigNumber {\n const multiplier = Math.pow(10, Number(decimals || 0));\n return new BigNumber(String(value)).div(multiplier);\n}\n\n/**\n * Calculates the number of leading zeros in the fractional part of a number.\n *\n * This function converts a number or a string representation of a number into\n * its decimal form and then counts the number of leading zeros present in the\n * fractional part of the number. This is useful for determining the precision\n * of very small numbers.\n *\n * @param numericValue - The number to analyze, which can be in the form\n * of a number or a string.\n * @returns The count of leading zeros in the fractional part of the number.\n */\nexport const getLeadingZeroCount = (numericValue: number | string): number => {\n const numToString = new BigNumber(numericValue, 10).toString(10);\n const fractionalPart = numToString.split('.')[1] ?? '';\n return fractionalPart.match(/^0*/u)?.[0]?.length ?? 0;\n};\n\n/**\n * This formats a number using Intl\n * It abbreviates large numbers (using K, M, B, T)\n * And abbreviates small numbers in 2 ways:\n * - Will format to the given number of decimal places\n * - Will format up to 4 decimal places\n * - Will ellipse the number if longer than given decimal places\n *\n * @param numericAmount - The number to format\n * @param opts - The options to use when formatting\n * @returns The formatted number\n */\nexport const formatAmount = (\n numericAmount: number,\n opts?: FormatOptions,\n): string => {\n // create options with defaults\n const options = { ...defaultFormatOptions, ...opts };\n\n const leadingZeros = getLeadingZeroCount(numericAmount);\n const isDecimal = numericAmount.toString().includes('.') || leadingZeros > 0;\n const isLargeNumber = numericAmount > 999;\n\n const handleShouldEllipse = (decimalPlaces: number): boolean =>\n Boolean(options?.shouldEllipse) && leadingZeros >= decimalPlaces;\n\n if (isLargeNumber) {\n return Intl.NumberFormat('en-US', {\n notation: 'compact',\n compactDisplay: 'short',\n maximumFractionDigits: 2,\n }).format(numericAmount);\n }\n\n if (isDecimal) {\n const ellipse = handleShouldEllipse(options.decimalPlaces);\n const formattedValue = Intl.NumberFormat('en-US', {\n minimumFractionDigits: ellipse ? options.decimalPlaces : undefined,\n maximumFractionDigits: options.decimalPlaces,\n }).format(numericAmount);\n\n return ellipse ? `${formattedValue}...` : formattedValue;\n }\n\n // Default to showing the raw amount\n return numericAmount.toString();\n};\n\nexport const getAmount = (\n amount: string,\n decimals: string,\n options?: FormatOptions,\n): string => {\n if (!amount || !decimals) {\n return '';\n }\n\n const numericAmount = calcTokenAmount(\n amount,\n parseFloat(decimals),\n ).toNumber();\n\n return formatAmount(numericAmount, options);\n};\n"]}
@@ -19,11 +19,11 @@ export declare function calcTokenAmount(value: string, decimals: number): BigNum
19
19
  * fractional part of the number. This is useful for determining the precision
20
20
  * of very small numbers.
21
21
  *
22
- * @param num - The number to analyze, which can be in the form
22
+ * @param numericValue - The number to analyze, which can be in the form
23
23
  * of a number or a string.
24
24
  * @returns The count of leading zeros in the fractional part of the number.
25
25
  */
26
- export declare const getLeadingZeroCount: (num: number | string) => number;
26
+ export declare const getLeadingZeroCount: (numericValue: number | string) => number;
27
27
  /**
28
28
  * This formats a number using Intl
29
29
  * It abbreviates large numbers (using K, M, B, T)
@@ -1 +1 @@
1
- {"version":3,"file":"get-notification-data.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAKF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAG9D;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,QAAS,MAAM,GAAG,MAAM,WAIvD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,kBAAmB,MAAM,SAAS,aAAa,WA+BvE,CAAC;AAEF,eAAO,MAAM,SAAS,WACZ,MAAM,YACJ,MAAM,YACN,aAAa,WAYxB,CAAC"}
1
+ {"version":3,"file":"get-notification-data.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAKF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAG1E;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,iBAAkB,MAAM,GAAG,MAAM,KAAG,MAInE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,kBACR,MAAM,SACd,aAAa,KACnB,MA+BF,CAAC;AAEF,eAAO,MAAM,SAAS,WACZ,MAAM,YACJ,MAAM,YACN,aAAa,KACtB,MAWF,CAAC"}
@@ -19,11 +19,11 @@ export declare function calcTokenAmount(value: string, decimals: number): BigNum
19
19
  * fractional part of the number. This is useful for determining the precision
20
20
  * of very small numbers.
21
21
  *
22
- * @param num - The number to analyze, which can be in the form
22
+ * @param numericValue - The number to analyze, which can be in the form
23
23
  * of a number or a string.
24
24
  * @returns The count of leading zeros in the fractional part of the number.
25
25
  */
26
- export declare const getLeadingZeroCount: (num: number | string) => number;
26
+ export declare const getLeadingZeroCount: (numericValue: number | string) => number;
27
27
  /**
28
28
  * This formats a number using Intl
29
29
  * It abbreviates large numbers (using K, M, B, T)
@@ -1 +1 @@
1
- {"version":3,"file":"get-notification-data.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAKF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAG9D;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,QAAS,MAAM,GAAG,MAAM,WAIvD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,kBAAmB,MAAM,SAAS,aAAa,WA+BvE,CAAC;AAEF,eAAO,MAAM,SAAS,WACZ,MAAM,YACJ,MAAM,YACN,aAAa,WAYxB,CAAC"}
1
+ {"version":3,"file":"get-notification-data.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAKF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAG1E;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,iBAAkB,MAAM,GAAG,MAAM,KAAG,MAInE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,kBACR,MAAM,SACd,aAAa,KACnB,MA+BF,CAAC;AAEF,eAAO,MAAM,SAAS,WACZ,MAAM,YACJ,MAAM,YACN,aAAa,KACtB,MAWF,CAAC"}
@@ -21,14 +21,14 @@ export function calcTokenAmount(value, decimals) {
21
21
  * fractional part of the number. This is useful for determining the precision
22
22
  * of very small numbers.
23
23
  *
24
- * @param num - The number to analyze, which can be in the form
24
+ * @param numericValue - The number to analyze, which can be in the form
25
25
  * of a number or a string.
26
26
  * @returns The count of leading zeros in the fractional part of the number.
27
27
  */
28
- export const getLeadingZeroCount = (num) => {
29
- const numToString = new BigNumber(num, 10).toString(10);
28
+ export const getLeadingZeroCount = (numericValue) => {
29
+ const numToString = new BigNumber(numericValue, 10).toString(10);
30
30
  const fractionalPart = numToString.split('.')[1] ?? '';
31
- return fractionalPart.match(/^0*/u)?.[0]?.length || 0;
31
+ return fractionalPart.match(/^0*/u)?.[0]?.length ?? 0;
32
32
  };
33
33
  /**
34
34
  * This formats a number using Intl
@@ -1 +1 @@
1
- {"version":3,"file":"get-notification-data.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,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st defaultFormatOptions = {\n decimalPlaces: 4,\n};\n\n/**\n * Calculates the token amount based on the given value and decimals.\n *\n * @param value - The value to calculate the token amount from.\n * @param decimals - The number of decimals to use for the calculation.\n * @returns The calculated token amount.\n */\nexport function calcTokenAmount(value: string, decimals: number) {\n const multiplier = Math.pow(10, Number(decimals || 0));\n return new BigNumber(String(value)).div(multiplier);\n}\n\n/**\n * Calculates the number of leading zeros in the fractional part of a number.\n *\n * This function converts a number or a string representation of a number into\n * its decimal form and then counts the number of leading zeros present in the\n * fractional part of the number. This is useful for determining the precision\n * of very small numbers.\n *\n * @param num - The number to analyze, which can be in the form\n * of a number or a string.\n * @returns The count of leading zeros in the fractional part of the number.\n */\nexport const getLeadingZeroCount = (num: number | string) => {\n const numToString = new BigNumber(num, 10).toString(10);\n const fractionalPart = numToString.split('.')[1] ?? '';\n return fractionalPart.match(/^0*/u)?.[0]?.length || 0;\n};\n\n/**\n * This formats a number using Intl\n * It abbreviates large numbers (using K, M, B, T)\n * And abbreviates small numbers in 2 ways:\n * - Will format to the given number of decimal places\n * - Will format up to 4 decimal places\n * - Will ellipse the number if longer than given decimal places\n *\n * @param numericAmount - The number to format\n * @param opts - The options to use when formatting\n * @returns The formatted number\n */\nexport const formatAmount = (numericAmount: number, opts?: FormatOptions) => {\n // create options with defaults\n const options = { ...defaultFormatOptions, ...opts };\n\n const leadingZeros = getLeadingZeroCount(numericAmount);\n const isDecimal = numericAmount.toString().includes('.') || leadingZeros > 0;\n const isLargeNumber = numericAmount > 999;\n\n const handleShouldEllipse = (decimalPlaces: number) =>\n Boolean(options?.shouldEllipse) && leadingZeros >= decimalPlaces;\n\n if (isLargeNumber) {\n return Intl.NumberFormat('en-US', {\n notation: 'compact',\n compactDisplay: 'short',\n maximumFractionDigits: 2,\n }).format(numericAmount);\n }\n\n if (isDecimal) {\n const ellipse = handleShouldEllipse(options.decimalPlaces);\n const formattedValue = Intl.NumberFormat('en-US', {\n minimumFractionDigits: ellipse ? options.decimalPlaces : undefined,\n maximumFractionDigits: options.decimalPlaces,\n }).format(numericAmount);\n\n return ellipse ? `${formattedValue}...` : formattedValue;\n }\n\n // Default to showing the raw amount\n return numericAmount.toString();\n};\n\nexport const getAmount = (\n amount: string,\n decimals: string,\n options?: FormatOptions,\n) => {\n if (!amount || !decimals) {\n return '';\n }\n\n const numericAmount = calcTokenAmount(\n amount,\n parseFloat(decimals),\n ).toNumber();\n\n return formatAmount(numericAmount, options);\n};\n"]}
1
+ {"version":3,"file":"get-notification-data.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAMzC,MAAM,oBAAoB,GAAG;IAC3B,aAAa,EAAE,CAAC;CACjB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,QAAgB;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,YAA6B,EAAU,EAAE;IAC3E,MAAM,WAAW,GAAG,IAAI,SAAS,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjE,MAAM,cAAc,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,OAAO,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GA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,CACvB,MAAc,EACd,QAAgB,EAChB,OAAuB,EACf,EAAE;IACV,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,aAAa,GAAG,eAAe,CACnC,MAAM,EACN,UAAU,CAAC,QAAQ,CAAC,CACrB,CAAC,QAAQ,EAAE,CAAC;IAEb,OAAO,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["import { BigNumber } from 'bignumber.js';\n\ntype FormatOptions = {\n decimalPlaces?: number;\n shouldEllipse?: boolean;\n};\nconst defaultFormatOptions = {\n decimalPlaces: 4,\n};\n\n/**\n * Calculates the token amount based on the given value and decimals.\n *\n * @param value - The value to calculate the token amount from.\n * @param decimals - The number of decimals to use for the calculation.\n * @returns The calculated token amount.\n */\nexport function calcTokenAmount(value: string, decimals: number): BigNumber {\n const multiplier = Math.pow(10, Number(decimals || 0));\n return new BigNumber(String(value)).div(multiplier);\n}\n\n/**\n * Calculates the number of leading zeros in the fractional part of a number.\n *\n * This function converts a number or a string representation of a number into\n * its decimal form and then counts the number of leading zeros present in the\n * fractional part of the number. This is useful for determining the precision\n * of very small numbers.\n *\n * @param numericValue - The number to analyze, which can be in the form\n * of a number or a string.\n * @returns The count of leading zeros in the fractional part of the number.\n */\nexport const getLeadingZeroCount = (numericValue: number | string): number => {\n const numToString = new BigNumber(numericValue, 10).toString(10);\n const fractionalPart = numToString.split('.')[1] ?? '';\n return fractionalPart.match(/^0*/u)?.[0]?.length ?? 0;\n};\n\n/**\n * This formats a number using Intl\n * It abbreviates large numbers (using K, M, B, T)\n * And abbreviates small numbers in 2 ways:\n * - Will format to the given number of decimal places\n * - Will format up to 4 decimal places\n * - Will ellipse the number if longer than given decimal places\n *\n * @param numericAmount - The number to format\n * @param opts - The options to use when formatting\n * @returns The formatted number\n */\nexport const formatAmount = (\n numericAmount: number,\n opts?: FormatOptions,\n): string => {\n // create options with defaults\n const options = { ...defaultFormatOptions, ...opts };\n\n const leadingZeros = getLeadingZeroCount(numericAmount);\n const isDecimal = numericAmount.toString().includes('.') || leadingZeros > 0;\n const isLargeNumber = numericAmount > 999;\n\n const handleShouldEllipse = (decimalPlaces: number): boolean =>\n Boolean(options?.shouldEllipse) && leadingZeros >= decimalPlaces;\n\n if (isLargeNumber) {\n return Intl.NumberFormat('en-US', {\n notation: 'compact',\n compactDisplay: 'short',\n maximumFractionDigits: 2,\n }).format(numericAmount);\n }\n\n if (isDecimal) {\n const ellipse = handleShouldEllipse(options.decimalPlaces);\n const formattedValue = Intl.NumberFormat('en-US', {\n minimumFractionDigits: ellipse ? options.decimalPlaces : undefined,\n maximumFractionDigits: options.decimalPlaces,\n }).format(numericAmount);\n\n return ellipse ? `${formattedValue}...` : formattedValue;\n }\n\n // Default to showing the raw amount\n return numericAmount.toString();\n};\n\nexport const getAmount = (\n amount: string,\n decimals: string,\n options?: FormatOptions,\n): string => {\n if (!amount || !decimals) {\n return '';\n }\n\n const numericAmount = calcTokenAmount(\n amount,\n parseFloat(decimals),\n ).toNumber();\n\n return formatAmount(numericAmount, options);\n};\n"]}
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createOnChainPushNotificationMessage = exports.createOnChainPushNotificationMessages = void 0;
4
4
  const get_notification_data_1 = require("./get-notification-data.cjs");
5
- const ui_1 = require("../../NotificationServicesController/ui/index.cjs");
6
5
  /**
7
6
  * On Chain Push Notification Messages.
8
7
  * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension
@@ -11,7 +10,7 @@ const ui_1 = require("../../NotificationServicesController/ui/index.cjs");
11
10
  * @returns A translation push message object.
12
11
  */
13
12
  const createOnChainPushNotificationMessages = (translationKeys) => {
14
- const t = (...args) => {
13
+ const translate = (...args) => {
15
14
  const [key, ...otherArgs] = args;
16
15
  // Coerce types for the translation function
17
16
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -20,140 +19,131 @@ const createOnChainPushNotificationMessages = (translationKeys) => {
20
19
  };
21
20
  return {
22
21
  erc20_sent: {
23
- title: () => t('pushPlatformNotificationsFundsSentTitle'),
24
- defaultDescription: () => t('pushPlatformNotificationsFundsSentDescriptionDefault'),
25
- getDescription: (n) => {
26
- const symbol = n?.payload?.data?.token?.symbol;
27
- const tokenAmount = n?.payload?.data?.token?.amount;
28
- const tokenDecimals = n?.payload?.data?.token?.decimals;
22
+ title: () => translate('pushPlatformNotificationsFundsSentTitle'),
23
+ defaultDescription: () => translate('pushPlatformNotificationsFundsSentDescriptionDefault'),
24
+ getDescription: (notification) => {
25
+ const symbol = notification?.payload?.data?.token?.symbol;
26
+ const tokenAmount = notification?.payload?.data?.token?.amount;
27
+ const tokenDecimals = notification?.payload?.data?.token?.decimals;
29
28
  if (!symbol || !tokenAmount || !tokenDecimals) {
30
29
  return null;
31
30
  }
32
31
  const amount = (0, get_notification_data_1.getAmount)(tokenAmount, tokenDecimals, {
33
32
  shouldEllipse: true,
34
33
  });
35
- return t('pushPlatformNotificationsFundsSentDescription', amount, symbol);
34
+ return translate('pushPlatformNotificationsFundsSentDescription', amount, symbol);
36
35
  },
37
36
  },
38
37
  eth_sent: {
39
- title: () => t('pushPlatformNotificationsFundsSentTitle'),
40
- defaultDescription: () => t('pushPlatformNotificationsFundsSentDescriptionDefault'),
41
- getDescription: (n) => {
42
- const symbol = getChainSymbol(n?.payload?.chain_id);
43
- const tokenAmount = n?.payload?.data?.amount?.eth;
38
+ title: () => translate('pushPlatformNotificationsFundsSentTitle'),
39
+ defaultDescription: () => translate('pushPlatformNotificationsFundsSentDescriptionDefault'),
40
+ getDescription: (notification) => {
41
+ const symbol = notification?.payload?.network?.native_symbol;
42
+ const tokenAmount = notification?.payload?.data?.amount?.eth;
44
43
  if (!symbol || !tokenAmount) {
45
44
  return null;
46
45
  }
47
46
  const amount = (0, get_notification_data_1.formatAmount)(parseFloat(tokenAmount), {
48
47
  shouldEllipse: true,
49
48
  });
50
- return t('pushPlatformNotificationsFundsSentDescription', amount, symbol);
49
+ return translate('pushPlatformNotificationsFundsSentDescription', amount, symbol);
51
50
  },
52
51
  },
53
52
  erc20_received: {
54
- title: () => t('pushPlatformNotificationsFundsReceivedTitle'),
55
- defaultDescription: () => t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
56
- getDescription: (n) => {
57
- const symbol = n?.payload?.data?.token?.symbol;
58
- const tokenAmount = n?.payload?.data?.token?.amount;
59
- const tokenDecimals = n?.payload?.data?.token?.decimals;
53
+ title: () => translate('pushPlatformNotificationsFundsReceivedTitle'),
54
+ defaultDescription: () => translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
55
+ getDescription: (notification) => {
56
+ const symbol = notification?.payload?.data?.token?.symbol;
57
+ const tokenAmount = notification?.payload?.data?.token?.amount;
58
+ const tokenDecimals = notification?.payload?.data?.token?.decimals;
60
59
  if (!symbol || !tokenAmount || !tokenDecimals) {
61
60
  return null;
62
61
  }
63
62
  const amount = (0, get_notification_data_1.getAmount)(tokenAmount, tokenDecimals, {
64
63
  shouldEllipse: true,
65
64
  });
66
- return t('pushPlatformNotificationsFundsReceivedDescription', amount, symbol);
65
+ return translate('pushPlatformNotificationsFundsReceivedDescription', amount, symbol);
67
66
  },
68
67
  },
69
68
  eth_received: {
70
- title: () => t('pushPlatformNotificationsFundsReceivedTitle'),
71
- defaultDescription: () => t('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
72
- getDescription: (n) => {
73
- const symbol = getChainSymbol(n?.payload?.chain_id);
74
- const tokenAmount = n?.payload?.data?.amount?.eth;
69
+ title: () => translate('pushPlatformNotificationsFundsReceivedTitle'),
70
+ defaultDescription: () => translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),
71
+ getDescription: (notification) => {
72
+ const symbol = notification?.payload?.network?.native_symbol;
73
+ const tokenAmount = notification?.payload?.data?.amount?.eth;
75
74
  if (!symbol || !tokenAmount) {
76
75
  return null;
77
76
  }
78
77
  const amount = (0, get_notification_data_1.formatAmount)(parseFloat(tokenAmount), {
79
78
  shouldEllipse: true,
80
79
  });
81
- return t('pushPlatformNotificationsFundsReceivedDescription', amount, symbol);
80
+ return translate('pushPlatformNotificationsFundsReceivedDescription', amount, symbol);
82
81
  },
83
82
  },
84
83
  metamask_swap_completed: {
85
- title: () => t('pushPlatformNotificationsSwapCompletedTitle'),
86
- defaultDescription: () => t('pushPlatformNotificationsSwapCompletedDescription'),
84
+ title: () => translate('pushPlatformNotificationsSwapCompletedTitle'),
85
+ defaultDescription: () => translate('pushPlatformNotificationsSwapCompletedDescription'),
87
86
  },
88
87
  erc721_sent: {
89
- title: () => t('pushPlatformNotificationsNftSentTitle'),
90
- defaultDescription: () => t('pushPlatformNotificationsNftSentDescription'),
88
+ title: () => translate('pushPlatformNotificationsNftSentTitle'),
89
+ defaultDescription: () => translate('pushPlatformNotificationsNftSentDescription'),
91
90
  },
92
91
  erc1155_sent: {
93
- title: () => t('pushPlatformNotificationsNftSentTitle'),
94
- defaultDescription: () => t('pushPlatformNotificationsNftSentDescription'),
92
+ title: () => translate('pushPlatformNotificationsNftSentTitle'),
93
+ defaultDescription: () => translate('pushPlatformNotificationsNftSentDescription'),
95
94
  },
96
95
  erc721_received: {
97
- title: () => t('pushPlatformNotificationsNftReceivedTitle'),
98
- defaultDescription: () => t('pushPlatformNotificationsNftReceivedDescription'),
96
+ title: () => translate('pushPlatformNotificationsNftReceivedTitle'),
97
+ defaultDescription: () => translate('pushPlatformNotificationsNftReceivedDescription'),
99
98
  },
100
99
  erc1155_received: {
101
- title: () => t('pushPlatformNotificationsNftReceivedTitle'),
102
- defaultDescription: () => t('pushPlatformNotificationsNftReceivedDescription'),
100
+ title: () => translate('pushPlatformNotificationsNftReceivedTitle'),
101
+ defaultDescription: () => translate('pushPlatformNotificationsNftReceivedDescription'),
103
102
  },
104
103
  rocketpool_stake_completed: {
105
- title: () => t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),
106
- defaultDescription: () => t('pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription'),
104
+ title: () => translate('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),
105
+ defaultDescription: () => translate('pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription'),
107
106
  },
108
107
  rocketpool_unstake_completed: {
109
- title: () => t('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle'),
110
- defaultDescription: () => t('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription'),
108
+ title: () => translate('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle'),
109
+ defaultDescription: () => translate('pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription'),
111
110
  },
112
111
  lido_stake_completed: {
113
- title: () => t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),
114
- defaultDescription: () => t('pushPlatformNotificationsStakingLidoStakeCompletedDescription'),
112
+ title: () => translate('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),
113
+ defaultDescription: () => translate('pushPlatformNotificationsStakingLidoStakeCompletedDescription'),
115
114
  },
116
115
  lido_stake_ready_to_be_withdrawn: {
117
- title: () => t('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle'),
118
- defaultDescription: () => t('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription'),
116
+ title: () => translate('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle'),
117
+ defaultDescription: () => translate('pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription'),
119
118
  },
120
119
  lido_withdrawal_requested: {
121
- title: () => t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),
122
- defaultDescription: () => t('pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription'),
120
+ title: () => translate('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),
121
+ defaultDescription: () => translate('pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription'),
123
122
  },
124
123
  lido_withdrawal_completed: {
125
- title: () => t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),
126
- defaultDescription: () => t('pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription'),
124
+ title: () => translate('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),
125
+ defaultDescription: () => translate('pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription'),
127
126
  },
128
127
  platform: {
129
- title: (n) => n.template.title,
130
- defaultDescription: (n) => n.template.body,
131
- getDescription: (n) => n.template.body,
128
+ title: (notification) => notification.template.title,
129
+ defaultDescription: (notification) => notification.template.body,
130
+ getDescription: (notification) => notification.template.body,
132
131
  },
133
132
  };
134
133
  };
135
134
  exports.createOnChainPushNotificationMessages = createOnChainPushNotificationMessages;
136
- /**
137
- * Retrieves the symbol associated with a given chain ID.
138
- *
139
- * @param chainId - The ID of the chain.
140
- * @returns The symbol associated with the chain ID, or null if not found.
141
- */
142
- function getChainSymbol(chainId) {
143
- return (ui_1.NOTIFICATION_NETWORK_CURRENCY_SYMBOL[chainId.toString()] ?? null);
144
- }
145
135
  /**
146
136
  * Creates a push notification message based on the given on-chain raw notification.
147
137
  *
148
- * @param n - processed notification.
138
+ * @param notification - processed notification.
149
139
  * @param translations - translates keys into text
150
140
  * @returns The push notification message object, or null if the notification is invalid.
151
141
  */
152
- function createOnChainPushNotificationMessage(n, translations) {
153
- if (!n?.type) {
142
+ function createOnChainPushNotificationMessage(notification, translations) {
143
+ if (!notification?.type) {
154
144
  return null;
155
145
  }
156
- const notificationMessage = (0, exports.createOnChainPushNotificationMessages)(translations)[n.type];
146
+ const notificationMessage = (0, exports.createOnChainPushNotificationMessages)(translations)[notification.type];
157
147
  if (!notificationMessage) {
158
148
  return null;
159
149
  }
@@ -161,18 +151,19 @@ function createOnChainPushNotificationMessage(n, translations) {
161
151
  try {
162
152
  description =
163
153
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
164
- notificationMessage?.getDescription?.(n) ??
154
+ notificationMessage?.getDescription?.(notification) ??
165
155
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
166
- notificationMessage.defaultDescription?.(n) ??
156
+ notificationMessage.defaultDescription?.(notification) ??
167
157
  null;
168
158
  }
169
159
  catch {
170
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
- description = notificationMessage.defaultDescription?.(n) ?? null;
160
+ description =
161
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
+ notificationMessage.defaultDescription?.(notification) ?? null;
172
163
  }
173
164
  return {
174
165
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
175
- title: notificationMessage?.title?.(n) ?? '', // Ensure title is always a string
166
+ title: notificationMessage?.title?.(notification) ?? '', // Ensure title is always a string
176
167
  description: description ?? '', // Fallback to empty string if null
177
168
  };
178
169
  }