@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.
- package/CHANGELOG.md +22 -3
- package/dist/NotificationServicesController/NotificationServicesController.cjs +70 -78
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +10 -34
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +10 -34
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +71 -79
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.cjs +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.cjs.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.d.cts.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.d.mts.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.mjs +1 -1
- package/dist/NotificationServicesController/__fixtures__/mock-notification-user-storage.mjs.map +1 -1
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.cjs +6 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.cjs.map +1 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.cts +3 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.cts.map +1 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.mts +3 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.d.mts.map +1 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.mjs +3 -0
- package/dist/NotificationServicesController/__fixtures__/mockAddresses.mjs.map +1 -0
- package/dist/NotificationServicesController/index.cjs +1 -0
- package/dist/NotificationServicesController/index.cjs.map +1 -1
- package/dist/NotificationServicesController/index.d.cts +1 -0
- package/dist/NotificationServicesController/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/index.d.mts +1 -0
- package/dist/NotificationServicesController/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/index.mjs +1 -0
- package/dist/NotificationServicesController/index.mjs.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.cjs +1 -0
- package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs +2 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/utils/utils.cjs +28 -2
- package/dist/NotificationServicesController/utils/utils.cjs.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.cts +11 -1
- package/dist/NotificationServicesController/utils/utils.d.cts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.mts +11 -1
- package/dist/NotificationServicesController/utils/utils.d.mts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.mjs +26 -1
- package/dist/NotificationServicesController/utils/utils.mjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +97 -57
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +19 -24
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +19 -24
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +98 -58
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs +14 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs.map +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts +3 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts +3 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs +10 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs.map +1 -0
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs +1 -13
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts +0 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs +1 -12
- package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.cjs +19 -93
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts +5 -29
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts +5 -29
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs +18 -94
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/dist/NotificationServicesPushController/types/index.cjs.map +1 -1
- package/dist/NotificationServicesPushController/types/index.d.cts +1 -0
- package/dist/NotificationServicesPushController/types/index.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/types/index.d.mts +1 -0
- package/dist/NotificationServicesPushController/types/index.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/types/index.mjs.map +1 -1
- package/dist/NotificationServicesPushController/{services/push/index.cjs → types/push-service-interface.cjs} +1 -1
- package/dist/NotificationServicesPushController/types/push-service-interface.cjs.map +1 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.d.cts +30 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.d.mts +30 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.mjs +2 -0
- package/dist/NotificationServicesPushController/types/push-service-interface.mjs.map +1 -0
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +1 -19
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +0 -7
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +0 -7
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +0 -17
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
- package/dist/NotificationServicesPushController/web/index.cjs +8 -0
- package/dist/NotificationServicesPushController/web/index.cjs.map +1 -0
- package/dist/NotificationServicesPushController/web/index.d.cts +2 -0
- package/dist/NotificationServicesPushController/web/index.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/web/index.d.mts +2 -0
- package/dist/NotificationServicesPushController/web/index.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/web/index.mjs +2 -0
- package/dist/NotificationServicesPushController/web/index.mjs.map +1 -0
- package/dist/NotificationServicesPushController/web/push-utils.cjs +170 -0
- package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -0
- package/dist/NotificationServicesPushController/web/push-utils.d.cts +37 -0
- package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -0
- package/dist/NotificationServicesPushController/web/push-utils.d.mts +37 -0
- package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -0
- package/dist/NotificationServicesPushController/web/push-utils.mjs +168 -0
- package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -0
- package/dist/shared/index.cjs +19 -0
- package/dist/shared/index.cjs.map +1 -0
- package/dist/shared/index.d.cts +3 -0
- package/dist/shared/index.d.cts.map +1 -0
- package/dist/shared/index.d.mts +3 -0
- package/dist/shared/index.d.mts.map +1 -0
- package/dist/shared/index.mjs +3 -0
- package/dist/shared/index.mjs.map +1 -0
- package/dist/shared/is-onchain-notification.cjs +22 -0
- package/dist/shared/is-onchain-notification.cjs.map +1 -0
- package/dist/shared/is-onchain-notification.d.cts +9 -0
- package/dist/shared/is-onchain-notification.d.cts.map +1 -0
- package/dist/shared/is-onchain-notification.d.mts +9 -0
- package/dist/shared/is-onchain-notification.d.mts.map +1 -0
- package/dist/shared/is-onchain-notification.mjs +18 -0
- package/dist/shared/is-onchain-notification.mjs.map +1 -0
- package/package.json +14 -4
- package/push-services/web/package.json +9 -0
- package/dist/NotificationServicesPushController/constants.cjs +0 -14
- package/dist/NotificationServicesPushController/constants.cjs.map +0 -1
- package/dist/NotificationServicesPushController/constants.d.cts +0 -11
- package/dist/NotificationServicesPushController/constants.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/constants.d.mts +0 -11
- package/dist/NotificationServicesPushController/constants.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/constants.mjs +0 -11
- package/dist/NotificationServicesPushController/constants.mjs.map +0 -1
- package/dist/NotificationServicesPushController/services/push/index.cjs.map +0 -1
- package/dist/NotificationServicesPushController/services/push/index.d.cts +0 -6
- package/dist/NotificationServicesPushController/services/push/index.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/services/push/index.d.mts +0 -6
- package/dist/NotificationServicesPushController/services/push/index.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/services/push/index.mjs +0 -2
- 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
|
-
-
|
|
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
|
|
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.
|
|
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,
|
|
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
|
-
|
|
137
|
+
__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = isUnlocked;
|
|
144
138
|
this.messagingSystem.subscribe('KeyringController:unlock', () => {
|
|
145
|
-
|
|
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
|
-
|
|
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 (
|
|
194
|
-
if (!__classPrivateFieldGet(this, _NotificationServicesController_isPushIntegrated, "f")) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
188
|
+
disablePushNotifications: async () => {
|
|
197
189
|
try {
|
|
198
|
-
await this.messagingSystem.call('NotificationServicesPushController:disablePushNotifications'
|
|
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,
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return;
|
|
219
|
+
try {
|
|
220
|
+
if (!__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked) {
|
|
221
|
+
throw new Error('Keyring is locked');
|
|
240
222
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
__classPrivateFieldSet(this, _NotificationServicesController_isPushNotificationsSetup, true, "f");
|
|
223
|
+
await this.enablePushNotifications();
|
|
224
|
+
__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").isSetup = true;
|
|
244
225
|
}
|
|
245
|
-
|
|
246
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f")
|
|
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
|
|
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,
|
|
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
|
-
*
|
|
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
|
-
|
|
344
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
491
|
-
|
|
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
|
-
//
|
|
530
|
-
|
|
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
|
-
|
|
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 {
|