@metamask-previews/notification-services-controller 26.0.1-preview-acb2929f3 → 26.0.1-preview-e3275932a

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.
Files changed (24) hide show
  1. package/CHANGELOG.md +0 -18
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +112 -128
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  5. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.mjs +113 -129
  7. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  8. package/dist/NotificationServicesController/mocks/mockResponses.cjs +1 -9
  9. package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
  10. package/dist/NotificationServicesController/mocks/mockResponses.d.cts +0 -1
  11. package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
  12. package/dist/NotificationServicesController/mocks/mockResponses.d.mts +0 -1
  13. package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
  14. package/dist/NotificationServicesController/mocks/mockResponses.mjs +1 -8
  15. package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
  16. package/dist/NotificationServicesController/services/api-notifications.cjs +4 -43
  17. package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
  18. package/dist/NotificationServicesController/services/api-notifications.d.cts +2 -23
  19. package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -1
  20. package/dist/NotificationServicesController/services/api-notifications.d.mts +2 -23
  21. package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -1
  22. package/dist/NotificationServicesController/services/api-notifications.mjs +3 -40
  23. package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
  24. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -9,27 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
- - **BREAKING:** `getNotificationsApiConfigCached` now returns `null` when the Trigger API could not be read, and an empty array only when the API reported that no address is subscribed ([#9985](https://github.com/MetaMask/core/pull/9985))
13
- - Previously both cases returned an empty array, so callers could not tell "the user has nothing enabled" from "we failed to ask", and acting on the guess re-subscribed or unregistered addresses behind the user.
14
12
  - Bump `@metamask/keyring-controller` from `^27.1.0` to `^27.1.1` ([#9791](https://github.com/MetaMask/core/pull/9791))
15
13
  - Bump `@metamask/authenticated-user-storage` from `^3.0.1` to `^3.0.2` ([#9972](https://github.com/MetaMask/core/pull/9972))
16
14
 
17
- ### Fixed
18
-
19
- - **BREAKING:** Wallet-activity addresses are once again sourced from the keyring and the Trigger API instead of Authenticated User Storage, which stops users receiving notifications for addresses they do not hold ([#9985](https://github.com/MetaMask/core/pull/9985))
20
- - Authenticated User Storage is keyed by canonical profile ID, which profile pairing shares across every SRP belonging to the same user, so an address list stored there pooled the addresses of unrelated SRPs and delivered each installation the union of all of them. Addresses are keyring-scoped and cannot live in profile-scoped storage.
21
- - `checkAccountsPresence`, `fetchAndUpdateMetamaskNotifications` and `enablePushNotifications` now take the candidate addresses from the keyring and read the per-address enabled bit from the Trigger API. An installation can therefore only ever ask about addresses it holds.
22
- - `enableAccounts` and `disableAccounts` now write subscriptions to the Trigger API. The endpoint is a per-address upsert, so two installations authenticating as the same profile no longer clobber each other's subscriptions.
23
- - `createOnChainTriggers` no longer writes addresses into `walletActivity.accounts`; it writes an empty list. It subscribes the keyring's accounts only when initializing preferences for the first time and the Trigger API has no subscriptions yet, so the daily re-subscribe can no longer re-enable accounts the user turned off.
24
- - The user-level `walletActivity.inAppNotificationsEnabled` and `walletActivity.pushNotificationsEnabled` toggles are still read from Authenticated User Storage. They contain no addresses, so they remain correct to share across a paired profile. An unreadable preferences blob is treated as both toggles enabled, so a storage outage no longer empties the notification list.
25
- - Unregister the device from push notifications when no account has notifications enabled ([#9985](https://github.com/MetaMask/core/pull/9985))
26
- - The push API rejects a registration with no addresses, and that request is what performs the delete-and-reinsert of the device's links, so the rejection left the previous links in place and push kept arriving after a user disabled every account.
27
- - `enableAccounts` and `disableAccounts` now reject when the Trigger API rejects the subscription change, instead of reporting success and caching a state the server never applied ([#9985](https://github.com/MetaMask/core/pull/9985))
28
- - A 4xx/5xx response was treated as success, so the settings UI showed the new toggle position and push links were added or removed for a subscription that did not change.
29
- - A failed Trigger API config read no longer re-enables accounts or unregisters the device ([#9985](https://github.com/MetaMask/core/pull/9985))
30
- - `createOnChainTriggers` now fails instead of reading a failed config query as "no subscriptions yet", which could subscribe every keyring account for a user who had turned them off, and it writes the preferences blob only after those subscriptions are in place so a failed run can still be retried as a first-time setup.
31
- - `enablePushNotifications` leaves the device's existing push links alone rather than unregistering it, and `checkAccountsPresence` rejects rather than reporting every account as disabled.
32
-
33
15
  ## [26.0.1]
34
16
 
35
17
  ### Changed
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- 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_isWalletActivityPushEnabled, _NotificationServicesController_registerPushNotifications, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
16
+ 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;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.NotificationServicesController = exports.DEFAULT_PRICE_ALERT_PREFERENCES = exports.DEFAULT_AGENTIC_CLI_PREFERENCES = exports.DEFAULT_SOCIAL_AI_PREFERENCES = exports.DEFAULT_PERPS_PREFERENCES = exports.defaultState = exports.ACCOUNTS_UPDATE_DEBOUNCE_TIME_MS = void 0;
19
19
  const authenticated_user_storage_1 = require("@metamask/authenticated-user-storage");
@@ -129,46 +129,57 @@ var authenticated_user_storage_2 = require("@metamask/authenticated-user-storage
129
129
  Object.defineProperty(exports, "DEFAULT_AGENTIC_CLI_PREFERENCES", { enumerable: true, get: function () { return authenticated_user_storage_2.DEFAULT_AGENTIC_CLI_PREFERENCES; } });
130
130
  Object.defineProperty(exports, "DEFAULT_PRICE_ALERT_PREFERENCES", { enumerable: true, get: function () { return authenticated_user_storage_2.DEFAULT_PRICE_ALERT_PREFERENCES; } });
131
131
  /**
132
- * Returns the subset of `accounts` that has a wallet-activity subscription in
133
- * the Trigger API, which is the source of truth for the per-address enabled bit.
132
+ * Builds wallet-activity preferences from the keyring's current accounts.
134
133
  *
135
- * The address universe is always supplied by the caller from the keyring, so the
136
- * result cannot contain an address this installation does not hold.
134
+ * @param accounts - The keyring accounts to build wallet-activity entries for.
135
+ * @returns An array of wallet-activity account entries (lower-cased addresses).
136
+ */
137
+ const buildWalletActivityAccounts = (accounts) => accounts.map(({ address, enabled }) => {
138
+ const lowercased = address.toLowerCase();
139
+ return {
140
+ address: lowercased,
141
+ enabled,
142
+ };
143
+ });
144
+ /**
145
+ * Builds wallet-activity initialization from the Trigger API. If Trigger has no
146
+ * enabled entries for the current keyring accounts, this is a first-time
147
+ * notification setup and all current accounts should start enabled.
137
148
  *
138
- * @param bearerToken - JWT used to query the Trigger API.
139
- * @param accounts - The keyring accounts to check.
149
+ * @param bearerToken - JWT used to query Trigger API.
150
+ * @param accounts - The keyring accounts to initialize.
140
151
  * @param env - The environment to use for the Trigger API call.
141
- * @returns The enabled addresses, as returned by the Trigger API, or `null` if
142
- * the Trigger API could not be read.
152
+ * @returns Wallet-activity account initialization entries.
143
153
  */
144
- const getEnabledAccounts = async (bearerToken, accounts, env) => {
154
+ const buildWalletActivityAccountsFromTriggerConfig = async (bearerToken, accounts, env) => {
145
155
  const triggerConfig = await (0, api_notifications_js_1.getNotificationsApiConfigCached)(bearerToken, accounts, env);
146
- if (triggerConfig === null) {
147
- return null;
148
- }
149
- return triggerConfig
150
- .filter((addressConfig) => Boolean(addressConfig.enabled))
151
- .map((addressConfig) => addressConfig.address);
156
+ const triggerConfigByAddress = new Map(triggerConfig.map(({ address, enabled }) => [
157
+ address.toLowerCase(),
158
+ enabled,
159
+ ]));
160
+ const hasEnabledTriggerAccount = accounts.some((address) => triggerConfigByAddress.get(address.toLowerCase()) === true);
161
+ return accounts.map((address) => ({
162
+ address,
163
+ enabled: hasEnabledTriggerAccount
164
+ ? (triggerConfigByAddress.get(address.toLowerCase()) ?? false)
165
+ : true,
166
+ }));
152
167
  };
153
168
  /**
154
169
  * Builds a fresh `NotificationPreferences` blob using hardcoded defaults for
155
- * Perps, Social AI, and Agentic CLI and the user's marketing/product-announcement
156
- * flags.
157
- *
158
- * `walletActivity.accounts` is deliberately left empty. Addresses are scoped to a
159
- * keyring, but this blob is keyed by canonical profile ID, which pairing shares
160
- * across every SRP belonging to the same user — so storing them here pools the
161
- * addresses of unrelated SRPs. Subscriptions live in the Trigger API instead.
170
+ * Perps, Social AI, and Agentic CLI, the supplied wallet-activity accounts and
171
+ * the user's marketing/product-announcement flags.
162
172
  *
173
+ * @param walletActivityAccounts - The wallet-activity account config to initialize.
163
174
  * @param hasMarketingConsent - Whether marketing push notifications should be enabled.
164
175
  * @param productAnnouncementEnabled - Whether marketing in-app notifications should be enabled.
165
176
  * @returns A complete `NotificationPreferences` object.
166
177
  */
167
- const buildFreshPreferences = (hasMarketingConsent, productAnnouncementEnabled) => ({
178
+ const buildFreshPreferences = (walletActivityAccounts, hasMarketingConsent, productAnnouncementEnabled) => ({
168
179
  walletActivity: {
169
180
  inAppNotificationsEnabled: true,
170
181
  pushNotificationsEnabled: true,
171
- accounts: [],
182
+ accounts: buildWalletActivityAccounts(walletActivityAccounts),
172
183
  },
173
184
  marketing: {
174
185
  inAppNotificationsEnabled: productAnnouncementEnabled,
@@ -470,20 +481,13 @@ class NotificationServicesController extends base_controller_1.BaseController {
470
481
  */
471
482
  async enablePushNotifications() {
472
483
  try {
473
- if (!(await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_isWalletActivityPushEnabled).call(this))) {
474
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").disablePushNotifications();
475
- return;
476
- }
477
- const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
478
- const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
479
- const enabledAddresses = await getEnabledAccounts(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
480
- if (enabledAddresses === null) {
481
- // "No addresses" unregisters the device, so an unreadable subscription
482
- // list must not be treated as an empty one: leave the existing links
483
- // alone until we can read the real state.
484
- return;
484
+ const preferences = await this.messenger.call('AuthenticatedUserStorageService:getNotificationPreferences');
485
+ const enabledAddresses = (preferences?.walletActivity.accounts ?? [])
486
+ .filter((account) => account.enabled)
487
+ .map((account) => account.address);
488
+ if (enabledAddresses.length > 0) {
489
+ await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(enabledAddresses);
485
490
  }
486
- await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerPushNotifications).call(this, enabledAddresses);
487
491
  }
488
492
  catch {
489
493
  // Do nothing, failing silently.
@@ -498,16 +502,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
498
502
  async checkAccountsPresence(accounts) {
499
503
  try {
500
504
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsCheckingAccountsPresence).call(this, true);
501
- const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
502
- const triggerConfig = await (0, api_notifications_js_1.getNotificationsApiConfigCached)(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
503
- if (triggerConfig === null) {
504
- // Reporting every account as disabled would misrepresent the user's
505
- // settings, so surface the failure instead.
506
- throw new Error('Failed to read wallet-activity subscriptions');
507
- }
508
- const enabledByAddress = new Map(triggerConfig.map((addressConfig) => [
509
- addressConfig.address.toLowerCase(),
510
- Boolean(addressConfig.enabled),
505
+ const preferences = await this.messenger.call('AuthenticatedUserStorageService:getNotificationPreferences');
506
+ const enabledByAddress = new Map((preferences?.walletActivity.accounts ?? []).map((account) => [
507
+ account.address.toLowerCase(),
508
+ account.enabled,
511
509
  ]));
512
510
  const result = {};
513
511
  for (const address of accounts) {
@@ -566,46 +564,27 @@ class NotificationServicesController extends base_controller_1.BaseController {
566
564
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
567
565
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
568
566
  const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
569
- // 1. Read existing AUS notification preferences. Their absence is what
570
- // marks a first-time setup, and they are initialized in step 3.
567
+ // 1. Read existing AUS notification preferences and initialize only if absent.
571
568
  const preferences = await this.messenger.call('AuthenticatedUserStorageService:getNotificationPreferences');
572
569
  const hasMarketingConsent = Boolean(opts?.hasMarketingConsent);
573
570
  const productAnnouncementEnabled = Boolean(opts?.productAnnouncementEnabled);
574
- const isFirstTimeSetup = preferences === null;
575
- const isPushEnabled = preferences?.walletActivity.pushNotificationsEnabled ?? true;
576
- // 2. Subscribe the keyring's accounts on first-time setup only.
577
- //
578
- // This method also runs on the daily re-subscribe, so the absence of a
579
- // preferences blob — not the absence of subscriptions — is what marks a
580
- // genuine first-time setup. Keying off "no subscriptions" would re-enable
581
- // every account daily for a user who had turned them all off.
582
- //
583
- // Even at first-time setup, existing subscriptions win: a user upgrading
584
- // from a client that never wrote a preferences blob keeps whichever
585
- // accounts they had already disabled.
586
- let accountsWithNotifications = await getEnabledAccounts(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
587
- if (accountsWithNotifications === null) {
588
- // An unreadable subscription list is not an empty one. Subscribing
589
- // every account here would re-enable ones the user had turned off, and
590
- // registering push for that guessed list would send activity for them,
591
- // so fail and let the caller retry.
592
- throw new Error('Failed to read wallet-activity subscriptions');
593
- }
594
- if (isFirstTimeSetup && accountsWithNotifications.length === 0) {
595
- await (0, api_notifications_js_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
596
- accountsWithNotifications = accounts;
571
+ let nextPreferences;
572
+ if (preferences === null) {
573
+ const walletActivityAccounts = await buildWalletActivityAccountsFromTriggerConfig(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
574
+ nextPreferences = buildFreshPreferences(walletActivityAccounts, hasMarketingConsent, productAnnouncementEnabled);
597
575
  }
598
- // 3. Initialize the preferences blob, only once the subscriptions above
599
- // are in place. Its existence is what makes the next run a re-subscribe
600
- // rather than a first-time setup, so writing it earlier would let a
601
- // failed subscribe leave the user enabled with no accounts subscribed
602
- // and no second chance to seed them.
603
- if (isFirstTimeSetup) {
604
- await this.messenger.call('AuthenticatedUserStorageService:putNotificationPreferences', buildFreshPreferences(hasMarketingConsent, productAnnouncementEnabled), __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform);
576
+ if (nextPreferences) {
577
+ await this.messenger.call('AuthenticatedUserStorageService:putNotificationPreferences', nextPreferences, __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform);
605
578
  }
579
+ const effectivePreferences = nextPreferences ?? preferences;
580
+ const accountsWithNotifications = (effectivePreferences?.walletActivity.accounts ?? [])
581
+ .filter((account) => account.enabled)
582
+ .map((account) => account.address);
606
583
  if (opts.registerPushNotifications ?? true) {
607
584
  // Attempt FCM/device registration only; clients must request OS permission separately.
608
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerPushNotifications).call(this, isPushEnabled ? accountsWithNotifications : []).catch(() => {
585
+ __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f")
586
+ .enablePushNotifications(accountsWithNotifications)
587
+ .catch(() => {
609
588
  // Do Nothing
610
589
  });
611
590
  }
@@ -698,8 +677,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
698
677
  async disableAccounts(accounts) {
699
678
  try {
700
679
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
701
- const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
702
- await (0, api_notifications_js_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: false })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
680
+ // Sign-in gate.
681
+ await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
682
+ await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerWalletActivityAddresses).call(this, accounts.map((address) => ({ address, enabled: false })));
703
683
  await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").deletePushNotificationLinks(accounts);
704
684
  }
705
685
  catch {
@@ -727,8 +707,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
727
707
  async enableAccounts(accounts) {
728
708
  try {
729
709
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
730
- const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
731
- await (0, api_notifications_js_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
710
+ // Sign-in gate.
711
+ await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
712
+ await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerWalletActivityAddresses).call(this, accounts.map((address) => ({ address, enabled: true })));
732
713
  await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").addPushNotificationLinks(accounts);
733
714
  }
734
715
  catch (error) {
@@ -767,20 +748,14 @@ class NotificationServicesController extends base_controller_1.BaseController {
767
748
  : [];
768
749
  // Raw On Chain Notifications
769
750
  const rawOnChainNotifications = [];
770
- const isWalletActivityInAppEnabled = notificationPreferences?.walletActivity.inAppNotificationsEnabled ??
771
- true;
772
- if (isGlobalNotifsEnabled && isWalletActivityInAppEnabled) {
751
+ if (isGlobalNotifsEnabled) {
773
752
  try {
774
753
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
775
- // Addresses come from the keyring, so this installation can only ever
776
- // ask for activity on accounts it actually holds. The Trigger API
777
- // narrows that to the ones the user has enabled.
778
- const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
779
- const addressesWithNotifications = await getEnabledAccounts(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
780
- if (addressesWithNotifications !== null) {
781
- const notifications = await (0, api_notifications_js_1.getAPINotifications)(bearerToken, addressesWithNotifications, __classPrivateFieldGet(this, _NotificationServicesController_locale, "f").call(this), __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform, __classPrivateFieldGet(this, _NotificationServicesController_env, "f")).catch(() => []);
782
- rawOnChainNotifications.push(...notifications);
783
- }
754
+ const addressesWithNotifications = (notificationPreferences?.walletActivity.accounts ?? [])
755
+ .filter((account) => account.enabled)
756
+ .map((account) => account.address);
757
+ const notifications = await (0, api_notifications_js_1.getAPINotifications)(bearerToken, addressesWithNotifications, __classPrivateFieldGet(this, _NotificationServicesController_locale, "f").call(this), __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform, __classPrivateFieldGet(this, _NotificationServicesController_env, "f")).catch(() => []);
758
+ rawOnChainNotifications.push(...notifications);
784
759
  }
785
760
  catch {
786
761
  // Do nothing
@@ -1004,44 +979,53 @@ _NotificationServicesController_keyringController = new WeakMap(), _Notification
1004
979
  throw new Error('Missing BearerToken');
1005
980
  }
1006
981
  return { bearerToken };
1007
- }, _NotificationServicesController_isWalletActivityPushEnabled =
982
+ }, _NotificationServicesController_registerWalletActivityAddresses =
1008
983
  /**
1009
- * Reads the global wallet-activity push toggle from
1010
- * {@link AuthenticatedUserStorageService}.
1011
- *
1012
- * Only the channel boolean is read. It is a user-level setting that contains
1013
- * no addresses, so sharing it across a paired profile is correct. The address
1014
- * list in the same blob is deliberately ignored — see
1015
- * {@link buildFreshPreferences}.
984
+ * Updates the `walletActivity.accounts` entries in the user's
985
+ * notification-preferences blob in {@link AuthenticatedUserStorageService}.
1016
986
  *
1017
- * A missing or unreadable blob counts as enabled, matching the API's "every
1018
- * toggle is on unless stated otherwise" default, so that a storage outage does
1019
- * not silently stop notifications.
987
+ * `putNotificationPreferences` replaces the entire blob, so we read the
988
+ * current preferences, merge the supplied updates into
989
+ * `walletActivity.accounts`, and write the result back. This helper is only
990
+ * meant to be used for incremental updates (enable/disable individual
991
+ * accounts) after the preferences blob has already been initialized via
992
+ * {@link createOnChainTriggers}; callers should not rely on it to perform
993
+ * first-time initialization.
1020
994
  *
1021
- * @returns Whether wallet-activity push notifications are enabled.
995
+ * @param updates - Addresses to register, each with the desired `enabled` flag
1022
996
  */
1023
- async function _NotificationServicesController_isWalletActivityPushEnabled() {
1024
- const preferences = await this.messenger
997
+ async function _NotificationServicesController_registerWalletActivityAddresses(updates) {
998
+ if (updates.length === 0) {
999
+ return;
1000
+ }
1001
+ const currentPreferences = await this.messenger
1025
1002
  .call('AuthenticatedUserStorageService:getNotificationPreferences')
1026
- .catch(() => null);
1027
- return preferences?.walletActivity.pushNotificationsEnabled ?? true;
1028
- }, _NotificationServicesController_registerPushNotifications =
1029
- /**
1030
- * Registers this device for push notifications on the given addresses.
1031
- *
1032
- * An empty list cannot be sent: the push API rejects a registration with no
1033
- * addresses, and because that request is what performs the delete-and-reinsert
1034
- * of the device's links, a rejection leaves the previous links in place and
1035
- * push keeps arriving. So "no addresses" has to mean unregistering the device.
1036
- *
1037
- * @param addresses - The addresses to receive push notifications for.
1038
- */
1039
- async function _NotificationServicesController_registerPushNotifications(addresses) {
1040
- if (addresses.length === 0) {
1041
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").disablePushNotifications();
1003
+ .catch((error) => {
1004
+ loglevel_1.default.error('Failed to get notification preferences. Re-initializing them instead.', error);
1005
+ // TODO: return null once validation error captured
1006
+ // return null;
1007
+ throw error;
1008
+ });
1009
+ if (!currentPreferences) {
1010
+ loglevel_1.default.warn('Preferences blob not yet initialized; run `createOnChainTriggers` first.');
1042
1011
  return;
1043
1012
  }
1044
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(addresses);
1013
+ const accountsByAddress = new Map(currentPreferences.walletActivity.accounts.map((account) => [
1014
+ account.address.toLowerCase(),
1015
+ { ...account, address: account.address.toLowerCase() },
1016
+ ]));
1017
+ for (const update of updates) {
1018
+ const address = update.address.toLowerCase();
1019
+ accountsByAddress.set(address, { address, enabled: update.enabled });
1020
+ }
1021
+ const nextPreferences = {
1022
+ ...currentPreferences,
1023
+ walletActivity: {
1024
+ ...currentPreferences.walletActivity,
1025
+ accounts: [...accountsByAddress.values()],
1026
+ },
1027
+ };
1028
+ await this.messenger.call('AuthenticatedUserStorageService:putNotificationPreferences', nextPreferences, __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform);
1045
1029
  }, _NotificationServicesController_setIsUpdatingMetamaskNotifications = function _NotificationServicesController_setIsUpdatingMetamaskNotifications(isUpdatingMetamaskNotifications) {
1046
1030
  this.update((state) => {
1047
1031
  state.isUpdatingMetamaskNotifications = isUpdatingMetamaskNotifications;