@metamask/notification-services-controller 18.3.1 → 20.0.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 +47 -68
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +8 -7
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +8 -7
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +47 -45
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.cjs +4 -14
- package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.d.cts +3 -13
- package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.d.mts +3 -13
- package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.mjs +3 -13
- package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs +427 -529
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts +20 -50
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts +20 -50
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs +424 -521
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.cjs +5 -5
- package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts +2 -2
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts +2 -2
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.mjs +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
- package/dist/NotificationServicesController/processors/index.cjs +1 -1
- package/dist/NotificationServicesController/processors/index.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/index.d.cts +1 -1
- package/dist/NotificationServicesController/processors/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/index.d.mts +1 -1
- package/dist/NotificationServicesController/processors/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/index.mjs +1 -1
- package/dist/NotificationServicesController/processors/index.mjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-api-notifications.cjs +22 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.cjs.map +1 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.d.cts +10 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.d.cts.map +1 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.d.mts +10 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.d.mts.map +1 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.mjs +18 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.mjs.map +1 -0
- package/dist/NotificationServicesController/processors/process-feature-announcement.cjs +2 -7
- package/dist/NotificationServicesController/processors/process-feature-announcement.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-feature-announcement.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/process-feature-announcement.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/process-feature-announcement.mjs +1 -6
- package/dist/NotificationServicesController/processors/process-feature-announcement.mjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.cjs +3 -3
- package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.cts +398 -458
- package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.mts +398 -458
- package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.mjs +4 -4
- package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/services/{onchain-notifications.cjs → api-notifications.cjs} +28 -15
- package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -0
- package/dist/NotificationServicesController/services/{onchain-notifications.d.cts → api-notifications.d.cts} +9 -7
- package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -0
- package/dist/NotificationServicesController/services/{onchain-notifications.d.mts → api-notifications.d.mts} +9 -7
- package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -0
- package/dist/NotificationServicesController/services/{onchain-notifications.mjs → api-notifications.mjs} +26 -13
- package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -0
- package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
- package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -1
- package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -1
- package/dist/NotificationServicesController/services/perp-notifications.cjs +0 -1
- 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 +0 -1
- package/dist/NotificationServicesController/services/perp-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/types/index.cjs.map +1 -1
- package/dist/NotificationServicesController/types/index.d.cts +1 -1
- package/dist/NotificationServicesController/types/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/index.d.mts +1 -1
- package/dist/NotificationServicesController/types/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/index.mjs.map +1 -1
- package/dist/NotificationServicesController/types/notification/notification.cjs.map +1 -1
- package/dist/NotificationServicesController/types/notification/notification.d.cts +3 -11
- package/dist/NotificationServicesController/types/notification/notification.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/notification/notification.d.mts +3 -11
- package/dist/NotificationServicesController/types/notification/notification.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/notification/notification.mjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/index.cjs.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/index.d.cts +3 -0
- package/dist/NotificationServicesController/types/notification-api/index.d.cts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/index.d.mts +3 -0
- package/dist/NotificationServicesController/types/notification-api/index.d.mts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/index.mjs.map +1 -0
- package/dist/NotificationServicesController/types/{on-chain-notification/on-chain-notification.cjs → notification-api/notification-api.cjs} +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.cjs.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts +64 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts +64 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.mjs +2 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.mjs.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/schema.cjs.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.cts +365 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.cts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.mts +365 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.mts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/schema.mjs.map +1 -0
- package/dist/NotificationServicesController/ui/constants.d.cts +27 -27
- package/dist/NotificationServicesController/ui/constants.d.mts +27 -27
- package/dist/NotificationServicesController/utils/isVersionInBounds.cjs.map +1 -1
- package/dist/NotificationServicesController/utils/isVersionInBounds.mjs.map +1 -1
- package/dist/NotificationServicesController/utils/should-auto-expire.cjs +12 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.cjs.map +1 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.d.cts +2 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.d.cts.map +1 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.d.mts +2 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.d.mts.map +1 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.mjs +8 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.mjs.map +1 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +8 -8
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +4 -4
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +4 -4
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +8 -8
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.cjs +5 -2
- package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.mjs +6 -3
- package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.cjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.mjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +51 -43
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +4 -2
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +4 -2
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +51 -43
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
- package/dist/NotificationServicesPushController/web/push-utils.cjs +5 -2
- 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 +6 -3
- package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -1
- package/dist/shared/is-onchain-notification.cjs +1 -2
- package/dist/shared/is-onchain-notification.cjs.map +1 -1
- package/dist/shared/is-onchain-notification.d.cts.map +1 -1
- package/dist/shared/is-onchain-notification.d.mts.map +1 -1
- package/dist/shared/is-onchain-notification.mjs +1 -2
- package/dist/shared/is-onchain-notification.mjs.map +1 -1
- package/dist/shared/to-raw-notification.cjs +22 -6
- package/dist/shared/to-raw-notification.cjs.map +1 -1
- package/dist/shared/to-raw-notification.d.cts +2 -2
- package/dist/shared/to-raw-notification.d.cts.map +1 -1
- package/dist/shared/to-raw-notification.d.mts +2 -2
- package/dist/shared/to-raw-notification.d.mts.map +1 -1
- package/dist/shared/to-raw-notification.mjs +20 -4
- package/dist/shared/to-raw-notification.mjs.map +1 -1
- package/package.json +11 -8
- package/dist/NotificationServicesController/processors/process-onchain-notifications.cjs +0 -19
- package/dist/NotificationServicesController/processors/process-onchain-notifications.cjs.map +0 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.d.cts +0 -10
- package/dist/NotificationServicesController/processors/process-onchain-notifications.d.cts.map +0 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.d.mts +0 -10
- package/dist/NotificationServicesController/processors/process-onchain-notifications.d.mts.map +0 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs +0 -15
- package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs.map +0 -1
- package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +0 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +0 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +0 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/index.cjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts +0 -2
- package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts +0 -2
- package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/index.mjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.cjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts +0 -49
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts +0 -49
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.mjs +0 -2
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.mjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/schema.cjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/schema.d.cts +0 -681
- package/dist/NotificationServicesController/types/on-chain-notification/schema.d.cts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/schema.d.mts +0 -681
- package/dist/NotificationServicesController/types/on-chain-notification/schema.d.mts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/schema.mjs.map +0 -1
- /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/index.cjs +0 -0
- /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/index.mjs +0 -0
- /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/schema.cjs +0 -0
- /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/schema.mjs +0 -0
|
@@ -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_featureAnnouncementEnv, _NotificationServicesController_registerMessageHandlers, _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_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth, _NotificationServicesController_getBearerToken, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
|
|
13
13
|
function $importDefault(module) {
|
|
14
14
|
if (module?.__esModule) {
|
|
15
15
|
return module.default;
|
|
@@ -24,8 +24,8 @@ import $log from "loglevel";
|
|
|
24
24
|
const log = $importDefault($log);
|
|
25
25
|
import { TRIGGER_TYPES } from "./constants/notification-schema.mjs";
|
|
26
26
|
import { processAndFilterNotifications, safeProcessNotification } from "./processors/process-notifications.mjs";
|
|
27
|
-
import
|
|
28
|
-
import
|
|
27
|
+
import { getAPINotifications, getNotificationsApiConfigCached, markNotificationsAsRead, updateOnChainNotifications } from "./services/api-notifications.mjs";
|
|
28
|
+
import { getFeatureAnnouncementNotifications } from "./services/feature-announcements.mjs";
|
|
29
29
|
import { createPerpOrderNotification } from "./services/perp-notifications.mjs";
|
|
30
30
|
// Unique name for the controller
|
|
31
31
|
const controllerName = 'NotificationServicesController';
|
|
@@ -33,61 +33,61 @@ const metadata = {
|
|
|
33
33
|
subscriptionAccountsSeen: {
|
|
34
34
|
includeInStateLogs: true,
|
|
35
35
|
persist: true,
|
|
36
|
-
|
|
36
|
+
includeInDebugSnapshot: true,
|
|
37
37
|
usedInUi: true,
|
|
38
38
|
},
|
|
39
39
|
isMetamaskNotificationsFeatureSeen: {
|
|
40
40
|
includeInStateLogs: true,
|
|
41
41
|
persist: true,
|
|
42
|
-
|
|
42
|
+
includeInDebugSnapshot: false,
|
|
43
43
|
usedInUi: true,
|
|
44
44
|
},
|
|
45
45
|
isNotificationServicesEnabled: {
|
|
46
46
|
includeInStateLogs: true,
|
|
47
47
|
persist: true,
|
|
48
|
-
|
|
48
|
+
includeInDebugSnapshot: false,
|
|
49
49
|
usedInUi: true,
|
|
50
50
|
},
|
|
51
51
|
isFeatureAnnouncementsEnabled: {
|
|
52
52
|
includeInStateLogs: true,
|
|
53
53
|
persist: true,
|
|
54
|
-
|
|
54
|
+
includeInDebugSnapshot: false,
|
|
55
55
|
usedInUi: true,
|
|
56
56
|
},
|
|
57
57
|
metamaskNotificationsList: {
|
|
58
58
|
includeInStateLogs: true,
|
|
59
59
|
persist: true,
|
|
60
|
-
|
|
60
|
+
includeInDebugSnapshot: true,
|
|
61
61
|
usedInUi: true,
|
|
62
62
|
},
|
|
63
63
|
metamaskNotificationsReadList: {
|
|
64
64
|
includeInStateLogs: false,
|
|
65
65
|
persist: true,
|
|
66
|
-
|
|
66
|
+
includeInDebugSnapshot: true,
|
|
67
67
|
usedInUi: true,
|
|
68
68
|
},
|
|
69
69
|
isUpdatingMetamaskNotifications: {
|
|
70
70
|
includeInStateLogs: false,
|
|
71
71
|
persist: false,
|
|
72
|
-
|
|
72
|
+
includeInDebugSnapshot: false,
|
|
73
73
|
usedInUi: true,
|
|
74
74
|
},
|
|
75
75
|
isFetchingMetamaskNotifications: {
|
|
76
76
|
includeInStateLogs: false,
|
|
77
77
|
persist: false,
|
|
78
|
-
|
|
78
|
+
includeInDebugSnapshot: false,
|
|
79
79
|
usedInUi: true,
|
|
80
80
|
},
|
|
81
81
|
isUpdatingMetamaskNotificationsAccount: {
|
|
82
82
|
includeInStateLogs: false,
|
|
83
83
|
persist: false,
|
|
84
|
-
|
|
84
|
+
includeInDebugSnapshot: false,
|
|
85
85
|
usedInUi: true,
|
|
86
86
|
},
|
|
87
87
|
isCheckingAccountsPresence: {
|
|
88
88
|
includeInStateLogs: false,
|
|
89
89
|
persist: false,
|
|
90
|
-
|
|
90
|
+
includeInDebugSnapshot: false,
|
|
91
91
|
usedInUi: true,
|
|
92
92
|
},
|
|
93
93
|
};
|
|
@@ -118,7 +118,7 @@ class NotificationServicesController extends BaseController {
|
|
|
118
118
|
* @param args.state - Initial state to set on this controller.
|
|
119
119
|
* @param args.env - environment variables for a given controller.
|
|
120
120
|
* @param args.env.featureAnnouncements - env variables for feature announcements.
|
|
121
|
-
* @param args.env.
|
|
121
|
+
* @param args.env.locale - users locale for better dynamic server notifications
|
|
122
122
|
*/
|
|
123
123
|
constructor({ messenger, state, env, }) {
|
|
124
124
|
super({
|
|
@@ -131,29 +131,29 @@ class NotificationServicesController extends BaseController {
|
|
|
131
131
|
_NotificationServicesController_keyringController.set(this, {
|
|
132
132
|
isUnlocked: false,
|
|
133
133
|
setupLockedStateSubscriptions: (onUnlock) => {
|
|
134
|
-
const { isUnlocked } = this.
|
|
134
|
+
const { isUnlocked } = this.messenger.call('KeyringController:getState');
|
|
135
135
|
__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = isUnlocked;
|
|
136
|
-
this.
|
|
136
|
+
this.messenger.subscribe('KeyringController:unlock', () => {
|
|
137
137
|
__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = true;
|
|
138
138
|
// messaging system cannot await promises
|
|
139
139
|
// we don't need to wait for a result on this.
|
|
140
140
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
141
141
|
onUnlock();
|
|
142
142
|
});
|
|
143
|
-
this.
|
|
143
|
+
this.messenger.subscribe('KeyringController:lock', () => {
|
|
144
144
|
__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = false;
|
|
145
145
|
});
|
|
146
146
|
},
|
|
147
147
|
});
|
|
148
148
|
_NotificationServicesController_auth.set(this, {
|
|
149
149
|
getBearerToken: async () => {
|
|
150
|
-
return await this.
|
|
150
|
+
return await this.messenger.call('AuthenticationController:getBearerToken');
|
|
151
151
|
},
|
|
152
152
|
isSignedIn: () => {
|
|
153
|
-
return this.
|
|
153
|
+
return this.messenger.call('AuthenticationController:isSignedIn');
|
|
154
154
|
},
|
|
155
155
|
signIn: async () => {
|
|
156
|
-
return await this.
|
|
156
|
+
return await this.messenger.call('AuthenticationController:performSignIn');
|
|
157
157
|
},
|
|
158
158
|
});
|
|
159
159
|
_NotificationServicesController_pushNotifications.set(this, {
|
|
@@ -162,11 +162,11 @@ class NotificationServicesController extends BaseController {
|
|
|
162
162
|
// To ensure we subscribe to the most up-to-date notifications
|
|
163
163
|
isSetup: false,
|
|
164
164
|
subscribeToPushNotifications: async () => {
|
|
165
|
-
await this.
|
|
165
|
+
await this.messenger.call('NotificationServicesPushController:subscribeToPushNotifications');
|
|
166
166
|
},
|
|
167
167
|
enablePushNotifications: async (addresses) => {
|
|
168
168
|
try {
|
|
169
|
-
await this.
|
|
169
|
+
await this.messenger.call('NotificationServicesPushController:enablePushNotifications', addresses);
|
|
170
170
|
}
|
|
171
171
|
catch (e) {
|
|
172
172
|
log.error('Silently failed to enable push notifications', e);
|
|
@@ -174,14 +174,14 @@ class NotificationServicesController extends BaseController {
|
|
|
174
174
|
},
|
|
175
175
|
disablePushNotifications: async () => {
|
|
176
176
|
try {
|
|
177
|
-
await this.
|
|
177
|
+
await this.messenger.call('NotificationServicesPushController:disablePushNotifications');
|
|
178
178
|
}
|
|
179
179
|
catch (e) {
|
|
180
180
|
log.error('Silently failed to disable push notifications', e);
|
|
181
181
|
}
|
|
182
182
|
},
|
|
183
183
|
subscribe: () => {
|
|
184
|
-
this.
|
|
184
|
+
this.messenger.subscribe('NotificationServicesPushController:onNewNotifications', (notification) => {
|
|
185
185
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
186
186
|
this.updateMetamaskNotificationsList(notification);
|
|
187
187
|
});
|
|
@@ -215,7 +215,7 @@ class NotificationServicesController extends BaseController {
|
|
|
215
215
|
// Flag to ensure we only setup once
|
|
216
216
|
isNotificationAccountsSetup: false,
|
|
217
217
|
getNotificationAccounts: () => {
|
|
218
|
-
const { keyrings } = this.
|
|
218
|
+
const { keyrings } = this.messenger.call('KeyringController:getState');
|
|
219
219
|
const firstHDKeyring = keyrings.find((k) => k.type === KeyringTypes.hd.toString());
|
|
220
220
|
const keyringAccounts = firstHDKeyring?.accounts ?? null;
|
|
221
221
|
return keyringAccounts;
|
|
@@ -278,7 +278,7 @@ class NotificationServicesController extends BaseController {
|
|
|
278
278
|
* And call effects to subscribe/unsubscribe to notifications.
|
|
279
279
|
*/
|
|
280
280
|
subscribe: () => {
|
|
281
|
-
this.
|
|
281
|
+
this.messenger.subscribe('KeyringController:stateChange', async (totalAccounts, prevTotalAccounts) => {
|
|
282
282
|
const hasTotalAccountsChanged = totalAccounts !== prevTotalAccounts;
|
|
283
283
|
if (!this.state.isNotificationServicesEnabled ||
|
|
284
284
|
!hasTotalAccountsChanged) {
|
|
@@ -299,8 +299,10 @@ class NotificationServicesController extends BaseController {
|
|
|
299
299
|
});
|
|
300
300
|
},
|
|
301
301
|
});
|
|
302
|
+
_NotificationServicesController_locale.set(this, void 0);
|
|
302
303
|
_NotificationServicesController_featureAnnouncementEnv.set(this, void 0);
|
|
303
304
|
__classPrivateFieldSet(this, _NotificationServicesController_featureAnnouncementEnv, env.featureAnnouncements, "f");
|
|
305
|
+
__classPrivateFieldSet(this, _NotificationServicesController_locale, env.locale ?? (() => 'en'), "f");
|
|
304
306
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerMessageHandlers).call(this);
|
|
305
307
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_clearLoadingStates).call(this);
|
|
306
308
|
}
|
|
@@ -322,7 +324,7 @@ class NotificationServicesController extends BaseController {
|
|
|
322
324
|
try {
|
|
323
325
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
324
326
|
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
325
|
-
const addressesWithNotifications = await
|
|
327
|
+
const addressesWithNotifications = await getNotificationsApiConfigCached(bearerToken, accounts);
|
|
326
328
|
const addresses = addressesWithNotifications
|
|
327
329
|
.filter((a) => Boolean(a.enabled))
|
|
328
330
|
.map((a) => a.address);
|
|
@@ -345,7 +347,7 @@ class NotificationServicesController extends BaseController {
|
|
|
345
347
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsCheckingAccountsPresence).call(this, true);
|
|
346
348
|
// Retrieve user storage
|
|
347
349
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
348
|
-
const addressesWithNotifications = await
|
|
350
|
+
const addressesWithNotifications = await getNotificationsApiConfigCached(bearerToken, accounts);
|
|
349
351
|
const result = {};
|
|
350
352
|
addressesWithNotifications.forEach((a) => {
|
|
351
353
|
result[a.address] = a.enabled;
|
|
@@ -397,7 +399,7 @@ class NotificationServicesController extends BaseController {
|
|
|
397
399
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
398
400
|
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
399
401
|
// 1. See if has enabled notifications before
|
|
400
|
-
const addressesWithNotifications = await
|
|
402
|
+
const addressesWithNotifications = await getNotificationsApiConfigCached(bearerToken, accounts);
|
|
401
403
|
// Notifications API can return array with addresses set to false
|
|
402
404
|
// So assert that at least one address is enabled
|
|
403
405
|
let accountsWithNotifications = addressesWithNotifications
|
|
@@ -405,7 +407,7 @@ class NotificationServicesController extends BaseController {
|
|
|
405
407
|
.map((a) => a.address);
|
|
406
408
|
// 2. Enable Notifications (if no accounts subscribed or we are resetting)
|
|
407
409
|
if (accountsWithNotifications.length === 0 || opts?.resetNotifications) {
|
|
408
|
-
await
|
|
410
|
+
await updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })));
|
|
409
411
|
accountsWithNotifications = accounts;
|
|
410
412
|
}
|
|
411
413
|
// 3. Lazily enable push notifications (FCM may take some time, so keeps UI unblocked)
|
|
@@ -497,7 +499,7 @@ class NotificationServicesController extends BaseController {
|
|
|
497
499
|
// Get and Validate BearerToken and User Storage Key
|
|
498
500
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
499
501
|
// Delete these UUIDs (Mutates User Storage)
|
|
500
|
-
await
|
|
502
|
+
await updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: false })));
|
|
501
503
|
}
|
|
502
504
|
catch (err) {
|
|
503
505
|
log.error('Failed to delete OnChain triggers', err);
|
|
@@ -526,7 +528,7 @@ class NotificationServicesController extends BaseController {
|
|
|
526
528
|
try {
|
|
527
529
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
|
|
528
530
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
529
|
-
await
|
|
531
|
+
await updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })));
|
|
530
532
|
}
|
|
531
533
|
catch (err) {
|
|
532
534
|
log.error('Failed to update OnChain triggers', err);
|
|
@@ -554,7 +556,7 @@ class NotificationServicesController extends BaseController {
|
|
|
554
556
|
const isGlobalNotifsEnabled = this.state.isNotificationServicesEnabled;
|
|
555
557
|
// Raw Feature Notifications
|
|
556
558
|
const rawAnnouncements = isGlobalNotifsEnabled && this.state.isFeatureAnnouncementsEnabled
|
|
557
|
-
? await
|
|
559
|
+
? await getFeatureAnnouncementNotifications(__classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f"), previewToken).catch(() => [])
|
|
558
560
|
: [];
|
|
559
561
|
// Raw On Chain Notifications
|
|
560
562
|
const rawOnChainNotifications = [];
|
|
@@ -562,10 +564,10 @@ class NotificationServicesController extends BaseController {
|
|
|
562
564
|
try {
|
|
563
565
|
const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
|
|
564
566
|
const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
|
|
565
|
-
const addressesWithNotifications = (await
|
|
567
|
+
const addressesWithNotifications = (await getNotificationsApiConfigCached(bearerToken, accounts))
|
|
566
568
|
.filter((a) => Boolean(a.enabled))
|
|
567
569
|
.map((a) => a.address);
|
|
568
|
-
const notifications = await
|
|
570
|
+
const notifications = await getAPINotifications(bearerToken, addressesWithNotifications, __classPrivateFieldGet(this, _NotificationServicesController_locale, "f").call(this), __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform).catch(() => []);
|
|
569
571
|
rawOnChainNotifications.push(...notifications);
|
|
570
572
|
}
|
|
571
573
|
catch {
|
|
@@ -588,7 +590,7 @@ class NotificationServicesController extends BaseController {
|
|
|
588
590
|
this.update((state) => {
|
|
589
591
|
state.metamaskNotificationsList = metamaskNotifications;
|
|
590
592
|
});
|
|
591
|
-
this.
|
|
593
|
+
this.messenger.publish(`${controllerName}:notificationsListUpdated`, this.state.metamaskNotificationsList);
|
|
592
594
|
__classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsFetchingMetamaskNotifications).call(this, false);
|
|
593
595
|
return metamaskNotifications;
|
|
594
596
|
}
|
|
@@ -642,7 +644,7 @@ class NotificationServicesController extends BaseController {
|
|
|
642
644
|
for (const id of ids) {
|
|
643
645
|
await this.deleteNotificationById(id);
|
|
644
646
|
}
|
|
645
|
-
this.
|
|
647
|
+
this.messenger.publish(`${controllerName}:notificationsListUpdated`, this.state.metamaskNotificationsList);
|
|
646
648
|
}
|
|
647
649
|
/**
|
|
648
650
|
* Marks specified metamask notifications as read.
|
|
@@ -675,7 +677,7 @@ class NotificationServicesController extends BaseController {
|
|
|
675
677
|
const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken();
|
|
676
678
|
if (bearerToken) {
|
|
677
679
|
onchainNotificationIds = onChainNotifications.map((notification) => notification.id);
|
|
678
|
-
await
|
|
680
|
+
await markNotificationsAsRead(bearerToken, onchainNotificationIds).catch(() => {
|
|
679
681
|
onchainNotificationIds = [];
|
|
680
682
|
log.warn('Unable to mark onchain notifications as read');
|
|
681
683
|
});
|
|
@@ -718,7 +720,7 @@ class NotificationServicesController extends BaseController {
|
|
|
718
720
|
return notification;
|
|
719
721
|
});
|
|
720
722
|
});
|
|
721
|
-
this.
|
|
723
|
+
this.messenger.publish(`${controllerName}:markNotificationsAsRead`, this.state.metamaskNotificationsList);
|
|
722
724
|
}
|
|
723
725
|
/**
|
|
724
726
|
* Updates the list of MetaMask notifications by adding a new notification at the beginning of the list.
|
|
@@ -743,7 +745,7 @@ class NotificationServicesController extends BaseController {
|
|
|
743
745
|
];
|
|
744
746
|
}
|
|
745
747
|
});
|
|
746
|
-
this.
|
|
748
|
+
this.messenger.publish(`${controllerName}:notificationsListUpdated`, this.state.metamaskNotificationsList);
|
|
747
749
|
}
|
|
748
750
|
}
|
|
749
751
|
/**
|
|
@@ -762,11 +764,11 @@ class NotificationServicesController extends BaseController {
|
|
|
762
764
|
}
|
|
763
765
|
}
|
|
764
766
|
}
|
|
765
|
-
_NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(), _NotificationServicesController_pushNotifications = new WeakMap(), _NotificationServicesController_accounts = new WeakMap(), _NotificationServicesController_featureAnnouncementEnv = new WeakMap(), _NotificationServicesController_instances = new WeakSet(), _NotificationServicesController_registerMessageHandlers = function _NotificationServicesController_registerMessageHandlers() {
|
|
766
|
-
this.
|
|
767
|
-
this.
|
|
768
|
-
this.
|
|
769
|
-
this.
|
|
767
|
+
_NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(), _NotificationServicesController_pushNotifications = new WeakMap(), _NotificationServicesController_accounts = new WeakMap(), _NotificationServicesController_locale = new WeakMap(), _NotificationServicesController_featureAnnouncementEnv = new WeakMap(), _NotificationServicesController_instances = new WeakSet(), _NotificationServicesController_registerMessageHandlers = function _NotificationServicesController_registerMessageHandlers() {
|
|
768
|
+
this.messenger.registerActionHandler(`${controllerName}:updateMetamaskNotificationsList`, this.updateMetamaskNotificationsList.bind(this));
|
|
769
|
+
this.messenger.registerActionHandler(`${controllerName}:disableNotificationServices`, this.disableNotificationServices.bind(this));
|
|
770
|
+
this.messenger.registerActionHandler(`${controllerName}:getNotificationsByType`, this.getNotificationsByType.bind(this));
|
|
771
|
+
this.messenger.registerActionHandler(`${controllerName}:deleteNotificationsById`, this.deleteNotificationsById.bind(this));
|
|
770
772
|
}, _NotificationServicesController_clearLoadingStates = function _NotificationServicesController_clearLoadingStates() {
|
|
771
773
|
this.update((state) => {
|
|
772
774
|
state.isUpdatingMetamaskNotifications = false;
|