@metamask/notification-services-controller 0.20.1 → 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 +34 -3
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +80 -80
  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 +81 -81
  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 +15 -5
  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,35 @@ 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
+
28
+ ## [0.21.0]
29
+
30
+ ### Added
31
+
32
+ - Lock conditional checks when initializing accounts inside the `NotificationServicesController` ([#5323](https://github.com/MetaMask/core/pull/5323))
33
+ - Accounts initialize call when the wallet is unlocked ([#5323](https://github.com/MetaMask/core/pull/5323))
34
+
35
+ ### Changed
36
+
37
+ - **BREAKING:** Bump `@metamask/profile-sync-controller` peer dependency from `^7.0.0` to `^8.0.0` ([#5318](https://github.com/MetaMask/core/pull/5318))
38
+
10
39
  ## [0.20.1]
11
40
 
12
41
  ### Changed
@@ -37,7 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
37
66
 
38
67
  ### Changed
39
68
 
40
- - **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))
41
70
 
42
71
  ## [0.16.0]
43
72
 
@@ -82,7 +111,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
82
111
 
83
112
  ### Fixed
84
113
 
85
- - 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))
86
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.
87
116
 
88
117
  ## [0.12.0]
@@ -308,7 +337,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
308
337
 
309
338
  - Initial release
310
339
 
311
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.20.1...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
342
+ [0.21.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.20.1...@metamask/notification-services-controller@0.21.0
312
343
  [0.20.1]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.20.0...@metamask/notification-services-controller@0.20.1
313
344
  [0.20.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.19.0...@metamask/notification-services-controller@0.20.0
314
345
  [0.19.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.18.0...@metamask/notification-services-controller@0.19.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,41 +202,39 @@ 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
  });
250
235
  _NotificationServicesController_accounts.set(this, {
236
+ // Flag to ensure we only setup once
237
+ isNotificationAccountsSetup: false,
251
238
  /**
252
239
  * Used to get list of addresses from keyring (wallet addresses)
253
240
  *
@@ -256,7 +243,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
256
243
  listAccounts: async () => {
257
244
  // Get previous and current account sets
258
245
  const nonChecksumAccounts = await this.messagingSystem.call('KeyringController:getAccounts');
259
- 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));
260
249
  const currentAccountsSet = new Set(accounts);
261
250
  const prevAccountsSet = new Set(this.state.subscriptionAccountsSeen);
262
251
  // Invalid value you cannot have zero accounts
@@ -286,8 +275,12 @@ class NotificationServicesController extends base_controller_1.BaseController {
286
275
  *
287
276
  * @returns result from list accounts
288
277
  */
289
- initialize: () => {
290
- return __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
278
+ initialize: async () => {
279
+ if (__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked &&
280
+ !__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup) {
281
+ await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
282
+ __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup = true;
283
+ }
291
284
  },
292
285
  /**
293
286
  * Subscription to any state change in the keyring controller (aka wallet accounts).
@@ -312,11 +305,13 @@ class NotificationServicesController extends base_controller_1.BaseController {
312
305
  },
313
306
  });
314
307
  _NotificationServicesController_featureAnnouncementEnv.set(this, void 0);
315
- __classPrivateFieldSet(this, _NotificationServicesController_isPushIntegrated, env.isPushIntegrated ?? true, "f");
316
308
  __classPrivateFieldSet(this, _NotificationServicesController_featureAnnouncementEnv, env.featureAnnouncements, "f");
317
309
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerMessageHandlers).call(this);
318
310
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_clearLoadingStates).call(this);
319
- __classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").setupLockedStateSubscriptions(__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").initializePushNotifications);
311
+ __classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").setupLockedStateSubscriptions(async () => {
312
+ await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
313
+ await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").initializePushNotifications();
314
+ });
320
315
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
321
316
  __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
322
317
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
@@ -325,15 +320,22 @@ class NotificationServicesController extends base_controller_1.BaseController {
325
320
  __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").subscribe();
326
321
  }
327
322
  /**
328
- * Retrieves the current enabled state of MetaMask notifications.
329
- *
330
- * This method directly returns the boolean value of `isMetamaskNotificationsEnabled`
331
- * from the controller's state, indicating whether MetaMask notifications are currently enabled.
332
- *
333
- * @returns The enabled state of MetaMask notifications.
323
+ * Public method to expose enabling push notifications
334
324
  */
335
- selectIsNotificationServicesEnabled() {
336
- 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();
337
339
  }
338
340
  async checkAccountsPresence(accounts) {
339
341
  try {
@@ -439,10 +441,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
439
441
  async enableMetamaskNotifications() {
440
442
  try {
441
443
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
442
- const isSignedIn = __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").isSignedIn();
443
- if (!isSignedIn) {
444
- await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").signIn();
445
- }
444
+ await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_enableAuth).call(this);
446
445
  await this.createOnChainTriggers();
447
446
  }
448
447
  catch (e) {
@@ -462,30 +461,25 @@ class NotificationServicesController extends base_controller_1.BaseController {
462
461
  * @throws {Error} If the user is not authenticated or if there is an error during the process.
463
462
  */
464
463
  async disableNotificationServices() {
464
+ __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
465
+ // Attempt Disable Push Notifications
465
466
  try {
466
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
467
- // Disable Push Notifications
468
- const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
469
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
470
- const UUIDs = Utils.getAllUUIDs(userStorage);
471
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").disablePushNotifications(UUIDs);
472
- const snapNotifications = this.state.metamaskNotificationsList.filter((notification) => notification.type === notification_schema_1.TRIGGER_TYPES.SNAP);
473
- // Clear Notification States (toggles and list)
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
- }
482
- catch (e) {
483
- loglevel_1.default.error('Unable to disable notifications', e);
484
- throw new Error('Unable to disable notifications');
467
+ await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").disablePushNotifications();
485
468
  }
486
- finally {
487
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, false);
469
+ catch {
470
+ // Do nothing
488
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);
489
483
  }
490
484
  /**
491
485
  * Deletes on-chain triggers associated with a specific account.
@@ -518,8 +512,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
518
512
  }
519
513
  // Delete these UUIDs (Mutates User Storage)
520
514
  await OnChainNotifications.deleteOnChainTriggers(userStorage, storageKey, bearerToken, UUIDs);
521
- // Delete these UUIDs from the push notifications
522
- 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);
523
518
  // Update User Storage
524
519
  await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
525
520
  return userStorage;
@@ -810,10 +805,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
810
805
  }
811
806
  }
812
807
  }
813
- _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() {
814
809
  this.messagingSystem.registerActionHandler(`${controllerName}:updateMetamaskNotificationsList`, this.updateMetamaskNotificationsList.bind(this));
815
810
  this.messagingSystem.registerActionHandler(`${controllerName}:disableNotificationServices`, this.disableNotificationServices.bind(this));
816
- this.messagingSystem.registerActionHandler(`${controllerName}:selectIsNotificationServicesEnabled`, this.selectIsNotificationServicesEnabled.bind(this));
817
811
  this.messagingSystem.registerActionHandler(`${controllerName}:getNotificationsByType`, this.getNotificationsByType.bind(this));
818
812
  this.messagingSystem.registerActionHandler(`${controllerName}:deleteNotificationsById`, this.deleteNotificationsById.bind(this));
819
813
  }, _NotificationServicesController_clearLoadingStates = function _NotificationServicesController_clearLoadingStates() {
@@ -830,6 +824,11 @@ _NotificationServicesController_isPushIntegrated = new WeakMap(), _NotificationS
830
824
  });
831
825
  throw new Error('User is not signed in.');
832
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
+ }
833
832
  }, _NotificationServicesController_getValidStorageKeyAndBearerToken = async function _NotificationServicesController_getValidStorageKeyAndBearerToken() {
834
833
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertAuthEnabled).call(this);
835
834
  const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken();
@@ -859,6 +858,7 @@ async function _NotificationServicesController_getUserStorage() {
859
858
  }
860
859
  try {
861
860
  const userStorage = JSON.parse(userStorageString);
861
+ Utils.cleanUserStorage(userStorage);
862
862
  return userStorage;
863
863
  }
864
864
  catch {