@metamask/notification-services-controller 21.0.0 → 22.1.0
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 +41 -1
- package/dist/NotificationServicesController/NotificationServicesController.cjs +56 -42
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +3 -2
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +3 -2
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +56 -41
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.cjs +4 -12
- package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.d.cts +0 -12
- package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.d.mts +0 -12
- package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.mjs +3 -11
- package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
- package/dist/NotificationServicesController/index.cjs +1 -2
- package/dist/NotificationServicesController/index.cjs.map +1 -1
- package/dist/NotificationServicesController/index.d.cts +0 -1
- package/dist/NotificationServicesController/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/index.d.mts +0 -1
- package/dist/NotificationServicesController/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/index.mjs +0 -1
- package/dist/NotificationServicesController/index.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-feature-announcements.cjs +2 -2
- package/dist/NotificationServicesController/mocks/mock-feature-announcements.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-feature-announcements.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-feature-announcements.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-feature-announcements.mjs +2 -2
- package/dist/NotificationServicesController/mocks/mock-feature-announcements.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs +120 -0
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs +120 -0
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-snap-notification.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-snap-notification.d.cts +1 -1
- package/dist/NotificationServicesController/mocks/mock-snap-notification.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-snap-notification.d.mts +1 -1
- package/dist/NotificationServicesController/mocks/mock-snap-notification.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-snap-notification.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.cjs +6 -0
- package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.mjs +6 -0
- package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.cjs +11 -9
- package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.cts +1 -563
- package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.mts +1 -563
- package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.mjs +11 -9
- package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-snap-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-snap-notifications.d.cts +1 -1
- package/dist/NotificationServicesController/processors/process-snap-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/process-snap-notifications.d.mts +1 -1
- package/dist/NotificationServicesController/processors/process-snap-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/process-snap-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.cjs +21 -21
- package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.mjs +21 -21
- package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.cjs +19 -10
- package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.mjs +19 -10
- package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
- package/dist/NotificationServicesController/services/notification-config-cache.cjs +4 -4
- package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -1
- package/dist/NotificationServicesController/services/notification-config-cache.mjs +4 -4
- package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -1
- package/dist/NotificationServicesController/services/perp-notifications.cjs +2 -2
- package/dist/NotificationServicesController/services/perp-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/perp-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/perp-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/perp-notifications.mjs +2 -2
- package/dist/NotificationServicesController/services/perp-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.cjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts +2 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts +2 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.mjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/schema.cjs +2 -0
- package/dist/NotificationServicesController/types/notification-api/schema.cjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/schema.d.cts +23 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/schema.d.mts +23 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/schema.mjs +2 -0
- package/dist/NotificationServicesController/types/notification-api/schema.mjs.map +1 -1
- package/dist/NotificationServicesController/types/perps/schema.cjs +2 -0
- package/dist/NotificationServicesController/types/perps/schema.cjs.map +1 -1
- package/dist/NotificationServicesController/types/perps/schema.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/perps/schema.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/perps/schema.mjs +2 -0
- package/dist/NotificationServicesController/types/perps/schema.mjs.map +1 -1
- package/dist/NotificationServicesController/utils/isVersionInBounds.cjs.map +1 -1
- package/dist/NotificationServicesController/utils/isVersionInBounds.d.cts.map +1 -1
- package/dist/NotificationServicesController/utils/isVersionInBounds.d.mts.map +1 -1
- package/dist/NotificationServicesController/utils/isVersionInBounds.mjs.map +1 -1
- package/dist/NotificationServicesController/utils/should-auto-expire.cjs.map +1 -1
- package/dist/NotificationServicesController/utils/should-auto-expire.d.cts.map +1 -1
- package/dist/NotificationServicesController/utils/should-auto-expire.d.mts.map +1 -1
- package/dist/NotificationServicesController/utils/should-auto-expire.mjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +0 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +0 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +9 -24
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +9 -24
- package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.cjs +4 -4
- package/dist/NotificationServicesPushController/utils/get-notification-data.cjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.d.cts +2 -2
- package/dist/NotificationServicesPushController/utils/get-notification-data.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.d.mts +2 -2
- package/dist/NotificationServicesPushController/utils/get-notification-data.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.mjs +4 -4
- package/dist/NotificationServicesPushController/utils/get-notification-data.mjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +62 -71
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +9 -9
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +9 -9
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +62 -71
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
- package/dist/NotificationServicesPushController/web/push-utils.cjs +15 -7
- package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -1
- package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/web/push-utils.mjs +16 -8
- package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -1
- package/dist/shared/is-onchain-notification.cjs +3 -3
- package/dist/shared/is-onchain-notification.cjs.map +1 -1
- package/dist/shared/is-onchain-notification.d.cts +2 -2
- package/dist/shared/is-onchain-notification.d.cts.map +1 -1
- package/dist/shared/is-onchain-notification.d.mts +2 -2
- package/dist/shared/is-onchain-notification.d.mts.map +1 -1
- package/dist/shared/is-onchain-notification.mjs +3 -3
- package/dist/shared/is-onchain-notification.mjs.map +1 -1
- package/dist/shared/to-raw-notification.cjs.map +1 -1
- package/dist/shared/to-raw-notification.mjs.map +1 -1
- package/package.json +12 -25
- package/dist/NotificationServicesController/ui/constants.cjs +0 -75
- package/dist/NotificationServicesController/ui/constants.cjs.map +0 -1
- package/dist/NotificationServicesController/ui/constants.d.cts +0 -66
- package/dist/NotificationServicesController/ui/constants.d.cts.map +0 -1
- package/dist/NotificationServicesController/ui/constants.d.mts +0 -66
- package/dist/NotificationServicesController/ui/constants.d.mts.map +0 -1
- package/dist/NotificationServicesController/ui/constants.mjs +0 -71
- package/dist/NotificationServicesController/ui/constants.mjs.map +0 -1
- package/dist/NotificationServicesController/ui/index.cjs +0 -18
- package/dist/NotificationServicesController/ui/index.cjs.map +0 -1
- package/dist/NotificationServicesController/ui/index.d.cts +0 -2
- package/dist/NotificationServicesController/ui/index.d.cts.map +0 -1
- package/dist/NotificationServicesController/ui/index.d.mts +0 -2
- package/dist/NotificationServicesController/ui/index.d.mts.map +0 -1
- package/dist/NotificationServicesController/ui/index.mjs +0 -2
- package/dist/NotificationServicesController/ui/index.mjs.map +0 -1
- package/dist/NotificationServicesPushController/services/push/push-web.cjs +0 -145
- package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +0 -1
- package/dist/NotificationServicesPushController/services/push/push-web.d.cts +0 -34
- package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +0 -1
- package/dist/NotificationServicesPushController/services/push/push-web.d.mts +0 -34
- package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +0 -1
- package/dist/NotificationServicesPushController/services/push/push-web.mjs +0 -142
- package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +0 -1
- package/notification-services/ui/package.json +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [22.1.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Debounce `KeyringController:stateChange` handler to reduce redundant notification subscription calls during rapid account syncing ([#7980](https://github.com/MetaMask/core/pull/7980))
|
|
15
|
+
- Filter out Product Account announcements notifications older than 3 months ([#7884](https://github.com/MetaMask/core/pull/7884))
|
|
16
|
+
- Bump `@metamask/controller-utils` from `^11.18.0` to `^11.19.0` ([#7995](https://github.com/MetaMask/core/pull/7995))
|
|
17
|
+
- Bump `@metamask/profile-sync-controller` from `^27.1.0` to `^28.0.0` ([#8162](https://github.com/MetaMask/core/pull/8162))
|
|
18
|
+
|
|
19
|
+
## [22.0.0]
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
|
|
24
|
+
- Move peer dependencies for controller and service packages to direct dependencies ([#7209](https://github.com/MetaMask/core/pull/7209), [#7713](https://github.com/MetaMask/core/pull/7713), [#7849](https://github.com/MetaMask/core/pull/7849))
|
|
25
|
+
- The dependencies moved are:
|
|
26
|
+
- `@metamask/keyring-controller` (^25.1.0)
|
|
27
|
+
- `@metamask/profile-sync-controller` (^27.1.0)
|
|
28
|
+
- In clients, it is now possible for multiple versions of these packages to exist in the dependency tree.
|
|
29
|
+
- For example, this scenario would be valid: a client relies on `@metamask/controller-a` 1.0.0 and `@metamask/controller-b` 1.0.0, and `@metamask/controller-b` depends on `@metamask/controller-a` 1.1.0.
|
|
30
|
+
- Note, however, that the versions specified in the client's `package.json` always "win", and you are expected to keep them up to date so as not to break controller and service intercommunication.
|
|
31
|
+
- Modified background push utilities to handle more edgecases and not throw errors ([#7275](https://github.com/MetaMask/core/pull/7275))
|
|
32
|
+
- Bump `@metamask/controller-utils` from `^11.16.0` to `^11.18.0` ([#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583))
|
|
33
|
+
- Filter feature announcements older than 3 months ([#7884](https://github.com/MetaMask/core/pull/7884))
|
|
34
|
+
- Move notifications networks metadata to backend ([#7840](https://github.com/MetaMask/core/pull/7840))
|
|
35
|
+
|
|
36
|
+
### Removed
|
|
37
|
+
|
|
38
|
+
- **BREAKING:** Removed the `"./notification-services/ui"` subpath export from `package.json` ([#7840](https://github.com/MetaMask/core/pull/7840))
|
|
39
|
+
- Consumers that import from `@metamask/notification-services-controller/notification-services/ui` must switch to network config provided by the backend.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- Remove non-actionable internal `log.error` calls for expected silent-failure notification paths, while preserving thrown errors where propagation is required ([#7885](https://github.com/MetaMask/core/pull/7885))
|
|
44
|
+
- Fix `createOnChainTriggers` to preserve user preferences on notification re-subscriptions ([#7423](https://github.com/MetaMask/core/pull/7423))
|
|
45
|
+
- Previously, `isFeatureAnnouncementsEnabled` was unconditionally set to `true` on every re-subscription, overriding user preferences
|
|
46
|
+
- Now, existing preferences are preserved when `isNotificationServicesEnabled` is already `true`
|
|
47
|
+
|
|
10
48
|
## [21.0.0]
|
|
11
49
|
|
|
12
50
|
### Changed
|
|
@@ -629,7 +667,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
629
667
|
|
|
630
668
|
- Initial release
|
|
631
669
|
|
|
632
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@
|
|
670
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@22.1.0...HEAD
|
|
671
|
+
[22.1.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@22.0.0...@metamask/notification-services-controller@22.1.0
|
|
672
|
+
[22.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@21.0.0...@metamask/notification-services-controller@22.0.0
|
|
633
673
|
[21.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@20.0.0...@metamask/notification-services-controller@21.0.0
|
|
634
674
|
[20.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@19.0.0...@metamask/notification-services-controller@20.0.0
|
|
635
675
|
[19.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@18.3.1...@metamask/notification-services-controller@19.0.0
|
|
@@ -15,11 +15,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
};
|
|
16
16
|
var _NotificationServicesController_instances, _NotificationServicesController_keyringController, _NotificationServicesController_auth, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_locale, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_env, _NotificationServicesController_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth, _NotificationServicesController_getBearerToken, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.defaultState = void 0;
|
|
18
|
+
exports.defaultState = exports.ACCOUNTS_UPDATE_DEBOUNCE_TIME_MS = void 0;
|
|
19
19
|
const base_controller_1 = require("@metamask/base-controller");
|
|
20
20
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
21
21
|
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
22
22
|
const utils_1 = require("@metamask/utils");
|
|
23
|
+
const lodash_1 = require("lodash");
|
|
23
24
|
const loglevel_1 = __importDefault(require("loglevel"));
|
|
24
25
|
const notification_schema_1 = require("./constants/notification-schema.cjs");
|
|
25
26
|
const process_notifications_1 = require("./processors/process-notifications.cjs");
|
|
@@ -28,6 +29,7 @@ const feature_announcements_1 = require("./services/feature-announcements.cjs");
|
|
|
28
29
|
const perp_notifications_1 = require("./services/perp-notifications.cjs");
|
|
29
30
|
// Unique name for the controller
|
|
30
31
|
const controllerName = 'NotificationServicesController';
|
|
32
|
+
exports.ACCOUNTS_UPDATE_DEBOUNCE_TIME_MS = 1000;
|
|
31
33
|
const metadata = {
|
|
32
34
|
subscriptionAccountsSeen: {
|
|
33
35
|
includeInStateLogs: true,
|
|
@@ -168,16 +170,16 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
168
170
|
try {
|
|
169
171
|
await this.messenger.call('NotificationServicesPushController:enablePushNotifications', addresses);
|
|
170
172
|
}
|
|
171
|
-
catch
|
|
172
|
-
|
|
173
|
+
catch {
|
|
174
|
+
// Do nothing, failing silently.
|
|
173
175
|
}
|
|
174
176
|
},
|
|
175
177
|
disablePushNotifications: async () => {
|
|
176
178
|
try {
|
|
177
179
|
await this.messenger.call('NotificationServicesPushController:disablePushNotifications');
|
|
178
180
|
}
|
|
179
|
-
catch
|
|
180
|
-
|
|
181
|
+
catch {
|
|
182
|
+
// Do nothing, failing silently.
|
|
181
183
|
}
|
|
182
184
|
},
|
|
183
185
|
subscribe: () => {
|
|
@@ -216,7 +218,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
216
218
|
isNotificationAccountsSetup: false,
|
|
217
219
|
getNotificationAccounts: () => {
|
|
218
220
|
const { keyrings } = this.messenger.call('KeyringController:getState');
|
|
219
|
-
const firstHDKeyring = keyrings.find((
|
|
221
|
+
const firstHDKeyring = keyrings.find((keyring) => keyring.type === keyring_controller_1.KeyringTypes.hd.toString());
|
|
220
222
|
const keyringAccounts = firstHDKeyring?.accounts ?? null;
|
|
221
223
|
return keyringAccounts;
|
|
222
224
|
},
|
|
@@ -236,8 +238,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
236
238
|
};
|
|
237
239
|
}
|
|
238
240
|
const accounts = nonChecksumAccounts
|
|
239
|
-
.map((
|
|
240
|
-
.filter((
|
|
241
|
+
.map((address) => (0, controller_utils_1.toChecksumHexAddress)(address))
|
|
242
|
+
.filter((address) => (0, controller_utils_1.isValidHexAddress)(address));
|
|
241
243
|
const currentAccountsSet = new Set(accounts);
|
|
242
244
|
const prevAccountsSet = new Set(this.state.subscriptionAccountsSeen);
|
|
243
245
|
// Invalid value you cannot have zero accounts
|
|
@@ -250,8 +252,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
250
252
|
};
|
|
251
253
|
}
|
|
252
254
|
// Calculate added and removed addresses
|
|
253
|
-
const accountsAdded = accounts.filter((
|
|
254
|
-
const accountsRemoved = [...prevAccountsSet.values()].filter((
|
|
255
|
+
const accountsAdded = accounts.filter((account) => !prevAccountsSet.has(account));
|
|
256
|
+
const accountsRemoved = [...prevAccountsSet.values()].filter((account) => !currentAccountsSet.has(account));
|
|
255
257
|
// Update accounts seen
|
|
256
258
|
this.update((state) => {
|
|
257
259
|
state.subscriptionAccountsSeen = [...currentAccountsSet];
|
|
@@ -278,7 +280,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
278
280
|
* And call effects to subscribe/unsubscribe to notifications.
|
|
279
281
|
*/
|
|
280
282
|
subscribe: () => {
|
|
281
|
-
|
|
283
|
+
const debouncedUpdateAccountNotifications = (0, lodash_1.debounce)(async (totalAccounts, prevTotalAccounts) => {
|
|
282
284
|
const hasTotalAccountsChanged = totalAccounts !== prevTotalAccounts;
|
|
283
285
|
if (!this.state.isNotificationServicesEnabled ||
|
|
284
286
|
!hasTotalAccountsChanged) {
|
|
@@ -293,7 +295,11 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
293
295
|
promises.push(this.disableAccounts(accountsRemoved));
|
|
294
296
|
}
|
|
295
297
|
await Promise.allSettled(promises);
|
|
296
|
-
},
|
|
298
|
+
}, exports.ACCOUNTS_UPDATE_DEBOUNCE_TIME_MS);
|
|
299
|
+
this.messenger.subscribe('KeyringController:stateChange',
|
|
300
|
+
// Using void return for async callback - result is intentionally ignored
|
|
301
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
302
|
+
debouncedUpdateAccountNotifications, (state) => {
|
|
297
303
|
return (state?.keyrings?.flatMap?.((keyring) => keyring.accounts)?.length ??
|
|
298
304
|
0);
|
|
299
305
|
});
|
|
@@ -328,14 +334,14 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
328
334
|
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
329
335
|
const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
330
336
|
const addresses = addressesWithNotifications
|
|
331
|
-
.filter((
|
|
332
|
-
.map((
|
|
337
|
+
.filter((addressConfig) => Boolean(addressConfig.enabled))
|
|
338
|
+
.map((addressConfig) => addressConfig.address);
|
|
333
339
|
if (addresses.length > 0) {
|
|
334
340
|
await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(addresses);
|
|
335
341
|
}
|
|
336
342
|
}
|
|
337
|
-
catch
|
|
338
|
-
|
|
343
|
+
catch {
|
|
344
|
+
// Do nothing, failing silently.
|
|
339
345
|
}
|
|
340
346
|
}
|
|
341
347
|
/**
|
|
@@ -375,12 +381,12 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
375
381
|
*/
|
|
376
382
|
async setFeatureAnnouncementsEnabled(featureAnnouncementsEnabled) {
|
|
377
383
|
try {
|
|
378
|
-
this.update((
|
|
379
|
-
|
|
384
|
+
this.update((state) => {
|
|
385
|
+
state.isFeatureAnnouncementsEnabled = featureAnnouncementsEnabled;
|
|
380
386
|
});
|
|
381
387
|
}
|
|
382
|
-
catch (
|
|
383
|
-
loglevel_1.default.error('Unable to toggle feature announcements',
|
|
388
|
+
catch (error) {
|
|
389
|
+
loglevel_1.default.error('Unable to toggle feature announcements', error);
|
|
384
390
|
throw new Error('Unable to toggle feature announcements');
|
|
385
391
|
}
|
|
386
392
|
}
|
|
@@ -405,8 +411,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
405
411
|
// Notifications API can return array with addresses set to false
|
|
406
412
|
// So assert that at least one address is enabled
|
|
407
413
|
let accountsWithNotifications = addressesWithNotifications
|
|
408
|
-
.filter((
|
|
409
|
-
.map((
|
|
414
|
+
.filter((addressConfig) => Boolean(addressConfig.enabled))
|
|
415
|
+
.map((addressConfig) => addressConfig.address);
|
|
410
416
|
// 2. Enable Notifications (if no accounts subscribed or we are resetting)
|
|
411
417
|
if (accountsWithNotifications.length === 0 || opts?.resetNotifications) {
|
|
412
418
|
await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
@@ -420,13 +426,21 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
420
426
|
});
|
|
421
427
|
// Update the state of the controller
|
|
422
428
|
this.update((state) => {
|
|
423
|
-
|
|
424
|
-
state.
|
|
425
|
-
|
|
429
|
+
// User is re-subscribing (daily resub to get latest notifications)
|
|
430
|
+
if (state.isNotificationServicesEnabled) {
|
|
431
|
+
// Keep their existing preferences on re-subscribe
|
|
432
|
+
// No state updates needed - preserving user's current settings
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
// User is turning on notifications from a disabled state
|
|
436
|
+
state.isNotificationServicesEnabled = true;
|
|
437
|
+
state.isFeatureAnnouncementsEnabled = true;
|
|
438
|
+
state.isMetamaskNotificationsFeatureSeen = true;
|
|
439
|
+
}
|
|
426
440
|
});
|
|
427
441
|
}
|
|
428
|
-
catch (
|
|
429
|
-
loglevel_1.default.error('Failed to create On Chain triggers',
|
|
442
|
+
catch (error) {
|
|
443
|
+
loglevel_1.default.error('Failed to create On Chain triggers', error);
|
|
430
444
|
throw new Error('Failed to create On Chain triggers');
|
|
431
445
|
}
|
|
432
446
|
finally {
|
|
@@ -445,8 +459,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
445
459
|
await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_enableAuth).call(this);
|
|
446
460
|
await this.createOnChainTriggers();
|
|
447
461
|
}
|
|
448
|
-
catch (
|
|
449
|
-
loglevel_1.default.error('Unable to enable notifications',
|
|
462
|
+
catch (error) {
|
|
463
|
+
loglevel_1.default.error('Unable to enable notifications', error);
|
|
450
464
|
throw new Error('Unable to enable notifications');
|
|
451
465
|
}
|
|
452
466
|
finally {
|
|
@@ -503,8 +517,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
503
517
|
// Delete these UUIDs (Mutates User Storage)
|
|
504
518
|
await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: false })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
505
519
|
}
|
|
506
|
-
catch
|
|
507
|
-
loglevel_1.default.error('Failed to delete OnChain triggers', err);
|
|
520
|
+
catch {
|
|
508
521
|
throw new Error('Failed to delete OnChain triggers');
|
|
509
522
|
}
|
|
510
523
|
finally {
|
|
@@ -532,8 +545,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
532
545
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
533
546
|
await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
|
|
534
547
|
}
|
|
535
|
-
catch (
|
|
536
|
-
loglevel_1.default.error('Failed to update OnChain triggers',
|
|
548
|
+
catch (error) {
|
|
549
|
+
loglevel_1.default.error('Failed to update OnChain triggers', error);
|
|
537
550
|
throw new Error('Failed to update OnChain triggers');
|
|
538
551
|
}
|
|
539
552
|
finally {
|
|
@@ -567,8 +580,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
567
580
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
568
581
|
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
569
582
|
const addressesWithNotifications = (await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f")))
|
|
570
|
-
.filter((
|
|
571
|
-
.map((
|
|
583
|
+
.filter((addressConfig) => Boolean(addressConfig.enabled))
|
|
584
|
+
.map((addressConfig) => addressConfig.address);
|
|
572
585
|
const notifications = await (0, api_notifications_1.getAPINotifications)(bearerToken, addressesWithNotifications, __classPrivateFieldGet(this, _NotificationServicesController_locale, "f").call(this), __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform, __classPrivateFieldGet(this, _NotificationServicesController_env, "f")).catch(() => []);
|
|
573
586
|
rawOnChainNotifications.push(...notifications);
|
|
574
587
|
}
|
|
@@ -587,7 +600,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
587
600
|
...snapNotifications,
|
|
588
601
|
];
|
|
589
602
|
// Sort Notifications
|
|
590
|
-
metamaskNotifications.sort((
|
|
603
|
+
metamaskNotifications.sort((notificationA, notificationB) => new Date(notificationB.createdAt).getTime() -
|
|
604
|
+
new Date(notificationA.createdAt).getTime());
|
|
591
605
|
// Update State
|
|
592
606
|
this.update((state) => {
|
|
593
607
|
state.metamaskNotificationsList = metamaskNotifications;
|
|
@@ -596,9 +610,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
596
610
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsFetchingMetamaskNotifications).call(this, false);
|
|
597
611
|
return metamaskNotifications;
|
|
598
612
|
}
|
|
599
|
-
catch (
|
|
613
|
+
catch (error) {
|
|
600
614
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsFetchingMetamaskNotifications).call(this, false);
|
|
601
|
-
loglevel_1.default.error('Failed to fetch notifications',
|
|
615
|
+
loglevel_1.default.error('Failed to fetch notifications', error);
|
|
602
616
|
throw new Error('Failed to fetch notifications');
|
|
603
617
|
}
|
|
604
618
|
}
|
|
@@ -694,8 +708,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
694
708
|
snapNotificationIds = snapNotifications.map((notification) => notification.id);
|
|
695
709
|
}
|
|
696
710
|
}
|
|
697
|
-
catch (
|
|
698
|
-
loglevel_1.default.warn('Something failed when marking notifications as read',
|
|
711
|
+
catch (error) {
|
|
712
|
+
loglevel_1.default.warn('Something failed when marking notifications as read', error);
|
|
699
713
|
}
|
|
700
714
|
// Update the state (state is also used on counter & badge)
|
|
701
715
|
this.update((state) => {
|
|
@@ -732,13 +746,13 @@ class NotificationServicesController extends base_controller_1.BaseController {
|
|
|
732
746
|
* @returns A promise that resolves when the notification list has been successfully updated.
|
|
733
747
|
*/
|
|
734
748
|
async updateMetamaskNotificationsList(notification) {
|
|
735
|
-
if (this.state.metamaskNotificationsList.some((
|
|
749
|
+
if (this.state.metamaskNotificationsList.some((existingNotification) => existingNotification.id === notification.id)) {
|
|
736
750
|
return;
|
|
737
751
|
}
|
|
738
752
|
const processedNotification = (0, process_notifications_1.safeProcessNotification)(notification);
|
|
739
753
|
if (processedNotification) {
|
|
740
754
|
this.update((state) => {
|
|
741
|
-
const existingNotificationIds = new Set(state.metamaskNotificationsList.map((
|
|
755
|
+
const existingNotificationIds = new Set(state.metamaskNotificationsList.map((existingNotification) => existingNotification.id));
|
|
742
756
|
// Add the new notification only if its ID is not already present in the list
|
|
743
757
|
if (!existingNotificationIds.has(processedNotification.id)) {
|
|
744
758
|
state.metamaskNotificationsList = [
|