@metamask-previews/notification-services-controller 23.1.1-preview-e5cef32c6 → 23.1.1-preview-a96479ea9
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 +1 -14
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.cts +2 -9
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.mts +2 -9
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.mjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.cjs +42 -178
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +7 -37
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +7 -37
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +42 -178
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.cjs +13 -1
- package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts +32 -10
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts +32 -10
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.mjs +12 -1
- package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.cjs +28 -3
- package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.cts +20 -1
- package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.mts +20 -1
- package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.mjs +25 -2
- package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
|
@@ -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, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_locale, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_env, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth, _NotificationServicesController_getBearerToken,
|
|
12
|
+
var _NotificationServicesController_instances, _NotificationServicesController_keyringController, _NotificationServicesController_auth, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_locale, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_env, _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;
|
|
@@ -25,7 +25,7 @@ import $log from "loglevel";
|
|
|
25
25
|
const log = $importDefault($log);
|
|
26
26
|
import { TRIGGER_TYPES } from "./constants/notification-schema.mjs";
|
|
27
27
|
import { processAndFilterNotifications, safeProcessNotification } from "./processors/process-notifications.mjs";
|
|
28
|
-
import { getAPINotifications, getNotificationsApiConfigCached, markNotificationsAsRead } from "./services/api-notifications.mjs";
|
|
28
|
+
import { getAPINotifications, getNotificationsApiConfigCached, markNotificationsAsRead, updateOnChainNotifications } from "./services/api-notifications.mjs";
|
|
29
29
|
import { getFeatureAnnouncementNotifications } from "./services/feature-announcements.mjs";
|
|
30
30
|
import { createPerpOrderNotification } from "./services/perp-notifications.mjs";
|
|
31
31
|
// Unique name for the controller
|
|
@@ -108,84 +108,6 @@ export const defaultState = {
|
|
|
108
108
|
const locallyPersistedNotificationTypes = new Set([
|
|
109
109
|
TRIGGER_TYPES.SNAP,
|
|
110
110
|
]);
|
|
111
|
-
/**
|
|
112
|
-
* Hardcoded default Perps notification preferences. Applied when notification
|
|
113
|
-
* preferences are initialized for the first time.
|
|
114
|
-
*/
|
|
115
|
-
export const DEFAULT_PERPS_PREFERENCES = {
|
|
116
|
-
inAppNotificationsEnabled: true,
|
|
117
|
-
pushNotificationsEnabled: true,
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Hardcoded default Social AI notification preferences. Applied when
|
|
121
|
-
* notification preferences are initialized for the first time.
|
|
122
|
-
*/
|
|
123
|
-
export const DEFAULT_SOCIAL_AI_PREFERENCES = {
|
|
124
|
-
inAppNotificationsEnabled: true,
|
|
125
|
-
pushNotificationsEnabled: true,
|
|
126
|
-
txAmountLimit: 500,
|
|
127
|
-
mutedTraderProfileIds: [],
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Builds wallet-activity preferences from the keyring's current accounts.
|
|
131
|
-
*
|
|
132
|
-
* @param accounts - The keyring accounts to build wallet-activity entries for.
|
|
133
|
-
* @returns An array of wallet-activity account entries (lower-cased addresses).
|
|
134
|
-
*/
|
|
135
|
-
const buildWalletActivityAccounts = (accounts) => accounts.map(({ address, enabled }) => {
|
|
136
|
-
const lowercased = address.toLowerCase();
|
|
137
|
-
return {
|
|
138
|
-
address: lowercased,
|
|
139
|
-
enabled,
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
/**
|
|
143
|
-
* Builds wallet-activity initialization from the Trigger API. If Trigger has no
|
|
144
|
-
* enabled entries for the current keyring accounts, this is a first-time
|
|
145
|
-
* notification setup and all current accounts should start enabled.
|
|
146
|
-
*
|
|
147
|
-
* @param bearerToken - JWT used to query Trigger API.
|
|
148
|
-
* @param accounts - The keyring accounts to initialize.
|
|
149
|
-
* @param env - The environment to use for the Trigger API call.
|
|
150
|
-
* @returns Wallet-activity account initialization entries.
|
|
151
|
-
*/
|
|
152
|
-
const buildWalletActivityAccountsFromTriggerConfig = async (bearerToken, accounts, env) => {
|
|
153
|
-
const triggerConfig = await getNotificationsApiConfigCached(bearerToken, accounts, env);
|
|
154
|
-
const triggerConfigByAddress = new Map(triggerConfig.map(({ address, enabled }) => [
|
|
155
|
-
address.toLowerCase(),
|
|
156
|
-
enabled,
|
|
157
|
-
]));
|
|
158
|
-
const hasEnabledTriggerAccount = accounts.some((address) => triggerConfigByAddress.get(address.toLowerCase()) === true);
|
|
159
|
-
return accounts.map((address) => ({
|
|
160
|
-
address,
|
|
161
|
-
enabled: hasEnabledTriggerAccount
|
|
162
|
-
? (triggerConfigByAddress.get(address.toLowerCase()) ?? false)
|
|
163
|
-
: true,
|
|
164
|
-
}));
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* Builds a fresh `NotificationPreferences` blob using hardcoded defaults for
|
|
168
|
-
* Perps and Social AI, the supplied wallet-activity accounts and the user's
|
|
169
|
-
* marketing/product-announcement flags.
|
|
170
|
-
*
|
|
171
|
-
* @param walletActivityAccounts - The wallet-activity account config to initialize.
|
|
172
|
-
* @param hasMarketingConsent - Whether marketing push notifications should be enabled.
|
|
173
|
-
* @param productAnnouncementEnabled - Whether marketing in-app notifications should be enabled.
|
|
174
|
-
* @returns A complete `NotificationPreferences` object.
|
|
175
|
-
*/
|
|
176
|
-
const buildFreshPreferences = (walletActivityAccounts, hasMarketingConsent, productAnnouncementEnabled) => ({
|
|
177
|
-
walletActivity: {
|
|
178
|
-
inAppNotificationsEnabled: true,
|
|
179
|
-
pushNotificationsEnabled: true,
|
|
180
|
-
accounts: buildWalletActivityAccounts(walletActivityAccounts),
|
|
181
|
-
},
|
|
182
|
-
marketing: {
|
|
183
|
-
inAppNotificationsEnabled: productAnnouncementEnabled,
|
|
184
|
-
pushNotificationsEnabled: hasMarketingConsent,
|
|
185
|
-
},
|
|
186
|
-
perps: { ...DEFAULT_PERPS_PREFERENCES },
|
|
187
|
-
socialAI: { ...DEFAULT_SOCIAL_AI_PREFERENCES },
|
|
188
|
-
});
|
|
189
111
|
const MESSENGER_EXPOSED_METHODS = [
|
|
190
112
|
'init',
|
|
191
113
|
'enablePushNotifications',
|
|
@@ -455,12 +377,14 @@ export class NotificationServicesController extends BaseController {
|
|
|
455
377
|
*/
|
|
456
378
|
async enablePushNotifications() {
|
|
457
379
|
try {
|
|
458
|
-
const
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
380
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
381
|
+
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
382
|
+
const addressesWithNotifications = await getNotificationsApiConfigCached(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
383
|
+
const addresses = addressesWithNotifications
|
|
384
|
+
.filter((addressConfig) => Boolean(addressConfig.enabled))
|
|
385
|
+
.map((addressConfig) => addressConfig.address);
|
|
386
|
+
if (addresses.length > 0) {
|
|
387
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(addresses);
|
|
464
388
|
}
|
|
465
389
|
}
|
|
466
390
|
catch {
|
|
@@ -476,15 +400,13 @@ export class NotificationServicesController extends BaseController {
|
|
|
476
400
|
async checkAccountsPresence(accounts) {
|
|
477
401
|
try {
|
|
478
402
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsCheckingAccountsPresence).call(this, true);
|
|
479
|
-
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
account.enabled,
|
|
483
|
-
]));
|
|
403
|
+
// Retrieve user storage
|
|
404
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
405
|
+
const addressesWithNotifications = await getNotificationsApiConfigCached(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
484
406
|
const result = {};
|
|
485
|
-
|
|
486
|
-
result[address] =
|
|
487
|
-
}
|
|
407
|
+
addressesWithNotifications.forEach((a) => {
|
|
408
|
+
result[a.address] = a.enabled;
|
|
409
|
+
});
|
|
488
410
|
return result;
|
|
489
411
|
}
|
|
490
412
|
catch (error) {
|
|
@@ -520,15 +442,9 @@ export class NotificationServicesController extends BaseController {
|
|
|
520
442
|
*
|
|
521
443
|
* **Action** - Used during Sign In / Enabling of notifications.
|
|
522
444
|
*
|
|
523
|
-
* Notification preferences are initialized only when
|
|
524
|
-
* {@link AuthenticatedUserStorageService} has no stored preferences yet.
|
|
525
|
-
* Existing preferences are left as-is.
|
|
526
|
-
*
|
|
527
445
|
* @param opts - optional options to mutate this functionality
|
|
528
|
-
* @param opts.
|
|
529
|
-
*
|
|
530
|
-
* @param opts.productAnnouncementEnabled - The user's product-announcement flag.
|
|
531
|
-
* Used only during initialization to seed marketing in-app notifications.
|
|
446
|
+
* @param opts.resetNotifications - this will not use the users stored preferences, and instead re-create notification triggers
|
|
447
|
+
* It will help in case uses get into a corrupted state or wants to wipe their notifications.
|
|
532
448
|
* @returns The updated or newly created user storage.
|
|
533
449
|
* @throws {Error} Throws an error if unauthenticated or from other operations.
|
|
534
450
|
*/
|
|
@@ -537,23 +453,19 @@ export class NotificationServicesController extends BaseController {
|
|
|
537
453
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
|
|
538
454
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
539
455
|
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
540
|
-
// 1.
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
let
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
456
|
+
// 1. See if has enabled notifications before
|
|
457
|
+
const addressesWithNotifications = await getNotificationsApiConfigCached(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
458
|
+
// Notifications API can return array with addresses set to false
|
|
459
|
+
// So assert that at least one address is enabled
|
|
460
|
+
let accountsWithNotifications = addressesWithNotifications
|
|
461
|
+
.filter((addressConfig) => Boolean(addressConfig.enabled))
|
|
462
|
+
.map((addressConfig) => addressConfig.address);
|
|
463
|
+
// 2. Enable Notifications (if no accounts subscribed or we are resetting)
|
|
464
|
+
if (accountsWithNotifications.length === 0 || opts?.resetNotifications) {
|
|
465
|
+
await updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
466
|
+
accountsWithNotifications = accounts;
|
|
548
467
|
}
|
|
549
|
-
|
|
550
|
-
await this.messenger.call('AuthenticatedUserStorageService:putNotificationPreferences', nextPreferences, __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform);
|
|
551
|
-
}
|
|
552
|
-
const effectivePreferences = nextPreferences ?? preferences;
|
|
553
|
-
const accountsWithNotifications = (effectivePreferences?.walletActivity.accounts ?? [])
|
|
554
|
-
.filter((account) => account.enabled)
|
|
555
|
-
.map((account) => account.address);
|
|
556
|
-
// 2. Lazily enable push notifications (FCM may take some time, so keeps UI unblocked)
|
|
468
|
+
// 3. Lazily enable push notifications (FCM may take some time, so keeps UI unblocked)
|
|
557
469
|
__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f")
|
|
558
470
|
.enablePushNotifications(accountsWithNotifications)
|
|
559
471
|
.catch(() => {
|
|
@@ -586,14 +498,13 @@ export class NotificationServicesController extends BaseController {
|
|
|
586
498
|
* Enables all MetaMask notifications for the user.
|
|
587
499
|
* This is identical flow when initializing notifications for the first time.
|
|
588
500
|
*
|
|
589
|
-
* @param opts - Optional settings for first-time AUS notification preferences initialization.
|
|
590
501
|
* @throws {Error} If there is an error during the process of enabling notifications.
|
|
591
502
|
*/
|
|
592
|
-
async enableMetamaskNotifications(
|
|
503
|
+
async enableMetamaskNotifications() {
|
|
593
504
|
try {
|
|
594
505
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
|
|
595
506
|
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_enableAuth).call(this);
|
|
596
|
-
await this.createOnChainTriggers(
|
|
507
|
+
await this.createOnChainTriggers();
|
|
597
508
|
}
|
|
598
509
|
catch (error) {
|
|
599
510
|
log.error('Unable to enable notifications', error);
|
|
@@ -648,9 +559,10 @@ export class NotificationServicesController extends BaseController {
|
|
|
648
559
|
async disableAccounts(accounts) {
|
|
649
560
|
try {
|
|
650
561
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
|
|
651
|
-
//
|
|
652
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
653
|
-
|
|
562
|
+
// Get and Validate BearerToken and User Storage Key
|
|
563
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
564
|
+
// Delete these UUIDs (Mutates User Storage)
|
|
565
|
+
await updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: false })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
654
566
|
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").deletePushNotificationLinks(accounts);
|
|
655
567
|
}
|
|
656
568
|
catch {
|
|
@@ -678,9 +590,8 @@ export class NotificationServicesController extends BaseController {
|
|
|
678
590
|
async enableAccounts(accounts) {
|
|
679
591
|
try {
|
|
680
592
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
|
|
681
|
-
|
|
682
|
-
await __classPrivateFieldGet(this,
|
|
683
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerWalletActivityAddresses).call(this, accounts.map((address) => ({ address, enabled: true })));
|
|
593
|
+
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
594
|
+
await updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
684
595
|
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").addPushNotificationLinks(accounts);
|
|
685
596
|
}
|
|
686
597
|
catch (error) {
|
|
@@ -716,10 +627,10 @@ export class NotificationServicesController extends BaseController {
|
|
|
716
627
|
if (isGlobalNotifsEnabled) {
|
|
717
628
|
try {
|
|
718
629
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
719
|
-
const
|
|
720
|
-
const addressesWithNotifications = (
|
|
721
|
-
.filter((
|
|
722
|
-
.map((
|
|
630
|
+
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
631
|
+
const addressesWithNotifications = (await getNotificationsApiConfigCached(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f")))
|
|
632
|
+
.filter((addressConfig) => Boolean(addressConfig.enabled))
|
|
633
|
+
.map((addressConfig) => addressConfig.address);
|
|
723
634
|
const notifications = await getAPINotifications(bearerToken, addressesWithNotifications, __classPrivateFieldGet(this, _NotificationServicesController_locale, "f").call(this), __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform, __classPrivateFieldGet(this, _NotificationServicesController_env, "f")).catch(() => []);
|
|
724
635
|
rawOnChainNotifications.push(...notifications);
|
|
725
636
|
}
|
|
@@ -944,53 +855,6 @@ _NotificationServicesController_keyringController = new WeakMap(), _Notification
|
|
|
944
855
|
throw new Error('Missing BearerToken');
|
|
945
856
|
}
|
|
946
857
|
return { bearerToken };
|
|
947
|
-
}, _NotificationServicesController_registerWalletActivityAddresses =
|
|
948
|
-
/**
|
|
949
|
-
* Updates the `walletActivity.accounts` entries in the user's
|
|
950
|
-
* notification-preferences blob in {@link AuthenticatedUserStorageService}.
|
|
951
|
-
*
|
|
952
|
-
* `putNotificationPreferences` replaces the entire blob, so we read the
|
|
953
|
-
* current preferences, merge the supplied updates into
|
|
954
|
-
* `walletActivity.accounts`, and write the result back. This helper is only
|
|
955
|
-
* meant to be used for incremental updates (enable/disable individual
|
|
956
|
-
* accounts) after the preferences blob has already been initialized via
|
|
957
|
-
* {@link createOnChainTriggers}; callers should not rely on it to perform
|
|
958
|
-
* first-time initialization.
|
|
959
|
-
*
|
|
960
|
-
* @param updates - Addresses to register, each with the desired `enabled` flag
|
|
961
|
-
*/
|
|
962
|
-
async function _NotificationServicesController_registerWalletActivityAddresses(updates) {
|
|
963
|
-
if (updates.length === 0) {
|
|
964
|
-
return;
|
|
965
|
-
}
|
|
966
|
-
const currentPreferences = await this.messenger
|
|
967
|
-
.call('AuthenticatedUserStorageService:getNotificationPreferences')
|
|
968
|
-
.catch((error) => {
|
|
969
|
-
log.error('Failed to get notification preferences. Re-initializing them instead.', error);
|
|
970
|
-
// TODO: return null once validation error captured
|
|
971
|
-
// return null;
|
|
972
|
-
throw error;
|
|
973
|
-
});
|
|
974
|
-
if (!currentPreferences) {
|
|
975
|
-
log.warn('Preferences blob not yet initialized; run `createOnChainTriggers` first.');
|
|
976
|
-
return;
|
|
977
|
-
}
|
|
978
|
-
const accountsByAddress = new Map(currentPreferences.walletActivity.accounts.map((account) => [
|
|
979
|
-
account.address.toLowerCase(),
|
|
980
|
-
{ ...account, address: account.address.toLowerCase() },
|
|
981
|
-
]));
|
|
982
|
-
for (const update of updates) {
|
|
983
|
-
const address = update.address.toLowerCase();
|
|
984
|
-
accountsByAddress.set(address, { address, enabled: update.enabled });
|
|
985
|
-
}
|
|
986
|
-
const nextPreferences = {
|
|
987
|
-
...currentPreferences,
|
|
988
|
-
walletActivity: {
|
|
989
|
-
...currentPreferences.walletActivity,
|
|
990
|
-
accounts: [...accountsByAddress.values()],
|
|
991
|
-
},
|
|
992
|
-
};
|
|
993
|
-
await this.messenger.call('AuthenticatedUserStorageService:putNotificationPreferences', nextPreferences, __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform);
|
|
994
858
|
}, _NotificationServicesController_setIsUpdatingMetamaskNotifications = function _NotificationServicesController_setIsUpdatingMetamaskNotifications(isUpdatingMetamaskNotifications) {
|
|
995
859
|
this.update((state) => {
|
|
996
860
|
state.isUpdatingMetamaskNotifications = isUpdatingMetamaskNotifications;
|