@metamask-previews/notification-services-controller 10.0.0-preview-53749f1 → 10.0.0-preview-e11fb169
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 +0 -16
- package/dist/NotificationServicesController/NotificationServicesController.cjs +188 -67
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +16 -10
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +16 -10
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +189 -68
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/constants/constants.cjs +7 -0
- package/dist/NotificationServicesController/constants/constants.cjs.map +1 -0
- package/dist/NotificationServicesController/constants/constants.d.cts +3 -0
- package/dist/NotificationServicesController/constants/constants.d.cts.map +1 -0
- package/dist/NotificationServicesController/constants/constants.d.mts +3 -0
- package/dist/NotificationServicesController/constants/constants.d.mts.map +1 -0
- package/dist/NotificationServicesController/constants/constants.mjs +4 -0
- package/dist/NotificationServicesController/constants/constants.mjs.map +1 -0
- package/dist/NotificationServicesController/constants/index.cjs +1 -0
- package/dist/NotificationServicesController/constants/index.cjs.map +1 -1
- package/dist/NotificationServicesController/constants/index.d.cts +1 -0
- package/dist/NotificationServicesController/constants/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/constants/index.d.mts +1 -0
- package/dist/NotificationServicesController/constants/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/constants/index.mjs +1 -0
- package/dist/NotificationServicesController/constants/index.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/index.cjs +2 -0
- package/dist/NotificationServicesController/mocks/index.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/index.d.cts +2 -0
- package/dist/NotificationServicesController/mocks/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/index.d.mts +2 -0
- package/dist/NotificationServicesController/mocks/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/index.mjs +2 -0
- package/dist/NotificationServicesController/mocks/index.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.cjs +22 -0
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.cjs.map +1 -0
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.cts +9 -0
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.cts.map +1 -0
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.mts +9 -0
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.mts.map +1 -0
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.mjs +18 -0
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.mjs.map +1 -0
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.cjs +82 -0
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.cjs.map +1 -0
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.cts +35 -0
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.cts.map +1 -0
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.mts +35 -0
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.mts.map +1 -0
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.mjs +76 -0
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.mjs.map +1 -0
- package/dist/NotificationServicesController/mocks/mockResponses.cjs +9 -9
- package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts +4 -7
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts +4 -7
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.mjs +7 -7
- package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.cjs +1 -4
- package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.cts +0 -623
- package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.mts +0 -623
- package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.mjs +0 -2
- package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.cjs +142 -50
- package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.cts +31 -23
- package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.mts +31 -23
- package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs +139 -48
- package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/types/index.cjs.map +1 -1
- package/dist/NotificationServicesController/types/index.d.cts +1 -0
- package/dist/NotificationServicesController/types/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/index.d.mts +1 -0
- package/dist/NotificationServicesController/types/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/index.mjs.map +1 -1
- package/dist/NotificationServicesController/types/user-storage/index.cjs +3 -0
- package/dist/NotificationServicesController/types/user-storage/index.cjs.map +1 -0
- package/dist/NotificationServicesController/types/user-storage/index.d.cts +2 -0
- package/dist/NotificationServicesController/types/user-storage/index.d.cts.map +1 -0
- package/dist/NotificationServicesController/types/user-storage/index.d.mts +2 -0
- package/dist/NotificationServicesController/types/user-storage/index.d.mts.map +1 -0
- package/dist/NotificationServicesController/types/user-storage/index.mjs +2 -0
- package/dist/NotificationServicesController/types/user-storage/index.mjs.map +1 -0
- package/dist/NotificationServicesController/types/user-storage/user-storage.cjs +3 -0
- package/dist/NotificationServicesController/types/user-storage/user-storage.cjs.map +1 -0
- package/dist/NotificationServicesController/types/user-storage/user-storage.d.cts +26 -0
- package/dist/NotificationServicesController/types/user-storage/user-storage.d.cts.map +1 -0
- package/dist/NotificationServicesController/types/user-storage/user-storage.d.mts +26 -0
- package/dist/NotificationServicesController/types/user-storage/user-storage.d.mts.map +1 -0
- package/dist/NotificationServicesController/types/user-storage/user-storage.mjs +2 -0
- package/dist/NotificationServicesController/types/user-storage/user-storage.mjs.map +1 -0
- package/dist/NotificationServicesController/utils/utils.cjs +350 -1
- package/dist/NotificationServicesController/utils/utils.cjs.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.cts +141 -0
- package/dist/NotificationServicesController/utils/utils.d.cts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.mts +141 -0
- package/dist/NotificationServicesController/utils/utils.d.mts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.mjs +337 -0
- package/dist/NotificationServicesController/utils/utils.mjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +14 -20
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +5 -6
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +5 -6
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +15 -21
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.cjs +16 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +7 -0
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +7 -0
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.mjs +14 -0
- package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.cjs +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.cts +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.mts +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.mjs +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.cjs +41 -18
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts +33 -19
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts +33 -19
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs +39 -17
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,24 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
-
- **BREAKING:** Migrated to notification v2 endpoints ([#5945](https://github.com/MetaMask/core/pull/5945))
|
|
13
|
-
|
|
14
|
-
- `https://trigger.api.cx.metamask.io/api/v2` for managing out notification subscriptions
|
|
15
|
-
- `https://notification.api.cx.metamask.io/api/v2` for fetching notifications (in-app notifications)
|
|
16
|
-
- `https://push.api.cx.metamask.io/v2` for subscribing push notifications
|
|
17
|
-
- Renamed method `updateOnChainTriggersByAccount` to `enableAccounts` in `NotificationServicesController`
|
|
18
|
-
- Renamed method `deleteOnChainTriggersByAccount` to `disableAccounts` in `NotificationServicesController`
|
|
19
|
-
- Deprecated `updateTriggerPushNotifications` from `NotificationServicesPushController` and will be removed in a subsequent release.
|
|
20
|
-
|
|
21
12
|
- Bump `@metamask/controller-utils` to `^11.10.0` ([#5935](https://github.com/MetaMask/core/pull/5935))
|
|
22
13
|
|
|
23
|
-
### Removed
|
|
24
|
-
|
|
25
|
-
- **BREAKING:** Migrated to notification v2 endpoints ([#5945](https://github.com/MetaMask/core/pull/5945))
|
|
26
|
-
|
|
27
|
-
- removed `NotificationServicesPushController:updateTriggerPushNotifications` action from `NotificationServicesController`
|
|
28
|
-
- removed `UserStorageController` usage from `NotificationServicesController`.
|
|
29
|
-
|
|
30
14
|
## [10.0.0]
|
|
31
15
|
|
|
32
16
|
### Changed
|
|
@@ -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_keyringController, _NotificationServicesController_auth, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth,
|
|
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");
|
|
@@ -44,10 +44,12 @@ const controller_utils_1 = require("@metamask/controller-utils");
|
|
|
44
44
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
45
45
|
const utils_1 = require("@metamask/utils");
|
|
46
46
|
const loglevel_1 = __importDefault(require("loglevel"));
|
|
47
|
+
const constants_1 = require("./constants/constants.cjs");
|
|
47
48
|
const notification_schema_1 = require("./constants/notification-schema.cjs");
|
|
48
49
|
const process_notifications_1 = require("./processors/process-notifications.cjs");
|
|
49
50
|
const FeatureNotifications = __importStar(require("./services/feature-announcements.cjs"));
|
|
50
51
|
const OnChainNotifications = __importStar(require("./services/onchain-notifications.cjs"));
|
|
52
|
+
const Utils = __importStar(require("./utils/utils.cjs"));
|
|
51
53
|
// Unique name for the controller
|
|
52
54
|
const controllerName = 'NotificationServicesController';
|
|
53
55
|
const metadata = {
|
|
@@ -157,6 +159,17 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
157
159
|
return await this.messagingSystem.call('AuthenticationController:performSignIn');
|
|
158
160
|
},
|
|
159
161
|
});
|
|
162
|
+
_NotificationServicesController_storage.set(this, {
|
|
163
|
+
getStorageKey: () => {
|
|
164
|
+
return this.messagingSystem.call('UserStorageController:getStorageKey');
|
|
165
|
+
},
|
|
166
|
+
getNotificationStorage: async () => {
|
|
167
|
+
return await this.messagingSystem.call('UserStorageController:performGetStorage', 'notifications.notification_settings');
|
|
168
|
+
},
|
|
169
|
+
setNotificationStorage: async (state) => {
|
|
170
|
+
return await this.messagingSystem.call('UserStorageController:performSetStorage', 'notifications.notification_settings', state);
|
|
171
|
+
},
|
|
172
|
+
});
|
|
160
173
|
_NotificationServicesController_pushNotifications.set(this, {
|
|
161
174
|
// Flag to check is notifications have been setup when the browser/extension is initialized.
|
|
162
175
|
// We want to re-initialize push notifications when the browser/extension is refreshed
|
|
@@ -165,9 +178,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
165
178
|
subscribeToPushNotifications: async () => {
|
|
166
179
|
await this.messagingSystem.call('NotificationServicesPushController:subscribeToPushNotifications');
|
|
167
180
|
},
|
|
168
|
-
enablePushNotifications: async (
|
|
181
|
+
enablePushNotifications: async (UUIDs) => {
|
|
169
182
|
try {
|
|
170
|
-
await this.messagingSystem.call('NotificationServicesPushController:enablePushNotifications',
|
|
183
|
+
await this.messagingSystem.call('NotificationServicesPushController:enablePushNotifications', UUIDs);
|
|
171
184
|
}
|
|
172
185
|
catch (e) {
|
|
173
186
|
loglevel_1.default.error('Silently failed to enable push notifications', e);
|
|
@@ -181,6 +194,14 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
181
194
|
loglevel_1.default.error('Silently failed to disable push notifications', e);
|
|
182
195
|
}
|
|
183
196
|
},
|
|
197
|
+
updatePushNotifications: async (UUIDs) => {
|
|
198
|
+
try {
|
|
199
|
+
await this.messagingSystem.call('NotificationServicesPushController:updateTriggerPushNotifications', UUIDs);
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
loglevel_1.default.error('Silently failed to update push notifications', e);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
184
205
|
subscribe: () => {
|
|
185
206
|
this.messagingSystem.subscribe('NotificationServicesPushController:onNewNotifications', (notification) => {
|
|
186
207
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -215,7 +236,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
215
236
|
_NotificationServicesController_accounts.set(this, {
|
|
216
237
|
// Flag to ensure we only setup once
|
|
217
238
|
isNotificationAccountsSetup: false,
|
|
218
|
-
getNotificationAccounts: () => {
|
|
239
|
+
getNotificationAccounts: async () => {
|
|
219
240
|
const { keyrings } = this.messagingSystem.call('KeyringController:getState');
|
|
220
241
|
const firstHDKeyring = keyrings.find((k) => k.type === keyring_controller_1.KeyringTypes.hd.toString());
|
|
221
242
|
const keyringAccounts = firstHDKeyring?.accounts ?? null;
|
|
@@ -226,9 +247,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
226
247
|
*
|
|
227
248
|
* @returns addresses removed, added, and latest list of addresses
|
|
228
249
|
*/
|
|
229
|
-
listAccounts: () => {
|
|
250
|
+
listAccounts: async () => {
|
|
230
251
|
// Get previous and current account sets
|
|
231
|
-
const nonChecksumAccounts = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").getNotificationAccounts();
|
|
252
|
+
const nonChecksumAccounts = await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").getNotificationAccounts();
|
|
232
253
|
if (!nonChecksumAccounts) {
|
|
233
254
|
return {
|
|
234
255
|
accountsAdded: [],
|
|
@@ -265,11 +286,13 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
265
286
|
},
|
|
266
287
|
/**
|
|
267
288
|
* Initializes the cache/previous list. This is handy so we have an accurate in-mem state of the previous list of accounts.
|
|
289
|
+
*
|
|
290
|
+
* @returns result from list accounts
|
|
268
291
|
*/
|
|
269
|
-
initialize: () => {
|
|
292
|
+
initialize: async () => {
|
|
270
293
|
if (__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked &&
|
|
271
294
|
!__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup) {
|
|
272
|
-
__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
295
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
273
296
|
__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup = true;
|
|
274
297
|
}
|
|
275
298
|
},
|
|
@@ -285,15 +308,15 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
285
308
|
!hasTotalAccountsChanged) {
|
|
286
309
|
return;
|
|
287
310
|
}
|
|
288
|
-
const { accountsAdded, accountsRemoved } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
311
|
+
const { accountsAdded, accountsRemoved } = await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
289
312
|
const promises = [];
|
|
290
313
|
if (accountsAdded.length > 0) {
|
|
291
|
-
promises.push(this.
|
|
314
|
+
promises.push(this.updateOnChainTriggersByAccount(accountsAdded));
|
|
292
315
|
}
|
|
293
316
|
if (accountsRemoved.length > 0) {
|
|
294
|
-
promises.push(this.
|
|
317
|
+
promises.push(this.deleteOnChainTriggersByAccount(accountsRemoved));
|
|
295
318
|
}
|
|
296
|
-
await Promise.
|
|
319
|
+
await Promise.all(promises);
|
|
297
320
|
}, (state) => {
|
|
298
321
|
return (state?.keyrings?.flatMap?.((keyring) => keyring.accounts)?.length ??
|
|
299
322
|
0);
|
|
@@ -307,9 +330,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
307
330
|
}
|
|
308
331
|
init() {
|
|
309
332
|
__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").setupLockedStateSubscriptions(async () => {
|
|
310
|
-
__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
|
|
333
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
|
|
311
334
|
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").initializePushNotifications();
|
|
312
335
|
});
|
|
336
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
313
337
|
__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
|
|
314
338
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
315
339
|
__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").initializePushNotifications();
|
|
@@ -320,18 +344,13 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
320
344
|
* Public method to expose enabling push notifications
|
|
321
345
|
*/
|
|
322
346
|
async enablePushNotifications() {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const addresses = addressesWithNotifications.map((a) => a.address);
|
|
328
|
-
if (addresses.length > 0) {
|
|
329
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(addresses);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
catch (e) {
|
|
333
|
-
loglevel_1.default.error('Failed to enable push notifications', e);
|
|
347
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_enableAuth).call(this);
|
|
348
|
+
const storage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
|
|
349
|
+
if (!storage) {
|
|
350
|
+
throw new Error('Unable to get triggers');
|
|
334
351
|
}
|
|
352
|
+
const uuids = Utils.getAllUUIDs(storage);
|
|
353
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(uuids);
|
|
335
354
|
}
|
|
336
355
|
/**
|
|
337
356
|
* Public method to expose disabling push notifications
|
|
@@ -343,13 +362,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
343
362
|
try {
|
|
344
363
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsCheckingAccountsPresence).call(this, true);
|
|
345
364
|
// Retrieve user storage
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
result[a.address] = a.enabled;
|
|
351
|
-
});
|
|
352
|
-
return result;
|
|
365
|
+
const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
|
|
366
|
+
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
|
|
367
|
+
const presence = Utils.checkAccountsPresence(userStorage, accounts);
|
|
368
|
+
return presence;
|
|
353
369
|
}
|
|
354
370
|
catch (error) {
|
|
355
371
|
loglevel_1.default.error('Failed to check accounts presence', error);
|
|
@@ -393,26 +409,40 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
393
409
|
async createOnChainTriggers(opts) {
|
|
394
410
|
try {
|
|
395
411
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
|
|
396
|
-
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m",
|
|
397
|
-
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
398
|
-
//
|
|
399
|
-
|
|
400
|
-
//
|
|
401
|
-
if
|
|
402
|
-
|
|
412
|
+
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getValidStorageKeyAndBearerToken).call(this);
|
|
413
|
+
const { accounts } = await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
414
|
+
// Attempt Get User Storage
|
|
415
|
+
// Will be null if entry does not exist, or a user is resetting their notifications
|
|
416
|
+
// Will be defined if entry exists
|
|
417
|
+
// Will throw if fails to get the user storage entry
|
|
418
|
+
let userStorage = opts?.resetNotifications
|
|
419
|
+
? null
|
|
420
|
+
: await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
|
|
421
|
+
// If userStorage does not exist, create a new one
|
|
422
|
+
// All the triggers created are set as: "disabled"
|
|
423
|
+
if (userStorage?.[constants_1.USER_STORAGE_VERSION_KEY] === undefined) {
|
|
424
|
+
userStorage = Utils.initializeUserStorage(accounts.map((account) => ({ address: account })), false);
|
|
425
|
+
// Write the userStorage
|
|
426
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
403
427
|
}
|
|
404
|
-
//
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
428
|
+
// Create the triggers
|
|
429
|
+
const triggers = Utils.traverseUserStorageTriggers(userStorage);
|
|
430
|
+
await OnChainNotifications.createOnChainTriggers(userStorage, storageKey, bearerToken, triggers);
|
|
431
|
+
// Create push notifications triggers in background
|
|
432
|
+
const allUUIDS = Utils.getAllUUIDs(userStorage);
|
|
433
|
+
// We do not want to wait for this request as it may take a while (e.g. for Firebase to setup)
|
|
434
|
+
__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(allUUIDS).catch(() => {
|
|
408
435
|
// Do Nothing
|
|
409
436
|
});
|
|
437
|
+
// Write the new userStorage (triggers are now "enabled")
|
|
438
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
410
439
|
// Update the state of the controller
|
|
411
440
|
this.update((state) => {
|
|
412
441
|
state.isNotificationServicesEnabled = true;
|
|
413
442
|
state.isFeatureAnnouncementsEnabled = true;
|
|
414
443
|
state.isMetamaskNotificationsFeatureSeen = true;
|
|
415
444
|
});
|
|
445
|
+
return userStorage;
|
|
416
446
|
}
|
|
417
447
|
catch (err) {
|
|
418
448
|
loglevel_1.default.error('Failed to create On Chain triggers', err);
|
|
@@ -425,6 +455,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
425
455
|
/**
|
|
426
456
|
* Enables all MetaMask notifications for the user.
|
|
427
457
|
* This is identical flow when initializing notifications for the first time.
|
|
458
|
+
* 1. Enable Profile Syncing
|
|
459
|
+
* 2. Get or Create Notification User Storage
|
|
460
|
+
* 3. Upsert Triggers
|
|
461
|
+
* 4. Update Push notifications
|
|
428
462
|
*
|
|
429
463
|
* @throws {Error} If there is an error during the process of enabling notifications.
|
|
430
464
|
*/
|
|
@@ -472,11 +506,12 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
472
506
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, false);
|
|
473
507
|
}
|
|
474
508
|
/**
|
|
475
|
-
* Deletes on-chain triggers associated with a specific account
|
|
509
|
+
* Deletes on-chain triggers associated with a specific account.
|
|
476
510
|
* This method performs several key operations:
|
|
477
|
-
* 1. Validates Auth
|
|
478
|
-
* 2.
|
|
479
|
-
*
|
|
511
|
+
* 1. Validates Auth & Storage
|
|
512
|
+
* 2. Finds and deletes all triggers associated with the account
|
|
513
|
+
* 3. Disables any related push notifications
|
|
514
|
+
* 4. Updates Storage to reflect new state.
|
|
480
515
|
*
|
|
481
516
|
* **Action** - When a user disables notifications for a given account in settings.
|
|
482
517
|
*
|
|
@@ -484,13 +519,29 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
484
519
|
* @returns A promise that resolves to void or an object containing a success message.
|
|
485
520
|
* @throws {Error} Throws an error if unauthenticated or from other operations.
|
|
486
521
|
*/
|
|
487
|
-
async
|
|
522
|
+
async deleteOnChainTriggersByAccount(accounts) {
|
|
488
523
|
try {
|
|
489
524
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
|
|
490
525
|
// Get and Validate BearerToken and User Storage Key
|
|
491
|
-
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m",
|
|
526
|
+
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getValidStorageKeyAndBearerToken).call(this);
|
|
527
|
+
// Get & Validate User Storage
|
|
528
|
+
const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
|
|
529
|
+
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
|
|
530
|
+
// Get the UUIDs to delete
|
|
531
|
+
const UUIDs = accounts
|
|
532
|
+
.map((a) => Utils.getUUIDsForAccount(userStorage, a.toLowerCase()))
|
|
533
|
+
.flat();
|
|
534
|
+
if (UUIDs.length === 0) {
|
|
535
|
+
return userStorage;
|
|
536
|
+
}
|
|
492
537
|
// Delete these UUIDs (Mutates User Storage)
|
|
493
|
-
await OnChainNotifications.
|
|
538
|
+
await OnChainNotifications.deleteOnChainTriggers(userStorage, storageKey, bearerToken, UUIDs);
|
|
539
|
+
// Update Push Notifications with new list of IDs
|
|
540
|
+
const remainingTriggerIds = Utils.getAllUUIDs(userStorage);
|
|
541
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").updatePushNotifications(remainingTriggerIds);
|
|
542
|
+
// Update User Storage
|
|
543
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
544
|
+
return userStorage;
|
|
494
545
|
}
|
|
495
546
|
catch (err) {
|
|
496
547
|
loglevel_1.default.error('Failed to delete OnChain triggers', err);
|
|
@@ -515,11 +566,45 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
515
566
|
* @returns A promise that resolves to the updated user storage.
|
|
516
567
|
* @throws {Error} Throws an error if unauthenticated or from other operations.
|
|
517
568
|
*/
|
|
518
|
-
async
|
|
569
|
+
async updateOnChainTriggersByAccount(accounts) {
|
|
519
570
|
try {
|
|
520
571
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
|
|
521
|
-
|
|
522
|
-
|
|
572
|
+
// Get and Validate BearerToken and User Storage Key
|
|
573
|
+
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getValidStorageKeyAndBearerToken).call(this);
|
|
574
|
+
// Get & Validate User Storage
|
|
575
|
+
const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
|
|
576
|
+
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
|
|
577
|
+
// Add any missing triggers
|
|
578
|
+
accounts.forEach((a) => Utils.upsertAddressTriggers(a, userStorage));
|
|
579
|
+
const newTriggers = Utils.traverseUserStorageTriggers(userStorage, {
|
|
580
|
+
mapTrigger: (t) => {
|
|
581
|
+
if (!t.enabled) {
|
|
582
|
+
return t;
|
|
583
|
+
}
|
|
584
|
+
return undefined;
|
|
585
|
+
},
|
|
586
|
+
});
|
|
587
|
+
// Create any missing triggers.
|
|
588
|
+
if (newTriggers.length > 0) {
|
|
589
|
+
// Write te updated userStorage (where triggers are disabled)
|
|
590
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
591
|
+
// Create the triggers
|
|
592
|
+
const triggers = Utils.traverseUserStorageTriggers(userStorage, {
|
|
593
|
+
mapTrigger: (t) => {
|
|
594
|
+
if (accounts.some((a) => a.toLowerCase() === t.address.toLowerCase())) {
|
|
595
|
+
return t;
|
|
596
|
+
}
|
|
597
|
+
return undefined;
|
|
598
|
+
},
|
|
599
|
+
});
|
|
600
|
+
await OnChainNotifications.createOnChainTriggers(userStorage, storageKey, bearerToken, triggers);
|
|
601
|
+
}
|
|
602
|
+
// Update Push Notifications Triggers
|
|
603
|
+
const UUIDs = Utils.getAllUUIDs(userStorage);
|
|
604
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").updatePushNotifications(UUIDs);
|
|
605
|
+
// Update the userStorage (where triggers are enabled)
|
|
606
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
607
|
+
return userStorage;
|
|
523
608
|
}
|
|
524
609
|
catch (err) {
|
|
525
610
|
loglevel_1.default.error('Failed to update OnChain triggers', err);
|
|
@@ -546,30 +631,37 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
546
631
|
// Not used by Snaps
|
|
547
632
|
const isGlobalNotifsEnabled = this.state.isNotificationServicesEnabled;
|
|
548
633
|
// Raw Feature Notifications
|
|
549
|
-
const
|
|
634
|
+
const rawFeatureAnnouncementNotifications = isGlobalNotifsEnabled && this.state.isFeatureAnnouncementsEnabled
|
|
550
635
|
? await FeatureNotifications.getFeatureAnnouncementNotifications(__classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f"), previewToken).catch(() => [])
|
|
551
636
|
: [];
|
|
552
637
|
// Raw On Chain Notifications
|
|
553
638
|
const rawOnChainNotifications = [];
|
|
554
639
|
if (isGlobalNotifsEnabled) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
640
|
+
const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f")
|
|
641
|
+
.getNotificationStorage()
|
|
642
|
+
.then((s) => s && JSON.parse(s))
|
|
643
|
+
.catch(() => null);
|
|
644
|
+
const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken().catch(() => null);
|
|
645
|
+
if (userStorage && bearerToken) {
|
|
646
|
+
const notifications = await OnChainNotifications.getOnChainNotifications(userStorage, bearerToken).catch(() => []);
|
|
559
647
|
rawOnChainNotifications.push(...notifications);
|
|
560
648
|
}
|
|
561
|
-
catch {
|
|
562
|
-
// Do nothing
|
|
563
|
-
}
|
|
564
649
|
}
|
|
565
650
|
// Snap Notifications (original)
|
|
566
651
|
// We do not want to remove them
|
|
567
652
|
const snapNotifications = this.state.metamaskNotificationsList.filter((notification) => notification.type === notification_schema_1.TRIGGER_TYPES.SNAP);
|
|
653
|
+
// Process Notifications
|
|
568
654
|
const readIds = this.state.metamaskNotificationsReadList;
|
|
655
|
+
const isNotUndefined = (t) => Boolean(t);
|
|
656
|
+
const processAndFilter = (ns) => ns
|
|
657
|
+
.map((n) => (0, process_notifications_1.safeProcessNotification)(n, readIds))
|
|
658
|
+
.filter(isNotUndefined);
|
|
659
|
+
const featureAnnouncementNotifications = processAndFilter(rawFeatureAnnouncementNotifications);
|
|
660
|
+
const onChainNotifications = processAndFilter(rawOnChainNotifications);
|
|
569
661
|
// Combine Notifications
|
|
570
662
|
const metamaskNotifications = [
|
|
571
|
-
...
|
|
572
|
-
...
|
|
663
|
+
...featureAnnouncementNotifications,
|
|
664
|
+
...onChainNotifications,
|
|
573
665
|
...snapNotifications,
|
|
574
666
|
];
|
|
575
667
|
// Sort Notifications
|
|
@@ -737,7 +829,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
737
829
|
}
|
|
738
830
|
}
|
|
739
831
|
}
|
|
740
|
-
_NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(), _NotificationServicesController_pushNotifications = new WeakMap(), _NotificationServicesController_accounts = new WeakMap(), _NotificationServicesController_featureAnnouncementEnv = new WeakMap(), _NotificationServicesController_instances = new WeakSet(), _NotificationServicesController_registerMessageHandlers = function _NotificationServicesController_registerMessageHandlers() {
|
|
832
|
+
_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() {
|
|
741
833
|
this.messagingSystem.registerActionHandler(`${controllerName}:updateMetamaskNotificationsList`, this.updateMetamaskNotificationsList.bind(this));
|
|
742
834
|
this.messagingSystem.registerActionHandler(`${controllerName}:disableNotificationServices`, this.disableNotificationServices.bind(this));
|
|
743
835
|
this.messagingSystem.registerActionHandler(`${controllerName}:getNotificationsByType`, this.getNotificationsByType.bind(this));
|
|
@@ -761,13 +853,42 @@ _NotificationServicesController_keyringController = new WeakMap(), _Notification
|
|
|
761
853
|
if (!isSignedIn) {
|
|
762
854
|
await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").signIn();
|
|
763
855
|
}
|
|
764
|
-
},
|
|
856
|
+
}, _NotificationServicesController_getValidStorageKeyAndBearerToken = async function _NotificationServicesController_getValidStorageKeyAndBearerToken() {
|
|
765
857
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertAuthEnabled).call(this);
|
|
766
858
|
const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken();
|
|
767
|
-
|
|
768
|
-
|
|
859
|
+
const storageKey = await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").getStorageKey();
|
|
860
|
+
if (!bearerToken || !storageKey) {
|
|
861
|
+
throw new Error('Missing BearerToken or storage key');
|
|
862
|
+
}
|
|
863
|
+
return { bearerToken, storageKey };
|
|
864
|
+
}, _NotificationServicesController_assertUserStorage = function _NotificationServicesController_assertUserStorage(storage) {
|
|
865
|
+
if (!storage) {
|
|
866
|
+
throw new Error('User Storage does not exist');
|
|
867
|
+
}
|
|
868
|
+
}, _NotificationServicesController_getUserStorage =
|
|
869
|
+
/**
|
|
870
|
+
* Retrieves and parses the user storage from the storage key.
|
|
871
|
+
*
|
|
872
|
+
* This method attempts to retrieve the user storage using the specified storage key,
|
|
873
|
+
* then parses the JSON string to an object. If the storage is not found or cannot be parsed,
|
|
874
|
+
* it throws an error.
|
|
875
|
+
*
|
|
876
|
+
* @returns The parsed user storage object or null
|
|
877
|
+
*/
|
|
878
|
+
async function _NotificationServicesController_getUserStorage() {
|
|
879
|
+
const userStorageString = await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").getNotificationStorage();
|
|
880
|
+
if (!userStorageString) {
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
try {
|
|
884
|
+
const userStorage = JSON.parse(userStorageString);
|
|
885
|
+
Utils.cleanUserStorage(userStorage);
|
|
886
|
+
return userStorage;
|
|
887
|
+
}
|
|
888
|
+
catch {
|
|
889
|
+
loglevel_1.default.error('Unable to parse User Storage');
|
|
890
|
+
return null;
|
|
769
891
|
}
|
|
770
|
-
return { bearerToken };
|
|
771
892
|
}, _NotificationServicesController_setIsUpdatingMetamaskNotifications = function _NotificationServicesController_setIsUpdatingMetamaskNotifications(isUpdatingMetamaskNotifications) {
|
|
772
893
|
this.update((state) => {
|
|
773
894
|
state.isUpdatingMetamaskNotifications = isUpdatingMetamaskNotifications;
|