@metamask-previews/notification-services-controller 23.1.1-preview-ccdc8dcd5 → 23.1.1-preview-e5cef32c6
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 +15 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.cts +9 -2
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.mts +9 -2
- 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 +178 -42
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +37 -7
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +37 -7
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +178 -42
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.cjs +1 -13
- package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts +10 -32
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts +10 -32
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.mjs +1 -12
- package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.cjs +3 -28
- package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.cts +1 -20
- package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.mts +1 -20
- package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.mjs +2 -25
- package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -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, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
|
|
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_registerWalletActivityAddresses, _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
|
|
28
|
+
import { getAPINotifications, getNotificationsApiConfigCached, markNotificationsAsRead } 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,6 +108,84 @@ 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
|
+
});
|
|
111
189
|
const MESSENGER_EXPOSED_METHODS = [
|
|
112
190
|
'init',
|
|
113
191
|
'enablePushNotifications',
|
|
@@ -377,14 +455,12 @@ export class NotificationServicesController extends BaseController {
|
|
|
377
455
|
*/
|
|
378
456
|
async enablePushNotifications() {
|
|
379
457
|
try {
|
|
380
|
-
const
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
if (addresses.length > 0) {
|
|
387
|
-
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(addresses);
|
|
458
|
+
const preferences = await this.messenger.call('AuthenticatedUserStorageService:getNotificationPreferences');
|
|
459
|
+
const enabledAddresses = (preferences?.walletActivity.accounts ?? [])
|
|
460
|
+
.filter((account) => account.enabled)
|
|
461
|
+
.map((account) => account.address);
|
|
462
|
+
if (enabledAddresses.length > 0) {
|
|
463
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(enabledAddresses);
|
|
388
464
|
}
|
|
389
465
|
}
|
|
390
466
|
catch {
|
|
@@ -400,13 +476,15 @@ export class NotificationServicesController extends BaseController {
|
|
|
400
476
|
async checkAccountsPresence(accounts) {
|
|
401
477
|
try {
|
|
402
478
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsCheckingAccountsPresence).call(this, true);
|
|
403
|
-
|
|
404
|
-
const
|
|
405
|
-
|
|
479
|
+
const preferences = await this.messenger.call('AuthenticatedUserStorageService:getNotificationPreferences');
|
|
480
|
+
const enabledByAddress = new Map((preferences?.walletActivity.accounts ?? []).map((account) => [
|
|
481
|
+
account.address.toLowerCase(),
|
|
482
|
+
account.enabled,
|
|
483
|
+
]));
|
|
406
484
|
const result = {};
|
|
407
|
-
|
|
408
|
-
result[
|
|
409
|
-
}
|
|
485
|
+
for (const address of accounts) {
|
|
486
|
+
result[address] = enabledByAddress.get(address.toLowerCase()) ?? false;
|
|
487
|
+
}
|
|
410
488
|
return result;
|
|
411
489
|
}
|
|
412
490
|
catch (error) {
|
|
@@ -442,9 +520,15 @@ export class NotificationServicesController extends BaseController {
|
|
|
442
520
|
*
|
|
443
521
|
* **Action** - Used during Sign In / Enabling of notifications.
|
|
444
522
|
*
|
|
523
|
+
* Notification preferences are initialized only when
|
|
524
|
+
* {@link AuthenticatedUserStorageService} has no stored preferences yet.
|
|
525
|
+
* Existing preferences are left as-is.
|
|
526
|
+
*
|
|
445
527
|
* @param opts - optional options to mutate this functionality
|
|
446
|
-
* @param opts.
|
|
447
|
-
*
|
|
528
|
+
* @param opts.hasMarketingConsent - The user's marketing-consent flag.
|
|
529
|
+
* Used only during initialization to seed marketing push notifications.
|
|
530
|
+
* @param opts.productAnnouncementEnabled - The user's product-announcement flag.
|
|
531
|
+
* Used only during initialization to seed marketing in-app notifications.
|
|
448
532
|
* @returns The updated or newly created user storage.
|
|
449
533
|
* @throws {Error} Throws an error if unauthenticated or from other operations.
|
|
450
534
|
*/
|
|
@@ -453,19 +537,23 @@ export class NotificationServicesController extends BaseController {
|
|
|
453
537
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
|
|
454
538
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
455
539
|
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
456
|
-
// 1.
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
let
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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;
|
|
540
|
+
// 1. Read existing AUS notification preferences and initialize only if absent.
|
|
541
|
+
const preferences = await this.messenger.call('AuthenticatedUserStorageService:getNotificationPreferences');
|
|
542
|
+
const hasMarketingConsent = Boolean(opts?.hasMarketingConsent);
|
|
543
|
+
const productAnnouncementEnabled = Boolean(opts?.productAnnouncementEnabled);
|
|
544
|
+
let nextPreferences;
|
|
545
|
+
if (preferences === null) {
|
|
546
|
+
const walletActivityAccounts = await buildWalletActivityAccountsFromTriggerConfig(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
547
|
+
nextPreferences = buildFreshPreferences(walletActivityAccounts, hasMarketingConsent, productAnnouncementEnabled);
|
|
467
548
|
}
|
|
468
|
-
|
|
549
|
+
if (nextPreferences) {
|
|
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)
|
|
469
557
|
__classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f")
|
|
470
558
|
.enablePushNotifications(accountsWithNotifications)
|
|
471
559
|
.catch(() => {
|
|
@@ -498,13 +586,14 @@ export class NotificationServicesController extends BaseController {
|
|
|
498
586
|
* Enables all MetaMask notifications for the user.
|
|
499
587
|
* This is identical flow when initializing notifications for the first time.
|
|
500
588
|
*
|
|
589
|
+
* @param opts - Optional settings for first-time AUS notification preferences initialization.
|
|
501
590
|
* @throws {Error} If there is an error during the process of enabling notifications.
|
|
502
591
|
*/
|
|
503
|
-
async enableMetamaskNotifications() {
|
|
592
|
+
async enableMetamaskNotifications(opts) {
|
|
504
593
|
try {
|
|
505
594
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
|
|
506
595
|
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_enableAuth).call(this);
|
|
507
|
-
await this.createOnChainTriggers();
|
|
596
|
+
await this.createOnChainTriggers(opts);
|
|
508
597
|
}
|
|
509
598
|
catch (error) {
|
|
510
599
|
log.error('Unable to enable notifications', error);
|
|
@@ -559,10 +648,9 @@ export class NotificationServicesController extends BaseController {
|
|
|
559
648
|
async disableAccounts(accounts) {
|
|
560
649
|
try {
|
|
561
650
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
|
|
562
|
-
//
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
await updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: false })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
651
|
+
// Sign-in gate.
|
|
652
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
653
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerWalletActivityAddresses).call(this, accounts.map((address) => ({ address, enabled: false })));
|
|
566
654
|
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").deletePushNotificationLinks(accounts);
|
|
567
655
|
}
|
|
568
656
|
catch {
|
|
@@ -590,8 +678,9 @@ export class NotificationServicesController extends BaseController {
|
|
|
590
678
|
async enableAccounts(accounts) {
|
|
591
679
|
try {
|
|
592
680
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
|
|
593
|
-
|
|
594
|
-
await
|
|
681
|
+
// Sign-in gate.
|
|
682
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
683
|
+
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerWalletActivityAddresses).call(this, accounts.map((address) => ({ address, enabled: true })));
|
|
595
684
|
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").addPushNotificationLinks(accounts);
|
|
596
685
|
}
|
|
597
686
|
catch (error) {
|
|
@@ -627,10 +716,10 @@ export class NotificationServicesController extends BaseController {
|
|
|
627
716
|
if (isGlobalNotifsEnabled) {
|
|
628
717
|
try {
|
|
629
718
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
630
|
-
const
|
|
631
|
-
const addressesWithNotifications = (
|
|
632
|
-
.filter((
|
|
633
|
-
.map((
|
|
719
|
+
const preferences = await this.messenger.call('AuthenticatedUserStorageService:getNotificationPreferences');
|
|
720
|
+
const addressesWithNotifications = (preferences?.walletActivity.accounts ?? [])
|
|
721
|
+
.filter((account) => account.enabled)
|
|
722
|
+
.map((account) => account.address);
|
|
634
723
|
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(() => []);
|
|
635
724
|
rawOnChainNotifications.push(...notifications);
|
|
636
725
|
}
|
|
@@ -855,6 +944,53 @@ _NotificationServicesController_keyringController = new WeakMap(), _Notification
|
|
|
855
944
|
throw new Error('Missing BearerToken');
|
|
856
945
|
}
|
|
857
946
|
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);
|
|
858
994
|
}, _NotificationServicesController_setIsUpdatingMetamaskNotifications = function _NotificationServicesController_setIsUpdatingMetamaskNotifications(isUpdatingMetamaskNotifications) {
|
|
859
995
|
this.update((state) => {
|
|
860
996
|
state.isUpdatingMetamaskNotifications = isUpdatingMetamaskNotifications;
|