@metamask/notification-services-controller 0.21.0 → 1.0.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 (148) hide show
  1. package/CHANGELOG.md +22 -3
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +70 -78
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts +10 -34
  5. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts +10 -34
  7. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/NotificationServicesController.mjs +71 -79
  9. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  10. package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.cjs +1 -1
  11. package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.cjs.map +1 -1
  12. package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.d.cts.map +1 -1
  13. package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.d.mts.map +1 -1
  14. package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.mjs +1 -1
  15. package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.mjs.map +1 -1
  16. package/dist/NotificationServicesController/__fixtures__/mockAddresses.cjs +6 -0
  17. package/dist/NotificationServicesController/__fixtures__/mockAddresses.cjs.map +1 -0
  18. package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.cts +3 -0
  19. package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.cts.map +1 -0
  20. package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.mts +3 -0
  21. package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.mts.map +1 -0
  22. package/dist/NotificationServicesController/__fixtures__/mockAddresses.mjs +3 -0
  23. package/dist/NotificationServicesController/__fixtures__/mockAddresses.mjs.map +1 -0
  24. package/dist/NotificationServicesController/index.cjs +1 -0
  25. package/dist/NotificationServicesController/index.cjs.map +1 -1
  26. package/dist/NotificationServicesController/index.d.cts +1 -0
  27. package/dist/NotificationServicesController/index.d.cts.map +1 -1
  28. package/dist/NotificationServicesController/index.d.mts +1 -0
  29. package/dist/NotificationServicesController/index.d.mts.map +1 -1
  30. package/dist/NotificationServicesController/index.mjs +1 -0
  31. package/dist/NotificationServicesController/index.mjs.map +1 -1
  32. package/dist/NotificationServicesController/services/onchain-notifications.cjs +1 -0
  33. package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +1 -1
  34. package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +1 -1
  35. package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +1 -1
  36. package/dist/NotificationServicesController/services/onchain-notifications.mjs +2 -1
  37. package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +1 -1
  38. package/dist/NotificationServicesController/utils/utils.cjs +28 -2
  39. package/dist/NotificationServicesController/utils/utils.cjs.map +1 -1
  40. package/dist/NotificationServicesController/utils/utils.d.cts +11 -1
  41. package/dist/NotificationServicesController/utils/utils.d.cts.map +1 -1
  42. package/dist/NotificationServicesController/utils/utils.d.mts +11 -1
  43. package/dist/NotificationServicesController/utils/utils.d.mts.map +1 -1
  44. package/dist/NotificationServicesController/utils/utils.mjs +26 -1
  45. package/dist/NotificationServicesController/utils/utils.mjs.map +1 -1
  46. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +97 -57
  47. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  48. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +19 -24
  49. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  50. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +19 -24
  51. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  52. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +98 -58
  53. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  54. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs +14 -0
  55. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs.map +1 -0
  56. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts +3 -0
  57. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts.map +1 -0
  58. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts +3 -0
  59. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts.map +1 -0
  60. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs +10 -0
  61. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs.map +1 -0
  62. package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs +1 -13
  63. package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs.map +1 -1
  64. package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts +0 -1
  65. package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts.map +1 -1
  66. package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts +0 -1
  67. package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts.map +1 -1
  68. package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs +1 -12
  69. package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs.map +1 -1
  70. package/dist/NotificationServicesPushController/services/services.cjs +19 -93
  71. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  72. package/dist/NotificationServicesPushController/services/services.d.cts +5 -29
  73. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  74. package/dist/NotificationServicesPushController/services/services.d.mts +5 -29
  75. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  76. package/dist/NotificationServicesPushController/services/services.mjs +18 -94
  77. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  78. package/dist/NotificationServicesPushController/types/index.cjs.map +1 -1
  79. package/dist/NotificationServicesPushController/types/index.d.cts +1 -0
  80. package/dist/NotificationServicesPushController/types/index.d.cts.map +1 -1
  81. package/dist/NotificationServicesPushController/types/index.d.mts +1 -0
  82. package/dist/NotificationServicesPushController/types/index.d.mts.map +1 -1
  83. package/dist/NotificationServicesPushController/types/index.mjs.map +1 -1
  84. package/dist/NotificationServicesPushController/{services/push/index.cjs → types/push-service-interface.cjs} +1 -1
  85. package/dist/NotificationServicesPushController/types/push-service-interface.cjs.map +1 -0
  86. package/dist/NotificationServicesPushController/types/push-service-interface.d.cts +30 -0
  87. package/dist/NotificationServicesPushController/types/push-service-interface.d.cts.map +1 -0
  88. package/dist/NotificationServicesPushController/types/push-service-interface.d.mts +30 -0
  89. package/dist/NotificationServicesPushController/types/push-service-interface.d.mts.map +1 -0
  90. package/dist/NotificationServicesPushController/types/push-service-interface.mjs +2 -0
  91. package/dist/NotificationServicesPushController/types/push-service-interface.mjs.map +1 -0
  92. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +1 -19
  93. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
  94. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +0 -7
  95. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
  96. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +0 -7
  97. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
  98. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +0 -17
  99. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
  100. package/dist/NotificationServicesPushController/web/index.cjs +8 -0
  101. package/dist/NotificationServicesPushController/web/index.cjs.map +1 -0
  102. package/dist/NotificationServicesPushController/web/index.d.cts +2 -0
  103. package/dist/NotificationServicesPushController/web/index.d.cts.map +1 -0
  104. package/dist/NotificationServicesPushController/web/index.d.mts +2 -0
  105. package/dist/NotificationServicesPushController/web/index.d.mts.map +1 -0
  106. package/dist/NotificationServicesPushController/web/index.mjs +2 -0
  107. package/dist/NotificationServicesPushController/web/index.mjs.map +1 -0
  108. package/dist/NotificationServicesPushController/web/push-utils.cjs +170 -0
  109. package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -0
  110. package/dist/NotificationServicesPushController/web/push-utils.d.cts +37 -0
  111. package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -0
  112. package/dist/NotificationServicesPushController/web/push-utils.d.mts +37 -0
  113. package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -0
  114. package/dist/NotificationServicesPushController/web/push-utils.mjs +168 -0
  115. package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -0
  116. package/dist/shared/index.cjs +19 -0
  117. package/dist/shared/index.cjs.map +1 -0
  118. package/dist/shared/index.d.cts +3 -0
  119. package/dist/shared/index.d.cts.map +1 -0
  120. package/dist/shared/index.d.mts +3 -0
  121. package/dist/shared/index.d.mts.map +1 -0
  122. package/dist/shared/index.mjs +3 -0
  123. package/dist/shared/index.mjs.map +1 -0
  124. package/dist/shared/is-onchain-notification.cjs +22 -0
  125. package/dist/shared/is-onchain-notification.cjs.map +1 -0
  126. package/dist/shared/is-onchain-notification.d.cts +9 -0
  127. package/dist/shared/is-onchain-notification.d.cts.map +1 -0
  128. package/dist/shared/is-onchain-notification.d.mts +9 -0
  129. package/dist/shared/is-onchain-notification.d.mts.map +1 -0
  130. package/dist/shared/is-onchain-notification.mjs +18 -0
  131. package/dist/shared/is-onchain-notification.mjs.map +1 -0
  132. package/package.json +14 -4
  133. package/push-services/web/package.json +9 -0
  134. package/dist/NotificationServicesPushController/constants.cjs +0 -14
  135. package/dist/NotificationServicesPushController/constants.cjs.map +0 -1
  136. package/dist/NotificationServicesPushController/constants.d.cts +0 -11
  137. package/dist/NotificationServicesPushController/constants.d.cts.map +0 -1
  138. package/dist/NotificationServicesPushController/constants.d.mts +0 -11
  139. package/dist/NotificationServicesPushController/constants.d.mts.map +0 -1
  140. package/dist/NotificationServicesPushController/constants.mjs +0 -11
  141. package/dist/NotificationServicesPushController/constants.mjs.map +0 -1
  142. package/dist/NotificationServicesPushController/services/push/index.cjs.map +0 -1
  143. package/dist/NotificationServicesPushController/services/push/index.d.cts +0 -6
  144. package/dist/NotificationServicesPushController/services/push/index.d.cts.map +0 -1
  145. package/dist/NotificationServicesPushController/services/push/index.d.mts +0 -6
  146. package/dist/NotificationServicesPushController/services/push/index.d.mts.map +0 -1
  147. package/dist/NotificationServicesPushController/services/push/index.mjs +0 -2
  148. package/dist/NotificationServicesPushController/services/push/index.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.0.0]
11
+
12
+ ### Added
13
+
14
+ - added new public methods `enablePushNotifications` and `disablePushNotification` on `NotificationServicesController` ([#5120](https://github.com/MetaMask/core/pull/5120))
15
+ - added `isPushEnabled` and `isUpdatingFCMToken` to `NotificationServicesPushController` state ([#5120](https://github.com/MetaMask/core/pull/5120))
16
+ - added `/push-services/web` subpath export to make it easier to import web helpers ([#5120](https://github.com/MetaMask/core/pull/5120))
17
+
18
+ ### Changed
19
+
20
+ - **BREAKING**: updated `NotificationServicesPushController` constructor config to require a push interface ([#5120](https://github.com/MetaMask/core/pull/5120))
21
+ - Optimized API calls for creating push notification links ([#5358](https://github.com/MetaMask/core/pull/5358))
22
+ - Bump `@metamask/utils` from `^11.1.0` to `^11.2.0` ([#5301](https://github.com/MetaMask/core/pull/5301))
23
+
24
+ ### Fixed
25
+
26
+ - only allow hex addresses when creating notifications ([#5343](https://github.com/MetaMask/core/pull/5343))
27
+
10
28
  ## [0.21.0]
11
29
 
12
30
  ### Added
@@ -48,7 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
48
66
 
49
67
  ### Changed
50
68
 
51
- - **BREAKING:** Bump depenency `firebase` from `^10.11.0` to `^11.2.0` ([#5196](https://github.com/MetaMask/core/pull/5196))
69
+ - Bump `firebase` from `^10.11.0` to `^11.2.0` ([#5196](https://github.com/MetaMask/core/pull/5196))
52
70
 
53
71
  ## [0.16.0]
54
72
 
@@ -93,7 +111,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
93
111
 
94
112
  ### Fixed
95
113
 
96
- - fix: allow snap notifications to be visbible when controller is disabled ([#4890](https://github.com/MetaMask/core/pull/4890))
114
+ - fix: allow snap notifications to be visible when controller is disabled ([#4890](https://github.com/MetaMask/core/pull/4890))
97
115
  - Most notification services are switched off when the controller is disabled, but since snaps are "local notifications", they need to be visible irrespective to the controller disabled state.
98
116
 
99
117
  ## [0.12.0]
@@ -319,7 +337,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
319
337
 
320
338
  - Initial release
321
339
 
322
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.21.0...HEAD
340
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@1.0.0...HEAD
341
+ [1.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.21.0...@metamask/notification-services-controller@1.0.0
323
342
  [0.21.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.20.1...@metamask/notification-services-controller@0.21.0
324
343
  [0.20.1]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.20.0...@metamask/notification-services-controller@0.20.1
325
344
  [0.20.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.19.0...@metamask/notification-services-controller@0.20.0
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _NotificationServicesController_instances, _NotificationServicesController_isPushIntegrated, _NotificationServicesController_isPushNotificationsSetup, _NotificationServicesController_isUnlocked, _NotificationServicesController_keyringController, _NotificationServicesController_auth, _NotificationServicesController_storage, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_getValidStorageKeyAndBearerToken, _NotificationServicesController_assertUserStorage, _NotificationServicesController_getUserStorage, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
39
+ var _NotificationServicesController_instances, _NotificationServicesController_keyringController, _NotificationServicesController_auth, _NotificationServicesController_storage, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth, _NotificationServicesController_getValidStorageKeyAndBearerToken, _NotificationServicesController_assertUserStorage, _NotificationServicesController_getUserStorage, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.defaultState = void 0;
42
42
  const base_controller_1 = require("@metamask/base-controller");
@@ -130,26 +130,20 @@ class NotificationServicesController extends base_controller_1.BaseController {
130
130
  state: { ...exports.defaultState, ...state },
131
131
  });
132
132
  _NotificationServicesController_instances.add(this);
133
- // Temporary boolean as push notifications are not yet enabled on mobile
134
- _NotificationServicesController_isPushIntegrated.set(this, true);
135
- // Flag to check is notifications have been setup when the browser/extension is initialized.
136
- // We want to re-initialize push notifications when the browser/extension is refreshed
137
- // To ensure we subscribe to the most up-to-date notifications
138
- _NotificationServicesController_isPushNotificationsSetup.set(this, false);
139
- _NotificationServicesController_isUnlocked.set(this, false);
140
133
  _NotificationServicesController_keyringController.set(this, {
134
+ isUnlocked: false,
141
135
  setupLockedStateSubscriptions: (onUnlock) => {
142
136
  const { isUnlocked } = this.messagingSystem.call('KeyringController:getState');
143
- __classPrivateFieldSet(this, _NotificationServicesController_isUnlocked, isUnlocked, "f");
137
+ __classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = isUnlocked;
144
138
  this.messagingSystem.subscribe('KeyringController:unlock', () => {
145
- __classPrivateFieldSet(this, _NotificationServicesController_isUnlocked, true, "f");
139
+ __classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = true;
146
140
  // messaging system cannot await promises
147
141
  // we don't need to wait for a result on this.
148
142
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
149
143
  onUnlock();
150
144
  });
151
145
  this.messagingSystem.subscribe('KeyringController:lock', () => {
152
- __classPrivateFieldSet(this, _NotificationServicesController_isUnlocked, false, "f");
146
+ __classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = false;
153
147
  });
154
148
  },
155
149
  });
@@ -176,13 +170,14 @@ class NotificationServicesController extends base_controller_1.BaseController {
176
170
  },
177
171
  });
178
172
  _NotificationServicesController_pushNotifications.set(this, {
173
+ // Flag to check is notifications have been setup when the browser/extension is initialized.
174
+ // We want to re-initialize push notifications when the browser/extension is refreshed
175
+ // To ensure we subscribe to the most up-to-date notifications
176
+ isSetup: false,
179
177
  subscribeToPushNotifications: async () => {
180
178
  await this.messagingSystem.call('NotificationServicesPushController:subscribeToPushNotifications');
181
179
  },
182
180
  enablePushNotifications: async (UUIDs) => {
183
- if (!__classPrivateFieldGet(this, _NotificationServicesController_isPushIntegrated, "f")) {
184
- return;
185
- }
186
181
  try {
187
182
  await this.messagingSystem.call('NotificationServicesPushController:enablePushNotifications', UUIDs);
188
183
  }
@@ -190,21 +185,15 @@ class NotificationServicesController extends base_controller_1.BaseController {
190
185
  loglevel_1.default.error('Silently failed to enable push notifications', e);
191
186
  }
192
187
  },
193
- disablePushNotifications: async (UUIDs) => {
194
- if (!__classPrivateFieldGet(this, _NotificationServicesController_isPushIntegrated, "f")) {
195
- return;
196
- }
188
+ disablePushNotifications: async () => {
197
189
  try {
198
- await this.messagingSystem.call('NotificationServicesPushController:disablePushNotifications', UUIDs);
190
+ await this.messagingSystem.call('NotificationServicesPushController:disablePushNotifications');
199
191
  }
200
192
  catch (e) {
201
193
  loglevel_1.default.error('Silently failed to disable push notifications', e);
202
194
  }
203
195
  },
204
196
  updatePushNotifications: async (UUIDs) => {
205
- if (!__classPrivateFieldGet(this, _NotificationServicesController_isPushIntegrated, "f")) {
206
- return;
207
- }
208
197
  try {
209
198
  await this.messagingSystem.call('NotificationServicesPushController:updateTriggerPushNotifications', UUIDs);
210
199
  }
@@ -213,37 +202,33 @@ class NotificationServicesController extends base_controller_1.BaseController {
213
202
  }
214
203
  },
215
204
  subscribe: () => {
216
- if (!__classPrivateFieldGet(this, _NotificationServicesController_isPushIntegrated, "f")) {
217
- return;
218
- }
219
205
  this.messagingSystem.subscribe('NotificationServicesPushController:onNewNotifications', (notification) => {
220
206
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
221
207
  this.updateMetamaskNotificationsList(notification);
222
208
  });
223
209
  },
224
210
  initializePushNotifications: async () => {
225
- if (!__classPrivateFieldGet(this, _NotificationServicesController_isPushIntegrated, "f")) {
226
- return;
227
- }
228
211
  if (!this.state.isNotificationServicesEnabled) {
229
212
  return;
230
213
  }
231
- if (__classPrivateFieldGet(this, _NotificationServicesController_isPushNotificationsSetup, "f")) {
214
+ if (__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").isSetup) {
232
215
  return;
233
216
  }
234
217
  // If wallet is unlocked, we can create a fresh push subscription
235
218
  // Otherwise we can subscribe to original subscription
236
- if (__classPrivateFieldGet(this, _NotificationServicesController_isUnlocked, "f")) {
237
- const storage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
238
- if (!storage) {
239
- return;
219
+ try {
220
+ if (!__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked) {
221
+ throw new Error('Keyring is locked');
240
222
  }
241
- const uuids = Utils.getAllUUIDs(storage);
242
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(uuids);
243
- __classPrivateFieldSet(this, _NotificationServicesController_isPushNotificationsSetup, true, "f");
223
+ await this.enablePushNotifications();
224
+ __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").isSetup = true;
244
225
  }
245
- else {
246
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").subscribeToPushNotifications();
226
+ catch {
227
+ await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f")
228
+ .subscribeToPushNotifications()
229
+ .catch(() => {
230
+ // do nothing
231
+ });
247
232
  }
248
233
  },
249
234
  });
@@ -258,7 +243,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
258
243
  listAccounts: async () => {
259
244
  // Get previous and current account sets
260
245
  const nonChecksumAccounts = await this.messagingSystem.call('KeyringController:getAccounts');
261
- const accounts = nonChecksumAccounts.map((a) => (0, controller_utils_1.toChecksumHexAddress)(a));
246
+ const accounts = nonChecksumAccounts
247
+ .map((a) => (0, controller_utils_1.toChecksumHexAddress)(a))
248
+ .filter((a) => (0, controller_utils_1.isValidHexAddress)(a));
262
249
  const currentAccountsSet = new Set(accounts);
263
250
  const prevAccountsSet = new Set(this.state.subscriptionAccountsSeen);
264
251
  // Invalid value you cannot have zero accounts
@@ -289,7 +276,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
289
276
  * @returns result from list accounts
290
277
  */
291
278
  initialize: async () => {
292
- if (__classPrivateFieldGet(this, _NotificationServicesController_isUnlocked, "f") && !__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup) {
279
+ if (__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked &&
280
+ !__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup) {
293
281
  await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
294
282
  __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup = true;
295
283
  }
@@ -317,7 +305,6 @@ class NotificationServicesController extends base_controller_1.BaseController {
317
305
  },
318
306
  });
319
307
  _NotificationServicesController_featureAnnouncementEnv.set(this, void 0);
320
- __classPrivateFieldSet(this, _NotificationServicesController_isPushIntegrated, env.isPushIntegrated ?? true, "f");
321
308
  __classPrivateFieldSet(this, _NotificationServicesController_featureAnnouncementEnv, env.featureAnnouncements, "f");
322
309
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerMessageHandlers).call(this);
323
310
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_clearLoadingStates).call(this);
@@ -333,15 +320,22 @@ class NotificationServicesController extends base_controller_1.BaseController {
333
320
  __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").subscribe();
334
321
  }
335
322
  /**
336
- * Retrieves the current enabled state of MetaMask notifications.
337
- *
338
- * This method directly returns the boolean value of `isMetamaskNotificationsEnabled`
339
- * from the controller's state, indicating whether MetaMask notifications are currently enabled.
340
- *
341
- * @returns The enabled state of MetaMask notifications.
323
+ * Public method to expose enabling push notifications
342
324
  */
343
- selectIsNotificationServicesEnabled() {
344
- return this.state.isNotificationServicesEnabled;
325
+ async enablePushNotifications() {
326
+ await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_enableAuth).call(this);
327
+ const storage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
328
+ if (!storage) {
329
+ throw new Error('Unable to get triggers');
330
+ }
331
+ const uuids = Utils.getAllUUIDs(storage);
332
+ await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(uuids);
333
+ }
334
+ /**
335
+ * Public method to expose disabling push notifications
336
+ */
337
+ async disablePushNotifications() {
338
+ await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").disablePushNotifications();
345
339
  }
346
340
  async checkAccountsPresence(accounts) {
347
341
  try {
@@ -447,10 +441,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
447
441
  async enableMetamaskNotifications() {
448
442
  try {
449
443
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
450
- const isSignedIn = __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").isSignedIn();
451
- if (!isSignedIn) {
452
- await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").signIn();
453
- }
444
+ await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_enableAuth).call(this);
454
445
  await this.createOnChainTriggers();
455
446
  }
456
447
  catch (e) {
@@ -470,30 +461,25 @@ class NotificationServicesController extends base_controller_1.BaseController {
470
461
  * @throws {Error} If the user is not authenticated or if there is an error during the process.
471
462
  */
472
463
  async disableNotificationServices() {
464
+ __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
465
+ // Attempt Disable Push Notifications
473
466
  try {
474
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
475
- // Disable Push Notifications
476
- const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
477
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
478
- const UUIDs = Utils.getAllUUIDs(userStorage);
479
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").disablePushNotifications(UUIDs);
480
- const snapNotifications = this.state.metamaskNotificationsList.filter((notification) => notification.type === notification_schema_1.TRIGGER_TYPES.SNAP);
481
- // Clear Notification States (toggles and list)
482
- this.update((state) => {
483
- state.isNotificationServicesEnabled = false;
484
- state.isFeatureAnnouncementsEnabled = false;
485
- // reassigning the notifications list with just snaps
486
- // since the disable shouldn't affect snaps notifications
487
- state.metamaskNotificationsList = snapNotifications;
488
- });
467
+ await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").disablePushNotifications();
489
468
  }
490
- catch (e) {
491
- loglevel_1.default.error('Unable to disable notifications', e);
492
- throw new Error('Unable to disable notifications');
493
- }
494
- finally {
495
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, false);
469
+ catch {
470
+ // Do nothing
496
471
  }
472
+ // Update State: remove non-permitted notifications & disable flags
473
+ const snapNotifications = this.state.metamaskNotificationsList.filter((notification) => notification.type === notification_schema_1.TRIGGER_TYPES.SNAP);
474
+ this.update((state) => {
475
+ state.isNotificationServicesEnabled = false;
476
+ state.isFeatureAnnouncementsEnabled = false;
477
+ // reassigning the notifications list with just snaps
478
+ // since the disable shouldn't affect snaps notifications
479
+ state.metamaskNotificationsList = snapNotifications;
480
+ });
481
+ // Finish Updating State
482
+ __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, false);
497
483
  }
498
484
  /**
499
485
  * Deletes on-chain triggers associated with a specific account.
@@ -526,8 +512,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
526
512
  }
527
513
  // Delete these UUIDs (Mutates User Storage)
528
514
  await OnChainNotifications.deleteOnChainTriggers(userStorage, storageKey, bearerToken, UUIDs);
529
- // Delete these UUIDs from the push notifications
530
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").disablePushNotifications(UUIDs);
515
+ // Update Push Notifications with new list of IDs
516
+ const remainingTriggerIds = Utils.getAllUUIDs(userStorage);
517
+ await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").updatePushNotifications(remainingTriggerIds);
531
518
  // Update User Storage
532
519
  await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
533
520
  return userStorage;
@@ -818,10 +805,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
818
805
  }
819
806
  }
820
807
  }
821
- _NotificationServicesController_isPushIntegrated = new WeakMap(), _NotificationServicesController_isPushNotificationsSetup = new WeakMap(), _NotificationServicesController_isUnlocked = new WeakMap(), _NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(), _NotificationServicesController_storage = new WeakMap(), _NotificationServicesController_pushNotifications = new WeakMap(), _NotificationServicesController_accounts = new WeakMap(), _NotificationServicesController_featureAnnouncementEnv = new WeakMap(), _NotificationServicesController_instances = new WeakSet(), _NotificationServicesController_registerMessageHandlers = function _NotificationServicesController_registerMessageHandlers() {
808
+ _NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(), _NotificationServicesController_storage = new WeakMap(), _NotificationServicesController_pushNotifications = new WeakMap(), _NotificationServicesController_accounts = new WeakMap(), _NotificationServicesController_featureAnnouncementEnv = new WeakMap(), _NotificationServicesController_instances = new WeakSet(), _NotificationServicesController_registerMessageHandlers = function _NotificationServicesController_registerMessageHandlers() {
822
809
  this.messagingSystem.registerActionHandler(`${controllerName}:updateMetamaskNotificationsList`, this.updateMetamaskNotificationsList.bind(this));
823
810
  this.messagingSystem.registerActionHandler(`${controllerName}:disableNotificationServices`, this.disableNotificationServices.bind(this));
824
- this.messagingSystem.registerActionHandler(`${controllerName}:selectIsNotificationServicesEnabled`, this.selectIsNotificationServicesEnabled.bind(this));
825
811
  this.messagingSystem.registerActionHandler(`${controllerName}:getNotificationsByType`, this.getNotificationsByType.bind(this));
826
812
  this.messagingSystem.registerActionHandler(`${controllerName}:deleteNotificationsById`, this.deleteNotificationsById.bind(this));
827
813
  }, _NotificationServicesController_clearLoadingStates = function _NotificationServicesController_clearLoadingStates() {
@@ -838,6 +824,11 @@ _NotificationServicesController_isPushIntegrated = new WeakMap(), _NotificationS
838
824
  });
839
825
  throw new Error('User is not signed in.');
840
826
  }
827
+ }, _NotificationServicesController_enableAuth = async function _NotificationServicesController_enableAuth() {
828
+ const isSignedIn = __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").isSignedIn();
829
+ if (!isSignedIn) {
830
+ await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").signIn();
831
+ }
841
832
  }, _NotificationServicesController_getValidStorageKeyAndBearerToken = async function _NotificationServicesController_getValidStorageKeyAndBearerToken() {
842
833
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertAuthEnabled).call(this);
843
834
  const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken();
@@ -867,6 +858,7 @@ async function _NotificationServicesController_getUserStorage() {
867
858
  }
868
859
  try {
869
860
  const userStorage = JSON.parse(userStorageString);
861
+ Utils.cleanUserStorage(userStorage);
870
862
  return userStorage;
871
863
  }
872
864
  catch {