@metamask-previews/notification-services-controller 10.0.0-preview-e11fb169 → 10.0.0-preview-7dcef379
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 +16 -0
- package/dist/NotificationServicesController/NotificationServicesController.cjs +76 -188
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +10 -16
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +10 -16
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +77 -189
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/constants/index.cjs +0 -1
- package/dist/NotificationServicesController/constants/index.cjs.map +1 -1
- package/dist/NotificationServicesController/constants/index.d.cts +0 -1
- package/dist/NotificationServicesController/constants/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/constants/index.d.mts +0 -1
- package/dist/NotificationServicesController/constants/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/constants/index.mjs +0 -1
- package/dist/NotificationServicesController/constants/index.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/index.cjs +0 -2
- package/dist/NotificationServicesController/mocks/index.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/index.d.cts +0 -2
- package/dist/NotificationServicesController/mocks/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/index.d.mts +0 -2
- package/dist/NotificationServicesController/mocks/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/index.mjs +0 -2
- package/dist/NotificationServicesController/mocks/index.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.cjs +9 -9
- package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts +7 -4
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts +7 -4
- 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 +4 -1
- package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.cts +623 -0
- package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.mts +623 -0
- package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.mjs +2 -0
- package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/services/notification-config-cache.cjs +72 -0
- package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -0
- package/dist/NotificationServicesController/services/notification-config-cache.d.cts +19 -0
- package/dist/NotificationServicesController/services/notification-config-cache.d.cts.map +1 -0
- package/dist/NotificationServicesController/services/notification-config-cache.d.mts +19 -0
- package/dist/NotificationServicesController/services/notification-config-cache.d.mts.map +1 -0
- package/dist/NotificationServicesController/services/notification-config-cache.mjs +68 -0
- package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -0
- package/dist/NotificationServicesController/services/onchain-notifications.cjs +67 -140
- package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.cts +25 -31
- package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.mts +25 -31
- package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs +65 -137
- 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 +0 -1
- package/dist/NotificationServicesController/types/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/index.d.mts +0 -1
- package/dist/NotificationServicesController/types/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/index.mjs.map +1 -1
- package/dist/NotificationServicesController/utils/utils.cjs +1 -350
- package/dist/NotificationServicesController/utils/utils.cjs.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.cts +0 -141
- package/dist/NotificationServicesController/utils/utils.d.cts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.mts +0 -141
- package/dist/NotificationServicesController/utils/utils.d.mts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.mjs +0 -337
- package/dist/NotificationServicesController/utils/utils.mjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +22 -15
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +6 -5
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +6 -5
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +23 -16
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.cjs +1 -16
- package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +0 -7
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +0 -7
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.mjs +0 -14
- 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 +18 -41
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts +19 -33
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts +19 -33
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs +17 -39
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/NotificationServicesController/constants/constants.cjs +0 -7
- package/dist/NotificationServicesController/constants/constants.cjs.map +0 -1
- package/dist/NotificationServicesController/constants/constants.d.cts +0 -3
- package/dist/NotificationServicesController/constants/constants.d.cts.map +0 -1
- package/dist/NotificationServicesController/constants/constants.d.mts +0 -3
- package/dist/NotificationServicesController/constants/constants.d.mts.map +0 -1
- package/dist/NotificationServicesController/constants/constants.mjs +0 -4
- package/dist/NotificationServicesController/constants/constants.mjs.map +0 -1
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.cjs +0 -22
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.cjs.map +0 -1
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.cts +0 -9
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.cts.map +0 -1
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.mts +0 -9
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.mts.map +0 -1
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.mjs +0 -18
- package/dist/NotificationServicesController/mocks/mock-notification-trigger.mjs.map +0 -1
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.cjs +0 -82
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.cjs.map +0 -1
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.cts +0 -35
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.cts.map +0 -1
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.mts +0 -35
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.mts.map +0 -1
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.mjs +0 -76
- package/dist/NotificationServicesController/mocks/mock-notification-user-storage.mjs.map +0 -1
- package/dist/NotificationServicesController/types/user-storage/index.cjs +0 -3
- package/dist/NotificationServicesController/types/user-storage/index.cjs.map +0 -1
- package/dist/NotificationServicesController/types/user-storage/index.d.cts +0 -2
- package/dist/NotificationServicesController/types/user-storage/index.d.cts.map +0 -1
- package/dist/NotificationServicesController/types/user-storage/index.d.mts +0 -2
- package/dist/NotificationServicesController/types/user-storage/index.d.mts.map +0 -1
- package/dist/NotificationServicesController/types/user-storage/index.mjs +0 -2
- package/dist/NotificationServicesController/types/user-storage/index.mjs.map +0 -1
- package/dist/NotificationServicesController/types/user-storage/user-storage.cjs +0 -3
- package/dist/NotificationServicesController/types/user-storage/user-storage.cjs.map +0 -1
- package/dist/NotificationServicesController/types/user-storage/user-storage.d.cts +0 -26
- package/dist/NotificationServicesController/types/user-storage/user-storage.d.cts.map +0 -1
- package/dist/NotificationServicesController/types/user-storage/user-storage.d.mts +0 -26
- package/dist/NotificationServicesController/types/user-storage/user-storage.d.mts.map +0 -1
- package/dist/NotificationServicesController/types/user-storage/user-storage.mjs +0 -2
- package/dist/NotificationServicesController/types/user-storage/user-storage.mjs.map +0 -1
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _NotificationServicesController_instances, _NotificationServicesController_keyringController, _NotificationServicesController_auth,
|
|
12
|
+
var _NotificationServicesController_instances, _NotificationServicesController_keyringController, _NotificationServicesController_auth, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth, _NotificationServicesController_getBearerToken, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
|
|
13
13
|
function $importDefault(module) {
|
|
14
14
|
if (module?.__esModule) {
|
|
15
15
|
return module.default;
|
|
@@ -22,12 +22,10 @@ import { KeyringTypes } from "@metamask/keyring-controller";
|
|
|
22
22
|
import { assert } from "@metamask/utils";
|
|
23
23
|
import $log from "loglevel";
|
|
24
24
|
const log = $importDefault($log);
|
|
25
|
-
import { USER_STORAGE_VERSION_KEY } from "./constants/constants.mjs";
|
|
26
25
|
import { TRIGGER_TYPES } from "./constants/notification-schema.mjs";
|
|
27
|
-
import { safeProcessNotification } from "./processors/process-notifications.mjs";
|
|
26
|
+
import { processAndFilterNotifications, safeProcessNotification } from "./processors/process-notifications.mjs";
|
|
28
27
|
import * as FeatureNotifications from "./services/feature-announcements.mjs";
|
|
29
28
|
import * as OnChainNotifications from "./services/onchain-notifications.mjs";
|
|
30
|
-
import * as Utils from "./utils/utils.mjs";
|
|
31
29
|
// Unique name for the controller
|
|
32
30
|
const controllerName = 'NotificationServicesController';
|
|
33
31
|
const metadata = {
|
|
@@ -137,17 +135,6 @@ class NotificationServicesController extends BaseController {
|
|
|
137
135
|
return await this.messagingSystem.call('AuthenticationController:performSignIn');
|
|
138
136
|
},
|
|
139
137
|
});
|
|
140
|
-
_NotificationServicesController_storage.set(this, {
|
|
141
|
-
getStorageKey: () => {
|
|
142
|
-
return this.messagingSystem.call('UserStorageController:getStorageKey');
|
|
143
|
-
},
|
|
144
|
-
getNotificationStorage: async () => {
|
|
145
|
-
return await this.messagingSystem.call('UserStorageController:performGetStorage', 'notifications.notification_settings');
|
|
146
|
-
},
|
|
147
|
-
setNotificationStorage: async (state) => {
|
|
148
|
-
return await this.messagingSystem.call('UserStorageController:performSetStorage', 'notifications.notification_settings', state);
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
138
|
_NotificationServicesController_pushNotifications.set(this, {
|
|
152
139
|
// Flag to check is notifications have been setup when the browser/extension is initialized.
|
|
153
140
|
// We want to re-initialize push notifications when the browser/extension is refreshed
|
|
@@ -156,9 +143,9 @@ class NotificationServicesController extends BaseController {
|
|
|
156
143
|
subscribeToPushNotifications: async () => {
|
|
157
144
|
await this.messagingSystem.call('NotificationServicesPushController:subscribeToPushNotifications');
|
|
158
145
|
},
|
|
159
|
-
enablePushNotifications: async (
|
|
146
|
+
enablePushNotifications: async (addresses) => {
|
|
160
147
|
try {
|
|
161
|
-
await this.messagingSystem.call('NotificationServicesPushController:enablePushNotifications',
|
|
148
|
+
await this.messagingSystem.call('NotificationServicesPushController:enablePushNotifications', addresses);
|
|
162
149
|
}
|
|
163
150
|
catch (e) {
|
|
164
151
|
log.error('Silently failed to enable push notifications', e);
|
|
@@ -172,14 +159,6 @@ class NotificationServicesController extends BaseController {
|
|
|
172
159
|
log.error('Silently failed to disable push notifications', e);
|
|
173
160
|
}
|
|
174
161
|
},
|
|
175
|
-
updatePushNotifications: async (UUIDs) => {
|
|
176
|
-
try {
|
|
177
|
-
await this.messagingSystem.call('NotificationServicesPushController:updateTriggerPushNotifications', UUIDs);
|
|
178
|
-
}
|
|
179
|
-
catch (e) {
|
|
180
|
-
log.error('Silently failed to update push notifications', e);
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
162
|
subscribe: () => {
|
|
184
163
|
this.messagingSystem.subscribe('NotificationServicesPushController:onNewNotifications', (notification) => {
|
|
185
164
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -214,7 +193,7 @@ class NotificationServicesController extends BaseController {
|
|
|
214
193
|
_NotificationServicesController_accounts.set(this, {
|
|
215
194
|
// Flag to ensure we only setup once
|
|
216
195
|
isNotificationAccountsSetup: false,
|
|
217
|
-
getNotificationAccounts:
|
|
196
|
+
getNotificationAccounts: () => {
|
|
218
197
|
const { keyrings } = this.messagingSystem.call('KeyringController:getState');
|
|
219
198
|
const firstHDKeyring = keyrings.find((k) => k.type === KeyringTypes.hd.toString());
|
|
220
199
|
const keyringAccounts = firstHDKeyring?.accounts ?? null;
|
|
@@ -225,9 +204,9 @@ class NotificationServicesController extends BaseController {
|
|
|
225
204
|
*
|
|
226
205
|
* @returns addresses removed, added, and latest list of addresses
|
|
227
206
|
*/
|
|
228
|
-
listAccounts:
|
|
207
|
+
listAccounts: () => {
|
|
229
208
|
// Get previous and current account sets
|
|
230
|
-
const nonChecksumAccounts =
|
|
209
|
+
const nonChecksumAccounts = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").getNotificationAccounts();
|
|
231
210
|
if (!nonChecksumAccounts) {
|
|
232
211
|
return {
|
|
233
212
|
accountsAdded: [],
|
|
@@ -264,13 +243,11 @@ class NotificationServicesController extends BaseController {
|
|
|
264
243
|
},
|
|
265
244
|
/**
|
|
266
245
|
* Initializes the cache/previous list. This is handy so we have an accurate in-mem state of the previous list of accounts.
|
|
267
|
-
*
|
|
268
|
-
* @returns result from list accounts
|
|
269
246
|
*/
|
|
270
|
-
initialize:
|
|
247
|
+
initialize: () => {
|
|
271
248
|
if (__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked &&
|
|
272
249
|
!__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup) {
|
|
273
|
-
|
|
250
|
+
__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
274
251
|
__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup = true;
|
|
275
252
|
}
|
|
276
253
|
},
|
|
@@ -286,15 +263,15 @@ class NotificationServicesController extends BaseController {
|
|
|
286
263
|
!hasTotalAccountsChanged) {
|
|
287
264
|
return;
|
|
288
265
|
}
|
|
289
|
-
const { accountsAdded, accountsRemoved } =
|
|
266
|
+
const { accountsAdded, accountsRemoved } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
290
267
|
const promises = [];
|
|
291
268
|
if (accountsAdded.length > 0) {
|
|
292
|
-
promises.push(this.
|
|
269
|
+
promises.push(this.enableAccounts(accountsAdded));
|
|
293
270
|
}
|
|
294
271
|
if (accountsRemoved.length > 0) {
|
|
295
|
-
promises.push(this.
|
|
272
|
+
promises.push(this.disableAccounts(accountsRemoved));
|
|
296
273
|
}
|
|
297
|
-
await Promise.
|
|
274
|
+
await Promise.allSettled(promises);
|
|
298
275
|
}, (state) => {
|
|
299
276
|
return (state?.keyrings?.flatMap?.((keyring) => keyring.accounts)?.length ??
|
|
300
277
|
0);
|
|
@@ -308,10 +285,9 @@ class NotificationServicesController extends BaseController {
|
|
|
308
285
|
}
|
|
309
286
|
init() {
|
|
310
287
|
__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").setupLockedStateSubscriptions(async () => {
|
|
311
|
-
|
|
288
|
+
__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
|
|
312
289
|
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").initializePushNotifications();
|
|
313
290
|
});
|
|
314
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
315
291
|
__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
|
|
316
292
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
317
293
|
__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").initializePushNotifications();
|
|
@@ -322,13 +298,20 @@ class NotificationServicesController extends BaseController {
|
|
|
322
298
|
* Public method to expose enabling push notifications
|
|
323
299
|
*/
|
|
324
300
|
async enablePushNotifications() {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
301
|
+
try {
|
|
302
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
303
|
+
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
304
|
+
const addressesWithNotifications = await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts);
|
|
305
|
+
const addresses = addressesWithNotifications
|
|
306
|
+
.filter((a) => Boolean(a.enabled))
|
|
307
|
+
.map((a) => a.address);
|
|
308
|
+
if (addresses.length > 0) {
|
|
309
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(addresses);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (e) {
|
|
313
|
+
log.error('Failed to enable push notifications', e);
|
|
329
314
|
}
|
|
330
|
-
const uuids = Utils.getAllUUIDs(storage);
|
|
331
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(uuids);
|
|
332
315
|
}
|
|
333
316
|
/**
|
|
334
317
|
* Public method to expose disabling push notifications
|
|
@@ -340,10 +323,13 @@ class NotificationServicesController extends BaseController {
|
|
|
340
323
|
try {
|
|
341
324
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsCheckingAccountsPresence).call(this, true);
|
|
342
325
|
// Retrieve user storage
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
|
|
326
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
327
|
+
const addressesWithNotifications = await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts);
|
|
328
|
+
const result = {};
|
|
329
|
+
addressesWithNotifications.forEach((a) => {
|
|
330
|
+
result[a.address] = a.enabled;
|
|
331
|
+
});
|
|
332
|
+
return result;
|
|
347
333
|
}
|
|
348
334
|
catch (error) {
|
|
349
335
|
log.error('Failed to check accounts presence', error);
|
|
@@ -387,40 +373,32 @@ class NotificationServicesController extends BaseController {
|
|
|
387
373
|
async createOnChainTriggers(opts) {
|
|
388
374
|
try {
|
|
389
375
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
|
|
390
|
-
const { bearerToken
|
|
391
|
-
const { accounts } =
|
|
392
|
-
//
|
|
393
|
-
|
|
394
|
-
//
|
|
395
|
-
//
|
|
396
|
-
let
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
//
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
// Write the userStorage
|
|
404
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
376
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
377
|
+
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
378
|
+
// 1. See if has enabled notifications before
|
|
379
|
+
const addressesWithNotifications = await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts);
|
|
380
|
+
// Notifications API can return array with addresses set to false
|
|
381
|
+
// So assert that at least one address is enabled
|
|
382
|
+
let accountsWithNotifications = addressesWithNotifications
|
|
383
|
+
.filter((a) => Boolean(a.enabled))
|
|
384
|
+
.map((a) => a.address);
|
|
385
|
+
// 2. Enable Notifications (if no accounts subscribed or we are resetting)
|
|
386
|
+
if (accountsWithNotifications.length === 0 || opts?.resetNotifications) {
|
|
387
|
+
await OnChainNotifications.updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })));
|
|
388
|
+
accountsWithNotifications = accounts;
|
|
405
389
|
}
|
|
406
|
-
//
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const allUUIDS = Utils.getAllUUIDs(userStorage);
|
|
411
|
-
// We do not want to wait for this request as it may take a while (e.g. for Firebase to setup)
|
|
412
|
-
__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(allUUIDS).catch(() => {
|
|
390
|
+
// 3. Lazily enable push notifications (FCM may take some time, so keeps UI unblocked)
|
|
391
|
+
__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f")
|
|
392
|
+
.enablePushNotifications(accountsWithNotifications)
|
|
393
|
+
.catch(() => {
|
|
413
394
|
// Do Nothing
|
|
414
395
|
});
|
|
415
|
-
// Write the new userStorage (triggers are now "enabled")
|
|
416
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
417
396
|
// Update the state of the controller
|
|
418
397
|
this.update((state) => {
|
|
419
398
|
state.isNotificationServicesEnabled = true;
|
|
420
399
|
state.isFeatureAnnouncementsEnabled = true;
|
|
421
400
|
state.isMetamaskNotificationsFeatureSeen = true;
|
|
422
401
|
});
|
|
423
|
-
return userStorage;
|
|
424
402
|
}
|
|
425
403
|
catch (err) {
|
|
426
404
|
log.error('Failed to create On Chain triggers', err);
|
|
@@ -433,10 +411,6 @@ class NotificationServicesController extends BaseController {
|
|
|
433
411
|
/**
|
|
434
412
|
* Enables all MetaMask notifications for the user.
|
|
435
413
|
* This is identical flow when initializing notifications for the first time.
|
|
436
|
-
* 1. Enable Profile Syncing
|
|
437
|
-
* 2. Get or Create Notification User Storage
|
|
438
|
-
* 3. Upsert Triggers
|
|
439
|
-
* 4. Update Push notifications
|
|
440
414
|
*
|
|
441
415
|
* @throws {Error} If there is an error during the process of enabling notifications.
|
|
442
416
|
*/
|
|
@@ -484,12 +458,11 @@ class NotificationServicesController extends BaseController {
|
|
|
484
458
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, false);
|
|
485
459
|
}
|
|
486
460
|
/**
|
|
487
|
-
* Deletes on-chain triggers associated with a specific account.
|
|
461
|
+
* Deletes on-chain triggers associated with a specific account/s.
|
|
488
462
|
* This method performs several key operations:
|
|
489
|
-
* 1. Validates Auth
|
|
490
|
-
* 2.
|
|
491
|
-
*
|
|
492
|
-
* 4. Updates Storage to reflect new state.
|
|
463
|
+
* 1. Validates Auth
|
|
464
|
+
* 2. Deletes accounts
|
|
465
|
+
* (note) We do not need to look through push notifications as we've deleted triggers
|
|
493
466
|
*
|
|
494
467
|
* **Action** - When a user disables notifications for a given account in settings.
|
|
495
468
|
*
|
|
@@ -497,29 +470,13 @@ class NotificationServicesController extends BaseController {
|
|
|
497
470
|
* @returns A promise that resolves to void or an object containing a success message.
|
|
498
471
|
* @throws {Error} Throws an error if unauthenticated or from other operations.
|
|
499
472
|
*/
|
|
500
|
-
async
|
|
473
|
+
async disableAccounts(accounts) {
|
|
501
474
|
try {
|
|
502
475
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
|
|
503
476
|
// Get and Validate BearerToken and User Storage Key
|
|
504
|
-
const { bearerToken
|
|
505
|
-
// Get & Validate User Storage
|
|
506
|
-
const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
|
|
507
|
-
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
|
|
508
|
-
// Get the UUIDs to delete
|
|
509
|
-
const UUIDs = accounts
|
|
510
|
-
.map((a) => Utils.getUUIDsForAccount(userStorage, a.toLowerCase()))
|
|
511
|
-
.flat();
|
|
512
|
-
if (UUIDs.length === 0) {
|
|
513
|
-
return userStorage;
|
|
514
|
-
}
|
|
477
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
515
478
|
// Delete these UUIDs (Mutates User Storage)
|
|
516
|
-
await OnChainNotifications.
|
|
517
|
-
// Update Push Notifications with new list of IDs
|
|
518
|
-
const remainingTriggerIds = Utils.getAllUUIDs(userStorage);
|
|
519
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").updatePushNotifications(remainingTriggerIds);
|
|
520
|
-
// Update User Storage
|
|
521
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
522
|
-
return userStorage;
|
|
479
|
+
await OnChainNotifications.updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: false })));
|
|
523
480
|
}
|
|
524
481
|
catch (err) {
|
|
525
482
|
log.error('Failed to delete OnChain triggers', err);
|
|
@@ -544,45 +501,11 @@ class NotificationServicesController extends BaseController {
|
|
|
544
501
|
* @returns A promise that resolves to the updated user storage.
|
|
545
502
|
* @throws {Error} Throws an error if unauthenticated or from other operations.
|
|
546
503
|
*/
|
|
547
|
-
async
|
|
504
|
+
async enableAccounts(accounts) {
|
|
548
505
|
try {
|
|
549
506
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
// Get & Validate User Storage
|
|
553
|
-
const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
|
|
554
|
-
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
|
|
555
|
-
// Add any missing triggers
|
|
556
|
-
accounts.forEach((a) => Utils.upsertAddressTriggers(a, userStorage));
|
|
557
|
-
const newTriggers = Utils.traverseUserStorageTriggers(userStorage, {
|
|
558
|
-
mapTrigger: (t) => {
|
|
559
|
-
if (!t.enabled) {
|
|
560
|
-
return t;
|
|
561
|
-
}
|
|
562
|
-
return undefined;
|
|
563
|
-
},
|
|
564
|
-
});
|
|
565
|
-
// Create any missing triggers.
|
|
566
|
-
if (newTriggers.length > 0) {
|
|
567
|
-
// Write te updated userStorage (where triggers are disabled)
|
|
568
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
569
|
-
// Create the triggers
|
|
570
|
-
const triggers = Utils.traverseUserStorageTriggers(userStorage, {
|
|
571
|
-
mapTrigger: (t) => {
|
|
572
|
-
if (accounts.some((a) => a.toLowerCase() === t.address.toLowerCase())) {
|
|
573
|
-
return t;
|
|
574
|
-
}
|
|
575
|
-
return undefined;
|
|
576
|
-
},
|
|
577
|
-
});
|
|
578
|
-
await OnChainNotifications.createOnChainTriggers(userStorage, storageKey, bearerToken, triggers);
|
|
579
|
-
}
|
|
580
|
-
// Update Push Notifications Triggers
|
|
581
|
-
const UUIDs = Utils.getAllUUIDs(userStorage);
|
|
582
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").updatePushNotifications(UUIDs);
|
|
583
|
-
// Update the userStorage (where triggers are enabled)
|
|
584
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
|
|
585
|
-
return userStorage;
|
|
507
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
508
|
+
await OnChainNotifications.updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })));
|
|
586
509
|
}
|
|
587
510
|
catch (err) {
|
|
588
511
|
log.error('Failed to update OnChain triggers', err);
|
|
@@ -609,37 +532,31 @@ class NotificationServicesController extends BaseController {
|
|
|
609
532
|
// Not used by Snaps
|
|
610
533
|
const isGlobalNotifsEnabled = this.state.isNotificationServicesEnabled;
|
|
611
534
|
// Raw Feature Notifications
|
|
612
|
-
const
|
|
535
|
+
const rawAnnouncements = isGlobalNotifsEnabled && this.state.isFeatureAnnouncementsEnabled
|
|
613
536
|
? await FeatureNotifications.getFeatureAnnouncementNotifications(__classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f"), previewToken).catch(() => [])
|
|
614
537
|
: [];
|
|
615
538
|
// Raw On Chain Notifications
|
|
616
539
|
const rawOnChainNotifications = [];
|
|
617
540
|
if (isGlobalNotifsEnabled) {
|
|
618
|
-
|
|
619
|
-
.
|
|
620
|
-
|
|
621
|
-
.
|
|
622
|
-
|
|
623
|
-
if (userStorage && bearerToken) {
|
|
624
|
-
const notifications = await OnChainNotifications.getOnChainNotifications(userStorage, bearerToken).catch(() => []);
|
|
541
|
+
try {
|
|
542
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
543
|
+
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
544
|
+
const addressesWithNotifications = (await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts)).map((a) => a.address);
|
|
545
|
+
const notifications = await OnChainNotifications.getOnChainNotifications(bearerToken, addressesWithNotifications).catch(() => []);
|
|
625
546
|
rawOnChainNotifications.push(...notifications);
|
|
626
547
|
}
|
|
548
|
+
catch {
|
|
549
|
+
// Do nothing
|
|
550
|
+
}
|
|
627
551
|
}
|
|
628
552
|
// Snap Notifications (original)
|
|
629
553
|
// We do not want to remove them
|
|
630
554
|
const snapNotifications = this.state.metamaskNotificationsList.filter((notification) => notification.type === TRIGGER_TYPES.SNAP);
|
|
631
|
-
// Process Notifications
|
|
632
555
|
const readIds = this.state.metamaskNotificationsReadList;
|
|
633
|
-
const isNotUndefined = (t) => Boolean(t);
|
|
634
|
-
const processAndFilter = (ns) => ns
|
|
635
|
-
.map((n) => safeProcessNotification(n, readIds))
|
|
636
|
-
.filter(isNotUndefined);
|
|
637
|
-
const featureAnnouncementNotifications = processAndFilter(rawFeatureAnnouncementNotifications);
|
|
638
|
-
const onChainNotifications = processAndFilter(rawOnChainNotifications);
|
|
639
556
|
// Combine Notifications
|
|
640
557
|
const metamaskNotifications = [
|
|
641
|
-
...
|
|
642
|
-
...
|
|
558
|
+
...processAndFilterNotifications(rawAnnouncements, readIds),
|
|
559
|
+
...processAndFilterNotifications(rawOnChainNotifications, readIds),
|
|
643
560
|
...snapNotifications,
|
|
644
561
|
];
|
|
645
562
|
// Sort Notifications
|
|
@@ -807,7 +724,7 @@ class NotificationServicesController extends BaseController {
|
|
|
807
724
|
}
|
|
808
725
|
}
|
|
809
726
|
}
|
|
810
|
-
_NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(),
|
|
727
|
+
_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() {
|
|
811
728
|
this.messagingSystem.registerActionHandler(`${controllerName}:updateMetamaskNotificationsList`, this.updateMetamaskNotificationsList.bind(this));
|
|
812
729
|
this.messagingSystem.registerActionHandler(`${controllerName}:disableNotificationServices`, this.disableNotificationServices.bind(this));
|
|
813
730
|
this.messagingSystem.registerActionHandler(`${controllerName}:getNotificationsByType`, this.getNotificationsByType.bind(this));
|
|
@@ -831,42 +748,13 @@ _NotificationServicesController_keyringController = new WeakMap(), _Notification
|
|
|
831
748
|
if (!isSignedIn) {
|
|
832
749
|
await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").signIn();
|
|
833
750
|
}
|
|
834
|
-
},
|
|
751
|
+
}, _NotificationServicesController_getBearerToken = async function _NotificationServicesController_getBearerToken() {
|
|
835
752
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertAuthEnabled).call(this);
|
|
836
753
|
const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken();
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
throw new Error('Missing BearerToken or storage key');
|
|
840
|
-
}
|
|
841
|
-
return { bearerToken, storageKey };
|
|
842
|
-
}, _NotificationServicesController_assertUserStorage = function _NotificationServicesController_assertUserStorage(storage) {
|
|
843
|
-
if (!storage) {
|
|
844
|
-
throw new Error('User Storage does not exist');
|
|
845
|
-
}
|
|
846
|
-
}, _NotificationServicesController_getUserStorage =
|
|
847
|
-
/**
|
|
848
|
-
* Retrieves and parses the user storage from the storage key.
|
|
849
|
-
*
|
|
850
|
-
* This method attempts to retrieve the user storage using the specified storage key,
|
|
851
|
-
* then parses the JSON string to an object. If the storage is not found or cannot be parsed,
|
|
852
|
-
* it throws an error.
|
|
853
|
-
*
|
|
854
|
-
* @returns The parsed user storage object or null
|
|
855
|
-
*/
|
|
856
|
-
async function _NotificationServicesController_getUserStorage() {
|
|
857
|
-
const userStorageString = await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").getNotificationStorage();
|
|
858
|
-
if (!userStorageString) {
|
|
859
|
-
return null;
|
|
860
|
-
}
|
|
861
|
-
try {
|
|
862
|
-
const userStorage = JSON.parse(userStorageString);
|
|
863
|
-
Utils.cleanUserStorage(userStorage);
|
|
864
|
-
return userStorage;
|
|
865
|
-
}
|
|
866
|
-
catch {
|
|
867
|
-
log.error('Unable to parse User Storage');
|
|
868
|
-
return null;
|
|
754
|
+
if (!bearerToken) {
|
|
755
|
+
throw new Error('Missing BearerToken');
|
|
869
756
|
}
|
|
757
|
+
return { bearerToken };
|
|
870
758
|
}, _NotificationServicesController_setIsUpdatingMetamaskNotifications = function _NotificationServicesController_setIsUpdatingMetamaskNotifications(isUpdatingMetamaskNotifications) {
|
|
871
759
|
this.update((state) => {
|
|
872
760
|
state.isUpdatingMetamaskNotifications = isUpdatingMetamaskNotifications;
|