@metamask-previews/notification-services-controller 0.1.0-preview-95089367 → 0.1.0-preview-caf274f8
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/dist/NotificationServicesController/NotificationServicesController.js +3 -3
- package/dist/NotificationServicesController/NotificationServicesController.mjs +2 -2
- package/dist/NotificationServicesController/constants/constants.js +1 -1
- package/dist/NotificationServicesController/constants/constants.mjs +1 -1
- package/dist/NotificationServicesController/constants/index.js +2 -2
- package/dist/NotificationServicesController/constants/index.mjs +2 -2
- package/dist/NotificationServicesController/constants/notification-schema.js +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.mjs +1 -1
- package/dist/NotificationServicesController/index.js +6 -6
- package/dist/NotificationServicesController/index.mjs +5 -5
- package/dist/NotificationServicesController/processors/index.js +2 -2
- package/dist/NotificationServicesController/processors/index.mjs +2 -2
- package/dist/NotificationServicesController/processors/process-feature-announcement.js +1 -1
- package/dist/NotificationServicesController/processors/process-feature-announcement.mjs +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.js +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.mjs +1 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.js +1 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.js +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.mjs +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.js +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs +1 -1
- package/dist/NotificationServicesController/utils/utils.js +1 -1
- package/dist/NotificationServicesController/utils/utils.mjs +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.js +9 -9
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +8 -8
- package/dist/NotificationServicesPushController/constants.js +1 -1
- package/dist/NotificationServicesPushController/constants.mjs +1 -1
- package/dist/NotificationServicesPushController/index.js +12 -12
- package/dist/NotificationServicesPushController/index.mjs +11 -11
- package/dist/NotificationServicesPushController/services/endpoints.js +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.mjs +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.js +7 -7
- package/dist/NotificationServicesPushController/services/push/push-web.mjs +6 -6
- package/dist/NotificationServicesPushController/services/services.js +8 -8
- package/dist/NotificationServicesPushController/services/services.mjs +7 -7
- package/dist/NotificationServicesPushController/utils/get-notification-data.js +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.mjs +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.js +7 -7
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +6 -6
- package/dist/NotificationServicesPushController/utils/index.js +8 -8
- package/dist/NotificationServicesPushController/utils/index.mjs +7 -7
- package/dist/{chunk-QTK2RMF7.mjs → chunk-57S5B7X2.mjs} +2 -2
- package/dist/{chunk-UPVIT75F.js → chunk-6265FKB5.js} +3 -3
- package/dist/{chunk-DKQBDI4C.js → chunk-6GPIA5G3.js} +35 -35
- package/dist/{chunk-PGMXFZ6Y.js → chunk-ABFHAGGB.js} +3 -3
- package/dist/{chunk-SSWX2N73.mjs → chunk-AHEMTJDE.mjs} +2 -2
- package/dist/{chunk-TT56I53C.mjs → chunk-CQI6FYPZ.mjs} +2 -2
- package/dist/{chunk-JLHFZ2UG.mjs → chunk-DBTJ34DS.mjs} +3 -3
- package/dist/{chunk-YRWUXGL3.js → chunk-DOYL2MCR.js} +102 -82
- package/dist/chunk-DOYL2MCR.js.map +1 -0
- package/dist/{chunk-NJBJIZLR.js → chunk-H4RSHSWR.js} +6 -7
- package/dist/chunk-H4RSHSWR.js.map +1 -0
- package/dist/chunk-IGY2S5BC.js +36 -0
- package/dist/{chunk-CQ6CGSKZ.js → chunk-IK7KP7N3.js} +3 -3
- package/dist/{chunk-FFQNSBPU.js → chunk-KCIC5BWH.js} +7 -7
- package/dist/chunk-NBRY7XVG.mjs +925 -0
- package/dist/chunk-NBRY7XVG.mjs.map +1 -0
- package/dist/{chunk-NXXY4CAP.js → chunk-O6RMA2N6.js} +9 -36
- package/dist/chunk-O6RMA2N6.js.map +1 -0
- package/dist/{chunk-NMLYB3XT.js → chunk-QJTZL7TJ.js} +4 -4
- package/dist/{chunk-VE4DTN4R.mjs → chunk-QSFGJCPI.mjs} +2 -2
- package/dist/{chunk-52NKJDI2.mjs → chunk-TI4UC3G3.mjs} +5 -6
- package/dist/chunk-TI4UC3G3.mjs.map +1 -0
- package/dist/{chunk-LFD7J7KR.mjs → chunk-TS2NQOUA.mjs} +6 -33
- package/dist/chunk-TS2NQOUA.mjs.map +1 -0
- package/dist/chunk-U5UIDVOO.mjs +36 -0
- package/dist/chunk-XYIGTTEP.js +925 -0
- package/dist/chunk-XYIGTTEP.js.map +1 -0
- package/dist/{chunk-RYAHBEX2.mjs → chunk-YSNDM6BH.mjs} +26 -6
- package/dist/chunk-YSNDM6BH.mjs.map +1 -0
- package/dist/{chunk-ODZ6V4PH.mjs → chunk-ZFNFSLS6.mjs} +4 -4
- package/dist/index.js +12 -12
- package/dist/index.mjs +11 -11
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/NotificationServicesController/NotificationServicesController.d.ts +2 -0
- package/dist/types/NotificationServicesController/NotificationServicesController.d.ts.map +1 -1
- package/dist/types/NotificationServicesController/__fixtures__/index.d.ts +0 -1
- package/dist/types/NotificationServicesController/__fixtures__/index.d.ts.map +1 -1
- package/dist/types/NotificationServicesPushController/__fixtures__/index.d.ts +0 -1
- package/dist/types/NotificationServicesPushController/__fixtures__/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-26CCETCM.mjs +0 -70
- package/dist/chunk-4KZO4UUC.js +0 -4300
- package/dist/chunk-4KZO4UUC.js.map +0 -1
- package/dist/chunk-52NKJDI2.mjs.map +0 -1
- package/dist/chunk-HCOBC2R5.mjs +0 -4300
- package/dist/chunk-HCOBC2R5.mjs.map +0 -1
- package/dist/chunk-LFD7J7KR.mjs.map +0 -1
- package/dist/chunk-NJBJIZLR.js.map +0 -1
- package/dist/chunk-NXXY4CAP.js.map +0 -1
- package/dist/chunk-RYAHBEX2.mjs.map +0 -1
- package/dist/chunk-V46WVGWN.js +0 -70
- package/dist/chunk-YRWUXGL3.js.map +0 -1
- /package/dist/{chunk-QTK2RMF7.mjs.map → chunk-57S5B7X2.mjs.map} +0 -0
- /package/dist/{chunk-UPVIT75F.js.map → chunk-6265FKB5.js.map} +0 -0
- /package/dist/{chunk-DKQBDI4C.js.map → chunk-6GPIA5G3.js.map} +0 -0
- /package/dist/{chunk-PGMXFZ6Y.js.map → chunk-ABFHAGGB.js.map} +0 -0
- /package/dist/{chunk-SSWX2N73.mjs.map → chunk-AHEMTJDE.mjs.map} +0 -0
- /package/dist/{chunk-TT56I53C.mjs.map → chunk-CQI6FYPZ.mjs.map} +0 -0
- /package/dist/{chunk-JLHFZ2UG.mjs.map → chunk-DBTJ34DS.mjs.map} +0 -0
- /package/dist/{chunk-V46WVGWN.js.map → chunk-IGY2S5BC.js.map} +0 -0
- /package/dist/{chunk-CQ6CGSKZ.js.map → chunk-IK7KP7N3.js.map} +0 -0
- /package/dist/{chunk-FFQNSBPU.js.map → chunk-KCIC5BWH.js.map} +0 -0
- /package/dist/{chunk-NMLYB3XT.js.map → chunk-QJTZL7TJ.js.map} +0 -0
- /package/dist/{chunk-VE4DTN4R.mjs.map → chunk-QSFGJCPI.mjs.map} +0 -0
- /package/dist/{chunk-26CCETCM.mjs.map → chunk-U5UIDVOO.mjs.map} +0 -0
- /package/dist/{chunk-ODZ6V4PH.mjs.map → chunk-ZFNFSLS6.mjs.map} +0 -0
|
@@ -26,7 +26,7 @@ var _chunkTLX5QQK5js = require('./chunk-TLX5QQK5.js');
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
var
|
|
29
|
+
var _chunkIGY2S5BCjs = require('./chunk-IGY2S5BC.js');
|
|
30
30
|
|
|
31
31
|
// src/NotificationServicesController/NotificationServicesController.ts
|
|
32
32
|
var _basecontroller = require('@metamask/base-controller');
|
|
@@ -87,7 +87,7 @@ var defaultState = {
|
|
|
87
87
|
isUpdatingMetamaskNotificationsAccount: [],
|
|
88
88
|
isCheckingAccountsPresence: false
|
|
89
89
|
};
|
|
90
|
-
var _auth, _storage, _pushNotifications, _accounts, _featureAnnouncementEnv, _registerMessageHandlers, registerMessageHandlers_fn, _clearLoadingStates, clearLoadingStates_fn, _assertAuthEnabled, assertAuthEnabled_fn, _getValidStorageKeyAndBearerToken, getValidStorageKeyAndBearerToken_fn, _performEnableProfileSyncing, _assertUserStorage, assertUserStorage_fn, _getUserStorage, getUserStorage_fn, _setIsUpdatingMetamaskNotifications, setIsUpdatingMetamaskNotifications_fn, _setIsFetchingMetamaskNotifications, setIsFetchingMetamaskNotifications_fn, _setIsCheckingAccountsPresence, setIsCheckingAccountsPresence_fn, _updateUpdatingAccountsState, updateUpdatingAccountsState_fn, _clearUpdatingAccountsState, clearUpdatingAccountsState_fn;
|
|
90
|
+
var _isPushIntegrated, _auth, _storage, _pushNotifications, _accounts, _featureAnnouncementEnv, _registerMessageHandlers, registerMessageHandlers_fn, _clearLoadingStates, clearLoadingStates_fn, _assertAuthEnabled, assertAuthEnabled_fn, _getValidStorageKeyAndBearerToken, getValidStorageKeyAndBearerToken_fn, _performEnableProfileSyncing, _assertUserStorage, assertUserStorage_fn, _getUserStorage, getUserStorage_fn, _setIsUpdatingMetamaskNotifications, setIsUpdatingMetamaskNotifications_fn, _setIsFetchingMetamaskNotifications, setIsFetchingMetamaskNotifications_fn, _setIsCheckingAccountsPresence, setIsCheckingAccountsPresence_fn, _updateUpdatingAccountsState, updateUpdatingAccountsState_fn, _clearUpdatingAccountsState, clearUpdatingAccountsState_fn;
|
|
91
91
|
var NotificationServicesController = class extends _basecontroller.BaseController {
|
|
92
92
|
/**
|
|
93
93
|
* Creates a NotificationServicesController instance.
|
|
@@ -97,6 +97,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
97
97
|
* @param args.state - Initial state to set on this controller.
|
|
98
98
|
* @param args.env - environment variables for a given controller.
|
|
99
99
|
* @param args.env.featureAnnouncements - env variables for feature announcements.
|
|
100
|
+
* @param args.env.isPushIntegrated - toggle push notifications on/off if client has integrated them.
|
|
100
101
|
*/
|
|
101
102
|
constructor({
|
|
102
103
|
messenger,
|
|
@@ -109,11 +110,11 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
109
110
|
name: controllerName,
|
|
110
111
|
state: { ...defaultState, ...state }
|
|
111
112
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _registerMessageHandlers);
|
|
114
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _clearLoadingStates);
|
|
115
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _assertAuthEnabled);
|
|
116
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _getValidStorageKeyAndBearerToken);
|
|
117
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _assertUserStorage);
|
|
117
118
|
/**
|
|
118
119
|
* Retrieves and parses the user storage from the storage key.
|
|
119
120
|
*
|
|
@@ -123,7 +124,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
123
124
|
*
|
|
124
125
|
* @returns The parsed user storage object or null
|
|
125
126
|
*/
|
|
126
|
-
|
|
127
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _getUserStorage);
|
|
127
128
|
/**
|
|
128
129
|
* Sets the state of notification creation process.
|
|
129
130
|
*
|
|
@@ -134,7 +135,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
134
135
|
*
|
|
135
136
|
* @param isUpdatingMetamaskNotifications - A boolean value representing the new state of the notification creation process.
|
|
136
137
|
*/
|
|
137
|
-
|
|
138
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _setIsUpdatingMetamaskNotifications);
|
|
138
139
|
/**
|
|
139
140
|
* Updates the state to indicate whether fetching of MetaMask notifications is in progress.
|
|
140
141
|
*
|
|
@@ -143,7 +144,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
143
144
|
*
|
|
144
145
|
* @param isFetchingMetamaskNotifications - A boolean value representing the fetching state.
|
|
145
146
|
*/
|
|
146
|
-
|
|
147
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _setIsFetchingMetamaskNotifications);
|
|
147
148
|
/**
|
|
148
149
|
* Updates the state to indicate that the checking of accounts presence is in progress.
|
|
149
150
|
*
|
|
@@ -153,21 +154,23 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
153
154
|
*
|
|
154
155
|
* @param isCheckingAccountsPresence - A boolean value indicating whether the account presence check is currently active.
|
|
155
156
|
*/
|
|
156
|
-
|
|
157
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _setIsCheckingAccountsPresence);
|
|
157
158
|
/**
|
|
158
159
|
* Updates the state to indicate that account updates are in progress.
|
|
159
160
|
* Removes duplicate accounts before updating the state.
|
|
160
161
|
*
|
|
161
162
|
* @param accounts - The accounts being updated.
|
|
162
163
|
*/
|
|
163
|
-
|
|
164
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _updateUpdatingAccountsState);
|
|
164
165
|
/**
|
|
165
166
|
* Clears the state indicating that account updates are complete.
|
|
166
167
|
*
|
|
167
168
|
* @param accounts - The accounts that have finished updating.
|
|
168
169
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _clearUpdatingAccountsState);
|
|
171
|
+
// Temporary boolean as push notifications are not yet enabled on mobile
|
|
172
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _isPushIntegrated, true);
|
|
173
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _auth, {
|
|
171
174
|
getBearerToken: async () => {
|
|
172
175
|
return await this.messagingSystem.call(
|
|
173
176
|
"AuthenticationController:getBearerToken"
|
|
@@ -177,7 +180,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
177
180
|
return this.messagingSystem.call("AuthenticationController:isSignedIn");
|
|
178
181
|
}
|
|
179
182
|
});
|
|
180
|
-
|
|
183
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _storage, {
|
|
181
184
|
enableProfileSyncing: async () => {
|
|
182
185
|
return await this.messagingSystem.call(
|
|
183
186
|
"UserStorageController:enableProfileSyncing"
|
|
@@ -200,26 +203,38 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
200
203
|
);
|
|
201
204
|
}
|
|
202
205
|
});
|
|
203
|
-
|
|
206
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _pushNotifications, {
|
|
204
207
|
enablePushNotifications: async (UUIDs) => {
|
|
205
|
-
|
|
208
|
+
if (!_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _isPushIntegrated)) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
await this.messagingSystem.call(
|
|
206
212
|
"NotificationServicesPushController:enablePushNotifications",
|
|
207
213
|
UUIDs
|
|
208
214
|
);
|
|
209
215
|
},
|
|
210
216
|
disablePushNotifications: async (UUIDs) => {
|
|
211
|
-
|
|
217
|
+
if (!_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _isPushIntegrated)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
await this.messagingSystem.call(
|
|
212
221
|
"NotificationServicesPushController:disablePushNotifications",
|
|
213
222
|
UUIDs
|
|
214
223
|
);
|
|
215
224
|
},
|
|
216
225
|
updatePushNotifications: async (UUIDs) => {
|
|
217
|
-
|
|
226
|
+
if (!_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _isPushIntegrated)) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
await this.messagingSystem.call(
|
|
218
230
|
"NotificationServicesPushController:updateTriggerPushNotifications",
|
|
219
231
|
UUIDs
|
|
220
232
|
);
|
|
221
233
|
},
|
|
222
234
|
subscribe: () => {
|
|
235
|
+
if (!_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _isPushIntegrated)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
223
238
|
this.messagingSystem.subscribe(
|
|
224
239
|
"NotificationServicesPushController:onNewNotifications",
|
|
225
240
|
(notification) => {
|
|
@@ -228,18 +243,21 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
228
243
|
);
|
|
229
244
|
},
|
|
230
245
|
initializePushNotifications: async () => {
|
|
246
|
+
if (!_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _isPushIntegrated)) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
231
249
|
if (!this.state.isNotificationServicesEnabled) {
|
|
232
250
|
return;
|
|
233
251
|
}
|
|
234
|
-
const storage = await
|
|
252
|
+
const storage = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getUserStorage, getUserStorage_fn).call(this);
|
|
235
253
|
if (!storage) {
|
|
236
254
|
return;
|
|
237
255
|
}
|
|
238
256
|
const uuids = _chunkPIZCE3JDjs.getAllUUIDs.call(void 0, storage);
|
|
239
|
-
await
|
|
257
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _pushNotifications).enablePushNotifications(uuids);
|
|
240
258
|
}
|
|
241
259
|
});
|
|
242
|
-
|
|
260
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _accounts, {
|
|
243
261
|
/**
|
|
244
262
|
* Used to get list of addresses from keyring (wallet addresses)
|
|
245
263
|
*
|
|
@@ -278,7 +296,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
278
296
|
* @returns result from list accounts
|
|
279
297
|
*/
|
|
280
298
|
initialize: () => {
|
|
281
|
-
return
|
|
299
|
+
return _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _accounts).listAccounts();
|
|
282
300
|
},
|
|
283
301
|
/**
|
|
284
302
|
* Subscription to any state change in the keyring controller (aka wallet accounts).
|
|
@@ -293,7 +311,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
293
311
|
if (!this.state.isNotificationServicesEnabled) {
|
|
294
312
|
return;
|
|
295
313
|
}
|
|
296
|
-
const { accountsAdded, accountsRemoved } = await
|
|
314
|
+
const { accountsAdded, accountsRemoved } = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _accounts).listAccounts();
|
|
297
315
|
const promises = [];
|
|
298
316
|
if (accountsAdded.length > 0) {
|
|
299
317
|
promises.push(this.updateOnChainTriggersByAccount(accountsAdded));
|
|
@@ -306,22 +324,23 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
306
324
|
);
|
|
307
325
|
}
|
|
308
326
|
});
|
|
309
|
-
|
|
310
|
-
|
|
327
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _featureAnnouncementEnv, void 0);
|
|
328
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _performEnableProfileSyncing, async () => {
|
|
311
329
|
try {
|
|
312
|
-
await
|
|
330
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _storage).enableProfileSyncing();
|
|
313
331
|
} catch (e) {
|
|
314
332
|
_loglevel2.default.error("Failed to enable profile syncing", e);
|
|
315
333
|
throw new Error("Failed to enable profile syncing");
|
|
316
334
|
}
|
|
317
335
|
});
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
336
|
+
_chunkIGY2S5BCjs.__privateSet.call(void 0, this, _isPushIntegrated, env.isPushIntegrated ?? true);
|
|
337
|
+
_chunkIGY2S5BCjs.__privateSet.call(void 0, this, _featureAnnouncementEnv, env.featureAnnouncements);
|
|
338
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
|
|
339
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _clearLoadingStates, clearLoadingStates_fn).call(this);
|
|
340
|
+
_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _accounts).initialize();
|
|
341
|
+
_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _pushNotifications).initializePushNotifications();
|
|
342
|
+
_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _accounts).subscribe();
|
|
343
|
+
_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _pushNotifications).subscribe();
|
|
325
344
|
}
|
|
326
345
|
/**
|
|
327
346
|
* Retrieves the current enabled state of MetaMask notifications.
|
|
@@ -336,16 +355,16 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
336
355
|
}
|
|
337
356
|
async checkAccountsPresence(accounts) {
|
|
338
357
|
try {
|
|
339
|
-
|
|
340
|
-
const userStorage = await
|
|
341
|
-
|
|
358
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsCheckingAccountsPresence, setIsCheckingAccountsPresence_fn).call(this, true);
|
|
359
|
+
const userStorage = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getUserStorage, getUserStorage_fn).call(this);
|
|
360
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertUserStorage, assertUserStorage_fn).call(this, userStorage);
|
|
342
361
|
const presence = _chunkPIZCE3JDjs.checkAccountsPresence.call(void 0, userStorage, accounts);
|
|
343
362
|
return presence;
|
|
344
363
|
} catch (error) {
|
|
345
364
|
_loglevel2.default.error("Failed to check accounts presence", error);
|
|
346
365
|
throw error;
|
|
347
366
|
} finally {
|
|
348
|
-
|
|
367
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsCheckingAccountsPresence, setIsCheckingAccountsPresence_fn).call(this, false);
|
|
349
368
|
}
|
|
350
369
|
}
|
|
351
370
|
/**
|
|
@@ -377,17 +396,17 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
377
396
|
*/
|
|
378
397
|
async createOnChainTriggers() {
|
|
379
398
|
try {
|
|
380
|
-
|
|
381
|
-
await
|
|
382
|
-
const { bearerToken, storageKey } = await
|
|
383
|
-
const { accounts } = await
|
|
384
|
-
let userStorage = await
|
|
399
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsUpdatingMetamaskNotifications, setIsUpdatingMetamaskNotifications_fn).call(this, true);
|
|
400
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _performEnableProfileSyncing).call(this);
|
|
401
|
+
const { bearerToken, storageKey } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getValidStorageKeyAndBearerToken, getValidStorageKeyAndBearerToken_fn).call(this);
|
|
402
|
+
const { accounts } = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _accounts).listAccounts();
|
|
403
|
+
let userStorage = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getUserStorage, getUserStorage_fn).call(this);
|
|
385
404
|
if (userStorage?.[_chunkTLX5QQK5js.USER_STORAGE_VERSION_KEY] === void 0) {
|
|
386
405
|
userStorage = _chunkPIZCE3JDjs.initializeUserStorage.call(void 0,
|
|
387
406
|
accounts.map((account) => ({ address: account })),
|
|
388
407
|
false
|
|
389
408
|
);
|
|
390
|
-
await
|
|
409
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _storage).setNotificationStorage(JSON.stringify(userStorage));
|
|
391
410
|
}
|
|
392
411
|
const triggers = _chunkPIZCE3JDjs.traverseUserStorageTriggers.call(void 0, userStorage);
|
|
393
412
|
await _chunkVOZ7Y2OOjs.createOnChainTriggers.call(void 0,
|
|
@@ -397,8 +416,8 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
397
416
|
triggers
|
|
398
417
|
);
|
|
399
418
|
const allUUIDS = _chunkPIZCE3JDjs.getAllUUIDs.call(void 0, userStorage);
|
|
400
|
-
await
|
|
401
|
-
await
|
|
419
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _pushNotifications).enablePushNotifications(allUUIDS);
|
|
420
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _storage).setNotificationStorage(JSON.stringify(userStorage));
|
|
402
421
|
this.update((state) => {
|
|
403
422
|
state.isNotificationServicesEnabled = true;
|
|
404
423
|
state.isFeatureAnnouncementsEnabled = true;
|
|
@@ -409,7 +428,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
409
428
|
_loglevel2.default.error("Failed to create On Chain triggers", err);
|
|
410
429
|
throw new Error("Failed to create On Chain triggers");
|
|
411
430
|
} finally {
|
|
412
|
-
|
|
431
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsUpdatingMetamaskNotifications, setIsUpdatingMetamaskNotifications_fn).call(this, false);
|
|
413
432
|
}
|
|
414
433
|
}
|
|
415
434
|
/**
|
|
@@ -424,13 +443,13 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
424
443
|
*/
|
|
425
444
|
async enableMetamaskNotifications() {
|
|
426
445
|
try {
|
|
427
|
-
|
|
446
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsUpdatingMetamaskNotifications, setIsUpdatingMetamaskNotifications_fn).call(this, true);
|
|
428
447
|
await this.createOnChainTriggers();
|
|
429
448
|
} catch (e) {
|
|
430
449
|
_loglevel2.default.error("Unable to enable notifications", e);
|
|
431
450
|
throw new Error("Unable to enable notifications");
|
|
432
451
|
} finally {
|
|
433
|
-
|
|
452
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsUpdatingMetamaskNotifications, setIsUpdatingMetamaskNotifications_fn).call(this, false);
|
|
434
453
|
}
|
|
435
454
|
}
|
|
436
455
|
/**
|
|
@@ -443,11 +462,11 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
443
462
|
*/
|
|
444
463
|
async disableNotificationServices() {
|
|
445
464
|
try {
|
|
446
|
-
|
|
447
|
-
const userStorage = await
|
|
448
|
-
|
|
465
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsUpdatingMetamaskNotifications, setIsUpdatingMetamaskNotifications_fn).call(this, true);
|
|
466
|
+
const userStorage = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getUserStorage, getUserStorage_fn).call(this);
|
|
467
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertUserStorage, assertUserStorage_fn).call(this, userStorage);
|
|
449
468
|
const UUIDs = _chunkPIZCE3JDjs.getAllUUIDs.call(void 0, userStorage);
|
|
450
|
-
await
|
|
469
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _pushNotifications).disablePushNotifications(UUIDs);
|
|
451
470
|
this.update((state) => {
|
|
452
471
|
state.isNotificationServicesEnabled = false;
|
|
453
472
|
state.isFeatureAnnouncementsEnabled = false;
|
|
@@ -457,7 +476,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
457
476
|
_loglevel2.default.error("Unable to disable notifications", e);
|
|
458
477
|
throw new Error("Unable to disable notifications");
|
|
459
478
|
} finally {
|
|
460
|
-
|
|
479
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsUpdatingMetamaskNotifications, setIsUpdatingMetamaskNotifications_fn).call(this, false);
|
|
461
480
|
}
|
|
462
481
|
}
|
|
463
482
|
/**
|
|
@@ -476,10 +495,10 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
476
495
|
*/
|
|
477
496
|
async deleteOnChainTriggersByAccount(accounts) {
|
|
478
497
|
try {
|
|
479
|
-
|
|
480
|
-
const { bearerToken, storageKey } = await
|
|
481
|
-
const userStorage = await
|
|
482
|
-
|
|
498
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _updateUpdatingAccountsState, updateUpdatingAccountsState_fn).call(this, accounts);
|
|
499
|
+
const { bearerToken, storageKey } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getValidStorageKeyAndBearerToken, getValidStorageKeyAndBearerToken_fn).call(this);
|
|
500
|
+
const userStorage = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getUserStorage, getUserStorage_fn).call(this);
|
|
501
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertUserStorage, assertUserStorage_fn).call(this, userStorage);
|
|
483
502
|
const UUIDs = accounts.map((a) => _chunkPIZCE3JDjs.getUUIDsForAccount.call(void 0, userStorage, a.toLowerCase())).flat();
|
|
484
503
|
if (UUIDs.length === 0) {
|
|
485
504
|
return userStorage;
|
|
@@ -490,14 +509,14 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
490
509
|
bearerToken,
|
|
491
510
|
UUIDs
|
|
492
511
|
);
|
|
493
|
-
await
|
|
494
|
-
await
|
|
512
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _pushNotifications).disablePushNotifications(UUIDs);
|
|
513
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _storage).setNotificationStorage(JSON.stringify(userStorage));
|
|
495
514
|
return userStorage;
|
|
496
515
|
} catch (err) {
|
|
497
516
|
_loglevel2.default.error("Failed to delete OnChain triggers", err);
|
|
498
517
|
throw new Error("Failed to delete OnChain triggers");
|
|
499
518
|
} finally {
|
|
500
|
-
|
|
519
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _clearUpdatingAccountsState, clearUpdatingAccountsState_fn).call(this, accounts);
|
|
501
520
|
}
|
|
502
521
|
}
|
|
503
522
|
/**
|
|
@@ -517,10 +536,10 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
517
536
|
*/
|
|
518
537
|
async updateOnChainTriggersByAccount(accounts) {
|
|
519
538
|
try {
|
|
520
|
-
|
|
521
|
-
const { bearerToken, storageKey } = await
|
|
522
|
-
const userStorage = await
|
|
523
|
-
|
|
539
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _updateUpdatingAccountsState, updateUpdatingAccountsState_fn).call(this, accounts);
|
|
540
|
+
const { bearerToken, storageKey } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getValidStorageKeyAndBearerToken, getValidStorageKeyAndBearerToken_fn).call(this);
|
|
541
|
+
const userStorage = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getUserStorage, getUserStorage_fn).call(this);
|
|
542
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertUserStorage, assertUserStorage_fn).call(this, userStorage);
|
|
524
543
|
accounts.forEach((a) => _chunkPIZCE3JDjs.upsertAddressTriggers.call(void 0, a, userStorage));
|
|
525
544
|
const newTriggers = _chunkPIZCE3JDjs.traverseUserStorageTriggers.call(void 0, userStorage, {
|
|
526
545
|
mapTrigger: (t) => {
|
|
@@ -531,7 +550,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
531
550
|
}
|
|
532
551
|
});
|
|
533
552
|
if (newTriggers.length > 0) {
|
|
534
|
-
await
|
|
553
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _storage).setNotificationStorage(JSON.stringify(userStorage));
|
|
535
554
|
const triggers = _chunkPIZCE3JDjs.traverseUserStorageTriggers.call(void 0, userStorage, {
|
|
536
555
|
mapTrigger: (t) => {
|
|
537
556
|
if (accounts.some((a) => a.toLowerCase() === t.address.toLowerCase())) {
|
|
@@ -548,14 +567,14 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
548
567
|
);
|
|
549
568
|
}
|
|
550
569
|
const UUIDs = _chunkPIZCE3JDjs.getAllUUIDs.call(void 0, userStorage);
|
|
551
|
-
await
|
|
552
|
-
await
|
|
570
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _pushNotifications).updatePushNotifications(UUIDs);
|
|
571
|
+
await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _storage).setNotificationStorage(JSON.stringify(userStorage));
|
|
553
572
|
return userStorage;
|
|
554
573
|
} catch (err) {
|
|
555
574
|
_loglevel2.default.error("Failed to update OnChain triggers", err);
|
|
556
575
|
throw new Error("Failed to update OnChain triggers");
|
|
557
576
|
} finally {
|
|
558
|
-
|
|
577
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _clearUpdatingAccountsState, clearUpdatingAccountsState_fn).call(this, accounts);
|
|
559
578
|
}
|
|
560
579
|
}
|
|
561
580
|
/**
|
|
@@ -568,13 +587,13 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
568
587
|
*/
|
|
569
588
|
async fetchAndUpdateMetamaskNotifications() {
|
|
570
589
|
try {
|
|
571
|
-
|
|
590
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsFetchingMetamaskNotifications, setIsFetchingMetamaskNotifications_fn).call(this, true);
|
|
572
591
|
const rawFeatureAnnouncementNotifications = this.state.isFeatureAnnouncementsEnabled ? await _chunkZMNXLHACjs.getFeatureAnnouncementNotifications.call(void 0,
|
|
573
|
-
|
|
592
|
+
_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _featureAnnouncementEnv)
|
|
574
593
|
).catch(() => []) : [];
|
|
575
594
|
const rawOnChainNotifications = [];
|
|
576
|
-
const userStorage = await
|
|
577
|
-
const bearerToken = await
|
|
595
|
+
const userStorage = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _storage).getNotificationStorage().then((s) => s && JSON.parse(s)).catch(() => null);
|
|
596
|
+
const bearerToken = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _auth).getBearerToken().catch(() => null);
|
|
578
597
|
if (userStorage && bearerToken) {
|
|
579
598
|
const notifications = await _chunkVOZ7Y2OOjs.getOnChainNotifications.call(void 0,
|
|
580
599
|
userStorage,
|
|
@@ -599,10 +618,10 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
599
618
|
this.update((state) => {
|
|
600
619
|
state.metamaskNotificationsList = metamaskNotifications;
|
|
601
620
|
});
|
|
602
|
-
|
|
621
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsFetchingMetamaskNotifications, setIsFetchingMetamaskNotifications_fn).call(this, false);
|
|
603
622
|
return metamaskNotifications;
|
|
604
623
|
} catch (err) {
|
|
605
|
-
|
|
624
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsFetchingMetamaskNotifications, setIsFetchingMetamaskNotifications_fn).call(this, false);
|
|
606
625
|
_loglevel2.default.error("Failed to fetch notifications", err);
|
|
607
626
|
throw new Error("Failed to fetch notifications");
|
|
608
627
|
}
|
|
@@ -624,7 +643,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
624
643
|
(notification) => notification.type === "features_announcement" /* FEATURES_ANNOUNCEMENT */ && !notification.isRead
|
|
625
644
|
);
|
|
626
645
|
if (onChainNotifications.length > 0) {
|
|
627
|
-
const bearerToken = await
|
|
646
|
+
const bearerToken = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _auth).getBearerToken();
|
|
628
647
|
if (bearerToken) {
|
|
629
648
|
onchainNotificationIds = onChainNotifications.map(
|
|
630
649
|
(notification) => notification.id
|
|
@@ -689,6 +708,7 @@ var NotificationServicesController = class extends _basecontroller.BaseControlle
|
|
|
689
708
|
}
|
|
690
709
|
}
|
|
691
710
|
};
|
|
711
|
+
_isPushIntegrated = new WeakMap();
|
|
692
712
|
_auth = new WeakMap();
|
|
693
713
|
_storage = new WeakMap();
|
|
694
714
|
_pushNotifications = new WeakMap();
|
|
@@ -720,7 +740,7 @@ clearLoadingStates_fn = function() {
|
|
|
720
740
|
};
|
|
721
741
|
_assertAuthEnabled = new WeakSet();
|
|
722
742
|
assertAuthEnabled_fn = function() {
|
|
723
|
-
if (!
|
|
743
|
+
if (!_chunkIGY2S5BCjs.__privateGet.call(void 0, this, _auth).isSignedIn()) {
|
|
724
744
|
this.update((state) => {
|
|
725
745
|
state.isNotificationServicesEnabled = false;
|
|
726
746
|
});
|
|
@@ -729,9 +749,9 @@ assertAuthEnabled_fn = function() {
|
|
|
729
749
|
};
|
|
730
750
|
_getValidStorageKeyAndBearerToken = new WeakSet();
|
|
731
751
|
getValidStorageKeyAndBearerToken_fn = async function() {
|
|
732
|
-
|
|
733
|
-
const bearerToken = await
|
|
734
|
-
const storageKey = await
|
|
752
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertAuthEnabled, assertAuthEnabled_fn).call(this);
|
|
753
|
+
const bearerToken = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _auth).getBearerToken();
|
|
754
|
+
const storageKey = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _storage).getStorageKey();
|
|
735
755
|
if (!bearerToken || !storageKey) {
|
|
736
756
|
throw new Error("Missing BearerToken or storage key");
|
|
737
757
|
}
|
|
@@ -746,7 +766,7 @@ assertUserStorage_fn = function(storage) {
|
|
|
746
766
|
};
|
|
747
767
|
_getUserStorage = new WeakSet();
|
|
748
768
|
getUserStorage_fn = async function() {
|
|
749
|
-
const userStorageString = await
|
|
769
|
+
const userStorageString = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _storage).getNotificationStorage();
|
|
750
770
|
if (!userStorageString) {
|
|
751
771
|
return null;
|
|
752
772
|
}
|
|
@@ -799,4 +819,4 @@ clearUpdatingAccountsState_fn = function(accounts) {
|
|
|
799
819
|
|
|
800
820
|
|
|
801
821
|
exports.defaultState = defaultState; exports.NotificationServicesController = NotificationServicesController;
|
|
802
|
-
//# sourceMappingURL=chunk-
|
|
822
|
+
//# sourceMappingURL=chunk-DOYL2MCR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/NotificationServicesController/NotificationServicesController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AASrC,OAAO,SAAS;AAuChB,IAAM,iBAAiB;AAwDvB,IAAM,WAA+D;AAAA,EACnE,0BAA0B;AAAA,IACx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A;AASA;AAAA,uBAAkB,SAChB,SACgC;AAChC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AACF;AAWM;AAAA,oBAAe,iBAAgC;AACnD,QAAM,oBACJ,MAAM,mBAAK,UAAS,uBAAuB;AAE7C,MAAI,CAAC,mBAAmB;AACtB,WAAO;AAAA,EACT;AAEA,MAAI;AACF,UAAM,cAA2B,KAAK,MAAM,iBAAiB;AAC7D,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,MAAM,8BAA8B;AACxC,WAAO;AAAA,EACT;AACF;AAwBA;AAAA,wCAAmC,SACjC,iCACA;AACA,OAAK,OAAO,CAAC,UAAU;AACrB,UAAM,kCAAkC;AAAA,EAC1C,CAAC;AACH;AAUA;AAAA,wCAAmC,SACjC,iCACA;AACA,OAAK,OAAO,CAAC,UAAU;AACrB,UAAM,kCAAkC;AAAA,EAC1C,CAAC;AACH;AAWA;AAAA,mCAA8B,SAAC,4BAAqC;AAClE,OAAK,OAAO,CAAC,UAAU;AACrB,UAAM,6BAA6B;AAAA,EACrC,CAAC;AACH;AAQA;AAAA,iCAA4B,SAAC,UAAoB;AAC/C,OAAK,OAAO,CAAC,UAAU;AACrB,UAAM,iBAAiB,oBAAI,IAAI;AAAA,MAC7B,GAAG,MAAM;AAAA,MACT,GAAG;AAAA,IACL,CAAC;AACD,UAAM,yCAAyC,MAAM,KAAK,cAAc;AAAA,EAC1E,CAAC;AACH;AAOA;AAAA,gCAA2B,SAAC,UAAoB;AAC9C,OAAK,OAAO,CAAC,UAAU;AACrB,UAAM,yCACJ,MAAM,uCAAuC;AAAA,MAC3C,CAAC,oBAAoB,CAAC,SAAS,SAAS,eAAe;AAAA,IACzD;AAAA,EACJ,CAAC;AACH","sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { toChecksumHexAddress } from '@metamask/controller-utils';\nimport type {\n KeyringControllerGetAccountsAction,\n KeyringControllerStateChangeEvent,\n} from '@metamask/keyring-controller';\nimport type {\n AuthenticationController,\n UserStorageController,\n} from '@metamask/profile-sync-controller';\nimport log from 'loglevel';\n\nimport { USER_STORAGE_VERSION_KEY } from './constants/constants';\nimport { TRIGGER_TYPES } from './constants/notification-schema';\nimport { safeProcessNotification } from './processors/process-notifications';\nimport * as FeatureNotifications from './services/feature-announcements';\nimport * as OnChainNotifications from './services/onchain-notifications';\nimport type {\n INotification,\n MarkAsReadNotificationsParam,\n NotificationUnion,\n} from './types/notification/notification';\nimport type { OnChainRawNotification } from './types/on-chain-notification/on-chain-notification';\nimport type { UserStorage } from './types/user-storage/user-storage';\nimport * as Utils from './utils/utils';\n\n// TODO: Fix Circular Type Dependencies\n// This indicates that control flow of messages is everywhere, lets orchestrate these better\nexport type NotificationServicesPushControllerEnablePushNotifications = {\n type: `NotificationServicesPushController:enablePushNotifications`;\n handler: (UUIDs: string[]) => Promise<void>;\n};\n\nexport type NotificationServicesPushControllerDisablePushNotifications = {\n type: `NotificationServicesPushController:disablePushNotifications`;\n handler: (UUIDs: string[]) => Promise<void>;\n};\n\nexport type NotificationServicesPushControllerUpdateTriggerPushNotifications = {\n type: `NotificationServicesPushController:updateTriggerPushNotifications`;\n handler: (UUIDs: string[]) => Promise<void>;\n};\n\nexport type NotificationServicesPushControllerOnNewNotification = {\n type: `NotificationServicesPushController:onNewNotifications`;\n payload: [INotification];\n};\n\n// Unique name for the controller\nconst controllerName = 'NotificationServicesController';\n\n/**\n * State shape for NotificationServicesController\n */\nexport type NotificationServicesControllerState = {\n /**\n * We store and manage accounts that have been seen/visted through the\n * account subscription. This allows us to track and add notifications for new accounts and not previous accounts added.\n */\n subscriptionAccountsSeen: string[];\n\n /**\n * Flag that indicates if the metamask notifications feature has been seen\n */\n isMetamaskNotificationsFeatureSeen: boolean;\n\n /**\n * Flag that indicates if the metamask notifications are enabled\n */\n isNotificationServicesEnabled: boolean;\n\n /**\n * Flag that indicates if the feature announcements are enabled\n */\n isFeatureAnnouncementsEnabled: boolean;\n\n /**\n * List of metamask notifications\n */\n metamaskNotificationsList: INotification[];\n\n /**\n * List of read metamask notifications\n */\n metamaskNotificationsReadList: string[];\n /**\n * Flag that indicates that the creating notifications is in progress\n */\n isUpdatingMetamaskNotifications: boolean;\n /**\n * Flag that indicates that the fetching notifications is in progress\n * This is used to show a loading spinner in the UI\n * when fetching notifications\n */\n isFetchingMetamaskNotifications: boolean;\n /**\n * Flag that indicates that the updating notifications for a specific address is in progress\n */\n isUpdatingMetamaskNotificationsAccount: string[];\n /**\n * Flag that indicates that the checking accounts presence is in progress\n */\n isCheckingAccountsPresence: boolean;\n};\n\nconst metadata: StateMetadata<NotificationServicesControllerState> = {\n subscriptionAccountsSeen: {\n persist: true,\n anonymous: true,\n },\n\n isMetamaskNotificationsFeatureSeen: {\n persist: true,\n anonymous: false,\n },\n isNotificationServicesEnabled: {\n persist: true,\n anonymous: false,\n },\n isFeatureAnnouncementsEnabled: {\n persist: true,\n anonymous: false,\n },\n metamaskNotificationsList: {\n persist: true,\n anonymous: true,\n },\n metamaskNotificationsReadList: {\n persist: true,\n anonymous: true,\n },\n isUpdatingMetamaskNotifications: {\n persist: false,\n anonymous: false,\n },\n isFetchingMetamaskNotifications: {\n persist: false,\n anonymous: false,\n },\n isUpdatingMetamaskNotificationsAccount: {\n persist: false,\n anonymous: false,\n },\n isCheckingAccountsPresence: {\n persist: false,\n anonymous: false,\n },\n};\nexport const defaultState: NotificationServicesControllerState = {\n subscriptionAccountsSeen: [],\n isMetamaskNotificationsFeatureSeen: false,\n isNotificationServicesEnabled: false,\n isFeatureAnnouncementsEnabled: false,\n metamaskNotificationsList: [],\n metamaskNotificationsReadList: [],\n isUpdatingMetamaskNotifications: false,\n isFetchingMetamaskNotifications: false,\n isUpdatingMetamaskNotificationsAccount: [],\n isCheckingAccountsPresence: false,\n};\n\nexport type NotificationServicesControllerUpdateMetamaskNotificationsList = {\n type: `${typeof controllerName}:updateMetamaskNotificationsList`;\n handler: NotificationServicesController['updateMetamaskNotificationsList'];\n};\n\nexport type NotificationServicesControllerDisableNotificationServices = {\n type: `${typeof controllerName}:disableNotificationServices`;\n handler: NotificationServicesController['disableNotificationServices'];\n};\n\nexport type NotificationServicesControllerSelectIsNotificationServicesEnabled =\n {\n type: `${typeof controllerName}:selectIsNotificationServicesEnabled`;\n handler: NotificationServicesController['selectIsNotificationServicesEnabled'];\n };\n\n// Messenger Actions\nexport type Actions =\n | NotificationServicesControllerUpdateMetamaskNotificationsList\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerSelectIsNotificationServicesEnabled\n | ControllerGetStateAction<'state', NotificationServicesControllerState>;\n\n// Allowed Actions\nexport type AllowedActions =\n // Keyring Controller Requests\n | KeyringControllerGetAccountsAction\n // Auth Controller Requests\n | AuthenticationController.AuthenticationControllerGetBearerToken\n | AuthenticationController.AuthenticationControllerIsSignedIn\n // User Storage Controller Requests\n | UserStorageController.UserStorageControllerEnableProfileSyncing\n | UserStorageController.UserStorageControllerGetStorageKey\n | UserStorageController.UserStorageControllerPerformGetStorage\n | UserStorageController.UserStorageControllerPerformSetStorage\n // Push Notifications Controller Requests\n | NotificationServicesPushControllerEnablePushNotifications\n | NotificationServicesPushControllerDisablePushNotifications\n | NotificationServicesPushControllerUpdateTriggerPushNotifications;\n\n// Events\nexport type NotificationServicesControllerMessengerEvents =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesControllerState\n >;\n\n// Allowed Events\nexport type AllowedEvents =\n | KeyringControllerStateChangeEvent\n | NotificationServicesPushControllerOnNewNotification;\n\n// Type for the messenger of NotificationServicesController\nexport type NotificationServicesControllerMessenger =\n RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n >;\n\ntype FeatureAnnouncementEnv = {\n spaceId: string;\n accessToken: string;\n platform: 'extension' | 'mobile';\n};\n\n/**\n * Controller that enables wallet notifications and feature announcements\n */\nexport default class NotificationServicesController extends BaseController<\n typeof controllerName,\n NotificationServicesControllerState,\n NotificationServicesControllerMessenger\n> {\n // Temporary boolean as push notifications are not yet enabled on mobile\n #isPushIntegrated = true;\n\n #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n isSignedIn: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n };\n\n #storage = {\n enableProfileSyncing: async () => {\n return await this.messagingSystem.call(\n 'UserStorageController:enableProfileSyncing',\n );\n },\n getStorageKey: () => {\n return this.messagingSystem.call('UserStorageController:getStorageKey');\n },\n getNotificationStorage: async () => {\n return await this.messagingSystem.call(\n 'UserStorageController:performGetStorage',\n 'notificationSettings',\n );\n },\n setNotificationStorage: async (state: string) => {\n return await this.messagingSystem.call(\n 'UserStorageController:performSetStorage',\n 'notificationSettings',\n state,\n );\n },\n };\n\n #pushNotifications = {\n enablePushNotifications: async (UUIDs: string[]) => {\n if (!this.#isPushIntegrated) {\n return;\n }\n await this.messagingSystem.call(\n 'NotificationServicesPushController:enablePushNotifications',\n UUIDs,\n );\n },\n disablePushNotifications: async (UUIDs: string[]) => {\n if (!this.#isPushIntegrated) {\n return;\n }\n await this.messagingSystem.call(\n 'NotificationServicesPushController:disablePushNotifications',\n UUIDs,\n );\n },\n updatePushNotifications: async (UUIDs: string[]) => {\n if (!this.#isPushIntegrated) {\n return;\n }\n await this.messagingSystem.call(\n 'NotificationServicesPushController:updateTriggerPushNotifications',\n UUIDs,\n );\n },\n subscribe: () => {\n if (!this.#isPushIntegrated) {\n return;\n }\n this.messagingSystem.subscribe(\n 'NotificationServicesPushController:onNewNotifications',\n (notification) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.updateMetamaskNotificationsList(notification);\n },\n );\n },\n initializePushNotifications: async () => {\n if (!this.#isPushIntegrated) {\n return;\n }\n if (!this.state.isNotificationServicesEnabled) {\n return;\n }\n\n const storage = await this.#getUserStorage();\n if (!storage) {\n return;\n }\n\n const uuids = Utils.getAllUUIDs(storage);\n await this.#pushNotifications.enablePushNotifications(uuids);\n },\n };\n\n #accounts = {\n /**\n * Used to get list of addresses from keyring (wallet addresses)\n *\n * @returns addresses removed, added, and latest list of addresses\n */\n listAccounts: async () => {\n // Get previous and current account sets\n const nonChecksumAccounts = await this.messagingSystem.call(\n 'KeyringController:getAccounts',\n );\n const accounts = nonChecksumAccounts.map((a) => toChecksumHexAddress(a));\n const currentAccountsSet = new Set(accounts);\n const prevAccountsSet = new Set(this.state.subscriptionAccountsSeen);\n\n // Invalid value you cannot have zero accounts\n // Only occurs when the Accounts controller is initializing.\n if (accounts.length === 0) {\n return {\n accountsAdded: [],\n accountsRemoved: [],\n accounts: [],\n };\n }\n\n // Calculate added and removed addresses\n const accountsAdded = accounts.filter((a) => !prevAccountsSet.has(a));\n const accountsRemoved = [...prevAccountsSet.values()].filter(\n (a) => !currentAccountsSet.has(a),\n );\n\n // Update accounts seen\n this.update((state) => {\n state.subscriptionAccountsSeen = [...prevAccountsSet, ...accountsAdded];\n });\n\n return {\n accountsAdded,\n accountsRemoved,\n accounts,\n };\n },\n\n /**\n * Initializes the cache/previous list. This is handy so we have an accurate in-mem state of the previous list of accounts.\n *\n * @returns result from list accounts\n */\n initialize: () => {\n return this.#accounts.listAccounts();\n },\n\n /**\n * Subscription to any state change in the keyring controller (aka wallet accounts).\n * We can call the `listAccounts` defined above to find out about any accounts added, removed\n * And call effects to subscribe/unsubscribe to notifications.\n */\n subscribe: () => {\n this.messagingSystem.subscribe(\n 'KeyringController:stateChange',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => {\n if (!this.state.isNotificationServicesEnabled) {\n return;\n }\n\n const { accountsAdded, accountsRemoved } =\n await this.#accounts.listAccounts();\n\n const promises: Promise<unknown>[] = [];\n if (accountsAdded.length > 0) {\n promises.push(this.updateOnChainTriggersByAccount(accountsAdded));\n }\n if (accountsRemoved.length > 0) {\n promises.push(this.deleteOnChainTriggersByAccount(accountsRemoved));\n }\n await Promise.all(promises);\n },\n );\n },\n };\n\n #featureAnnouncementEnv: FeatureAnnouncementEnv;\n\n /**\n * Creates a NotificationServicesController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n * @param args.env - environment variables for a given controller.\n * @param args.env.featureAnnouncements - env variables for feature announcements.\n * @param args.env.isPushIntegrated - toggle push notifications on/off if client has integrated them.\n */\n constructor({\n messenger,\n state,\n env,\n }: {\n messenger: NotificationServicesControllerMessenger;\n state?: Partial<NotificationServicesControllerState>;\n env: {\n featureAnnouncements: FeatureAnnouncementEnv;\n isPushIntegrated?: boolean;\n };\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#isPushIntegrated = env.isPushIntegrated ?? true;\n\n this.#featureAnnouncementEnv = env.featureAnnouncements;\n this.#registerMessageHandlers();\n this.#clearLoadingStates();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#accounts.initialize();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#pushNotifications.initializePushNotifications();\n this.#accounts.subscribe();\n this.#pushNotifications.subscribe();\n }\n\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateMetamaskNotificationsList`,\n this.updateMetamaskNotificationsList.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:disableNotificationServices`,\n this.disableNotificationServices.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:selectIsNotificationServicesEnabled`,\n this.selectIsNotificationServicesEnabled.bind(this),\n );\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingMetamaskNotifications = false;\n state.isCheckingAccountsPresence = false;\n state.isFetchingMetamaskNotifications = false;\n state.isUpdatingMetamaskNotificationsAccount = [];\n });\n }\n\n #assertAuthEnabled() {\n if (!this.#auth.isSignedIn()) {\n this.update((state) => {\n state.isNotificationServicesEnabled = false;\n });\n throw new Error('User is not signed in.');\n }\n }\n\n async #getValidStorageKeyAndBearerToken() {\n this.#assertAuthEnabled();\n\n const bearerToken = await this.#auth.getBearerToken();\n const storageKey = await this.#storage.getStorageKey();\n\n if (!bearerToken || !storageKey) {\n throw new Error('Missing BearerToken or storage key');\n }\n\n return { bearerToken, storageKey };\n }\n\n #performEnableProfileSyncing = async () => {\n try {\n await this.#storage.enableProfileSyncing();\n } catch (e) {\n log.error('Failed to enable profile syncing', e);\n throw new Error('Failed to enable profile syncing');\n }\n };\n\n #assertUserStorage(\n storage: UserStorage | null,\n ): asserts storage is UserStorage {\n if (!storage) {\n throw new Error('User Storage does not exist');\n }\n }\n\n /**\n * Retrieves and parses the user storage from the storage key.\n *\n * This method attempts to retrieve the user storage using the specified storage key,\n * then parses the JSON string to an object. If the storage is not found or cannot be parsed,\n * it throws an error.\n *\n * @returns The parsed user storage object or null\n */\n async #getUserStorage(): Promise<UserStorage | null> {\n const userStorageString: string | null =\n await this.#storage.getNotificationStorage();\n\n if (!userStorageString) {\n return null;\n }\n\n try {\n const userStorage: UserStorage = JSON.parse(userStorageString);\n return userStorage;\n } catch (error) {\n log.error('Unable to parse User Storage');\n return null;\n }\n }\n\n /**\n * Retrieves the current enabled state of MetaMask notifications.\n *\n * This method directly returns the boolean value of `isMetamaskNotificationsEnabled`\n * from the controller's state, indicating whether MetaMask notifications are currently enabled.\n *\n * @returns The enabled state of MetaMask notifications.\n */\n public selectIsNotificationServicesEnabled(): boolean {\n return this.state.isNotificationServicesEnabled;\n }\n\n /**\n * Sets the state of notification creation process.\n *\n * This method updates the `isUpdatingMetamaskNotifications` state, which can be used to indicate\n * whether the notification creation process is currently active or not. This is useful\n * for UI elements that need to reflect the state of ongoing operations, such as loading\n * indicators or disabled buttons during processing.\n *\n * @param isUpdatingMetamaskNotifications - A boolean value representing the new state of the notification creation process.\n */\n #setIsUpdatingMetamaskNotifications(\n isUpdatingMetamaskNotifications: boolean,\n ) {\n this.update((state) => {\n state.isUpdatingMetamaskNotifications = isUpdatingMetamaskNotifications;\n });\n }\n\n /**\n * Updates the state to indicate whether fetching of MetaMask notifications is in progress.\n *\n * This method is used to set the `isFetchingMetamaskNotifications` state, which can be utilized\n * to show or hide loading indicators in the UI when notifications are being fetched.\n *\n * @param isFetchingMetamaskNotifications - A boolean value representing the fetching state.\n */\n #setIsFetchingMetamaskNotifications(\n isFetchingMetamaskNotifications: boolean,\n ) {\n this.update((state) => {\n state.isFetchingMetamaskNotifications = isFetchingMetamaskNotifications;\n });\n }\n\n /**\n * Updates the state to indicate that the checking of accounts presence is in progress.\n *\n * This method modifies the `isCheckingAccountsPresence` state, which can be used to manage UI elements\n * that depend on the status of account presence checks, such as displaying loading indicators or disabling\n * buttons while the check is ongoing.\n *\n * @param isCheckingAccountsPresence - A boolean value indicating whether the account presence check is currently active.\n */\n #setIsCheckingAccountsPresence(isCheckingAccountsPresence: boolean) {\n this.update((state) => {\n state.isCheckingAccountsPresence = isCheckingAccountsPresence;\n });\n }\n\n /**\n * Updates the state to indicate that account updates are in progress.\n * Removes duplicate accounts before updating the state.\n *\n * @param accounts - The accounts being updated.\n */\n #updateUpdatingAccountsState(accounts: string[]) {\n this.update((state) => {\n const uniqueAccounts = new Set([\n ...state.isUpdatingMetamaskNotificationsAccount,\n ...accounts,\n ]);\n state.isUpdatingMetamaskNotificationsAccount = Array.from(uniqueAccounts);\n });\n }\n\n /**\n * Clears the state indicating that account updates are complete.\n *\n * @param accounts - The accounts that have finished updating.\n */\n #clearUpdatingAccountsState(accounts: string[]) {\n this.update((state) => {\n state.isUpdatingMetamaskNotificationsAccount =\n state.isUpdatingMetamaskNotificationsAccount.filter(\n (existingAccount) => !accounts.includes(existingAccount),\n );\n });\n }\n\n public async checkAccountsPresence(\n accounts: string[],\n ): Promise<Record<string, boolean>> {\n try {\n this.#setIsCheckingAccountsPresence(true);\n\n // Retrieve user storage\n const userStorage = await this.#getUserStorage();\n this.#assertUserStorage(userStorage);\n\n const presence = Utils.checkAccountsPresence(userStorage, accounts);\n return presence;\n } catch (error) {\n log.error('Failed to check accounts presence', error);\n throw error;\n } finally {\n this.#setIsCheckingAccountsPresence(false);\n }\n }\n\n /**\n * Sets the enabled state of feature announcements.\n *\n * **Action** - used in the notification settings to enable/disable feature announcements.\n *\n * @param featureAnnouncementsEnabled - A boolean value indicating the desired enabled state of the feature announcements.\n * @async\n * @throws {Error} If fails to update\n */\n public async setFeatureAnnouncementsEnabled(\n featureAnnouncementsEnabled: boolean,\n ) {\n try {\n this.update((s) => {\n s.isFeatureAnnouncementsEnabled = featureAnnouncementsEnabled;\n });\n } catch (e) {\n log.error('Unable to toggle feature announcements', e);\n throw new Error('Unable to toggle feature announcements');\n }\n }\n\n /**\n * This creates/re-creates on-chain triggers defined in User Storage.\n *\n * **Action** - Used during Sign In / Enabling of notifications.\n *\n * @returns The updated or newly created user storage.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async createOnChainTriggers(): Promise<UserStorage> {\n try {\n this.#setIsUpdatingMetamaskNotifications(true);\n\n await this.#performEnableProfileSyncing();\n\n const { bearerToken, storageKey } =\n await this.#getValidStorageKeyAndBearerToken();\n\n const { accounts } = await this.#accounts.listAccounts();\n\n let userStorage = await this.#getUserStorage();\n\n // If userStorage does not exist, create a new one\n // All the triggers created are set as: \"disabled\"\n if (userStorage?.[USER_STORAGE_VERSION_KEY] === undefined) {\n userStorage = Utils.initializeUserStorage(\n accounts.map((account) => ({ address: account })),\n false,\n );\n\n // Write the userStorage\n await this.#storage.setNotificationStorage(JSON.stringify(userStorage));\n }\n\n // Create the triggers\n const triggers = Utils.traverseUserStorageTriggers(userStorage);\n await OnChainNotifications.createOnChainTriggers(\n userStorage,\n storageKey,\n bearerToken,\n triggers,\n );\n\n // Create push notifications triggers\n const allUUIDS = Utils.getAllUUIDs(userStorage);\n await this.#pushNotifications.enablePushNotifications(allUUIDS);\n\n // Write the new userStorage (triggers are now \"enabled\")\n await this.#storage.setNotificationStorage(JSON.stringify(userStorage));\n\n // Update the state of the controller\n this.update((state) => {\n state.isNotificationServicesEnabled = true;\n state.isFeatureAnnouncementsEnabled = true;\n state.isMetamaskNotificationsFeatureSeen = true;\n });\n\n return userStorage;\n } catch (err) {\n log.error('Failed to create On Chain triggers', err);\n throw new Error('Failed to create On Chain triggers');\n } finally {\n this.#setIsUpdatingMetamaskNotifications(false);\n }\n }\n\n /**\n * Enables all MetaMask notifications for the user.\n * This is identical flow when initializing notifications for the first time.\n * 1. Enable Profile Syncing\n * 2. Get or Create Notification User Storage\n * 3. Upsert Triggers\n * 4. Update Push notifications\n *\n * @throws {Error} If there is an error during the process of enabling notifications.\n */\n public async enableMetamaskNotifications() {\n try {\n this.#setIsUpdatingMetamaskNotifications(true);\n await this.createOnChainTriggers();\n } catch (e) {\n log.error('Unable to enable notifications', e);\n throw new Error('Unable to enable notifications');\n } finally {\n this.#setIsUpdatingMetamaskNotifications(false);\n }\n }\n\n /**\n * Disables all MetaMask notifications for the user.\n * This method ensures that the user is authenticated, retrieves all linked accounts,\n * and disables on-chain triggers for each account. It also sets the global notification\n * settings for MetaMask, feature announcements to false.\n *\n * @throws {Error} If the user is not authenticated or if there is an error during the process.\n */\n public async disableNotificationServices() {\n try {\n this.#setIsUpdatingMetamaskNotifications(true);\n\n // Disable Push Notifications\n const userStorage = await this.#getUserStorage();\n this.#assertUserStorage(userStorage);\n const UUIDs = Utils.getAllUUIDs(userStorage);\n await this.#pushNotifications.disablePushNotifications(UUIDs);\n\n // Clear Notification States (toggles and list)\n this.update((state) => {\n state.isNotificationServicesEnabled = false;\n state.isFeatureAnnouncementsEnabled = false;\n state.metamaskNotificationsList = [];\n });\n } catch (e) {\n log.error('Unable to disable notifications', e);\n throw new Error('Unable to disable notifications');\n } finally {\n this.#setIsUpdatingMetamaskNotifications(false);\n }\n }\n\n /**\n * Deletes on-chain triggers associated with a specific account.\n * This method performs several key operations:\n * 1. Validates Auth & Storage\n * 2. Finds and deletes all triggers associated with the account\n * 3. Disables any related push notifications\n * 4. Updates Storage to reflect new state.\n *\n * **Action** - When a user disables notifications for a given account in settings.\n *\n * @param accounts - The account for which on-chain triggers are to be deleted.\n * @returns A promise that resolves to void or an object containing a success message.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async deleteOnChainTriggersByAccount(\n accounts: string[],\n ): Promise<UserStorage> {\n try {\n this.#updateUpdatingAccountsState(accounts);\n // Get and Validate BearerToken and User Storage Key\n const { bearerToken, storageKey } =\n await this.#getValidStorageKeyAndBearerToken();\n\n // Get & Validate User Storage\n const userStorage = await this.#getUserStorage();\n this.#assertUserStorage(userStorage);\n\n // Get the UUIDs to delete\n const UUIDs = accounts\n .map((a) => Utils.getUUIDsForAccount(userStorage, a.toLowerCase()))\n .flat();\n\n if (UUIDs.length === 0) {\n return userStorage;\n }\n\n // Delete these UUIDs (Mutates User Storage)\n await OnChainNotifications.deleteOnChainTriggers(\n userStorage,\n storageKey,\n bearerToken,\n UUIDs,\n );\n\n // Delete these UUIDs from the push notifications\n await this.#pushNotifications.disablePushNotifications(UUIDs);\n\n // Update User Storage\n await this.#storage.setNotificationStorage(JSON.stringify(userStorage));\n return userStorage;\n } catch (err) {\n log.error('Failed to delete OnChain triggers', err);\n throw new Error('Failed to delete OnChain triggers');\n } finally {\n this.#clearUpdatingAccountsState(accounts);\n }\n }\n\n /**\n * Updates/Creates on-chain triggers for a specific account.\n *\n * This method performs several key operations:\n * 1. Validates Auth & Storage\n * 2. Finds and creates any missing triggers associated with the account\n * 3. Enables any related push notifications\n * 4. Updates Storage to reflect new state.\n *\n * **Action** - When a user enables notifications for an account\n *\n * @param accounts - List of accounts you want to update.\n * @returns A promise that resolves to the updated user storage.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async updateOnChainTriggersByAccount(\n accounts: string[],\n ): Promise<UserStorage> {\n try {\n this.#updateUpdatingAccountsState(accounts);\n // Get and Validate BearerToken and User Storage Key\n const { bearerToken, storageKey } =\n await this.#getValidStorageKeyAndBearerToken();\n\n // Get & Validate User Storage\n const userStorage = await this.#getUserStorage();\n this.#assertUserStorage(userStorage);\n\n // Add any missing triggers\n accounts.forEach((a) => Utils.upsertAddressTriggers(a, userStorage));\n\n const newTriggers = Utils.traverseUserStorageTriggers(userStorage, {\n mapTrigger: (t) => {\n if (!t.enabled) {\n return t;\n }\n return undefined;\n },\n });\n\n // Create any missing triggers.\n if (newTriggers.length > 0) {\n // Write te updated userStorage (where triggers are disabled)\n await this.#storage.setNotificationStorage(JSON.stringify(userStorage));\n\n // Create the triggers\n const triggers = Utils.traverseUserStorageTriggers(userStorage, {\n mapTrigger: (t) => {\n if (\n accounts.some((a) => a.toLowerCase() === t.address.toLowerCase())\n ) {\n return t;\n }\n return undefined;\n },\n });\n await OnChainNotifications.createOnChainTriggers(\n userStorage,\n storageKey,\n bearerToken,\n triggers,\n );\n }\n\n // Update Push Notifications Triggers\n const UUIDs = Utils.getAllUUIDs(userStorage);\n await this.#pushNotifications.updatePushNotifications(UUIDs);\n\n // Update the userStorage (where triggers are enabled)\n await this.#storage.setNotificationStorage(JSON.stringify(userStorage));\n return userStorage;\n } catch (err) {\n log.error('Failed to update OnChain triggers', err);\n throw new Error('Failed to update OnChain triggers');\n } finally {\n this.#clearUpdatingAccountsState(accounts);\n }\n }\n\n /**\n * Fetches the list of metamask notifications.\n * This includes OnChain notifications and Feature Announcements.\n *\n * **Action** - When a user views the notification list page/dropdown\n *\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\n public async fetchAndUpdateMetamaskNotifications(): Promise<INotification[]> {\n try {\n this.#setIsFetchingMetamaskNotifications(true);\n\n // Raw Feature Notifications\n const rawFeatureAnnouncementNotifications = this.state\n .isFeatureAnnouncementsEnabled\n ? await FeatureNotifications.getFeatureAnnouncementNotifications(\n this.#featureAnnouncementEnv,\n ).catch(() => [])\n : [];\n\n // Raw On Chain Notifications\n const rawOnChainNotifications: OnChainRawNotification[] = [];\n const userStorage = await this.#storage\n .getNotificationStorage()\n .then((s) => s && (JSON.parse(s) as UserStorage))\n .catch(() => null);\n const bearerToken = await this.#auth.getBearerToken().catch(() => null);\n if (userStorage && bearerToken) {\n const notifications =\n await OnChainNotifications.getOnChainNotifications(\n userStorage,\n bearerToken,\n ).catch(() => []);\n\n rawOnChainNotifications.push(...notifications);\n }\n\n const readIds = this.state.metamaskNotificationsReadList;\n\n // Combined Notifications\n const isNotUndefined = <Item>(t?: Item): t is Item => Boolean(t);\n const processAndFilter = (ns: NotificationUnion[]) =>\n ns\n .map((n) => safeProcessNotification(n, readIds))\n .filter(isNotUndefined);\n\n const featureAnnouncementNotifications = processAndFilter(\n rawFeatureAnnouncementNotifications,\n );\n const onChainNotifications = processAndFilter(rawOnChainNotifications);\n\n const metamaskNotifications: INotification[] = [\n ...featureAnnouncementNotifications,\n ...onChainNotifications,\n ];\n metamaskNotifications.sort(\n (a, b) =>\n new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),\n );\n\n // Update State\n this.update((state) => {\n state.metamaskNotificationsList = metamaskNotifications;\n });\n\n this.#setIsFetchingMetamaskNotifications(false);\n return metamaskNotifications;\n } catch (err) {\n this.#setIsFetchingMetamaskNotifications(false);\n log.error('Failed to fetch notifications', err);\n throw new Error('Failed to fetch notifications');\n }\n }\n\n /**\n * Marks specified metamask notifications as read.\n *\n * @param notifications - An array of notifications to be marked as read. Each notification should include its type and read status.\n * @returns A promise that resolves when the operation is complete.\n */\n public async markMetamaskNotificationsAsRead(\n notifications: MarkAsReadNotificationsParam,\n ): Promise<void> {\n let onchainNotificationIds: string[] = [];\n let featureAnnouncementNotificationIds: string[] = [];\n\n try {\n // Filter unread on/off chain notifications\n const onChainNotifications = notifications.filter(\n (notification) =>\n notification.type !== TRIGGER_TYPES.FEATURES_ANNOUNCEMENT &&\n !notification.isRead,\n );\n\n const featureAnnouncementNotifications = notifications.filter(\n (notification) =>\n notification.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT &&\n !notification.isRead,\n );\n\n // Mark On-Chain Notifications as Read\n if (onChainNotifications.length > 0) {\n const bearerToken = await this.#auth.getBearerToken();\n\n if (bearerToken) {\n onchainNotificationIds = onChainNotifications.map(\n (notification) => notification.id,\n );\n await OnChainNotifications.markNotificationsAsRead(\n bearerToken,\n onchainNotificationIds,\n ).catch(() => {\n onchainNotificationIds = [];\n log.warn('Unable to mark onchain notifications as read');\n });\n }\n }\n\n // Mark Off-Chain notifications as Read\n if (featureAnnouncementNotifications.length > 0) {\n featureAnnouncementNotificationIds =\n featureAnnouncementNotifications.map(\n (notification) => notification.id,\n );\n }\n } catch (err) {\n log.warn('Something failed when marking notifications as read', err);\n }\n\n // Update the state (state is also used on counter & badge)\n this.update((state) => {\n const currentReadList = state.metamaskNotificationsReadList;\n const newReadIds = [...featureAnnouncementNotificationIds];\n state.metamaskNotificationsReadList = [\n ...new Set([...currentReadList, ...newReadIds]),\n ];\n\n state.metamaskNotificationsList = state.metamaskNotificationsList.map(\n (notification: INotification) => {\n if (\n newReadIds.includes(notification.id) ||\n onchainNotificationIds.includes(notification.id)\n ) {\n return { ...notification, isRead: true };\n }\n return notification;\n },\n );\n });\n }\n\n /**\n * Updates the list of MetaMask notifications by adding a new notification at the beginning of the list.\n * This method ensures that the most recent notification is displayed first in the UI.\n *\n * @param notification - The new notification object to be added to the list.\n * @returns A promise that resolves when the notification list has been successfully updated.\n */\n public async updateMetamaskNotificationsList(\n notification: INotification,\n ): Promise<void> {\n if (\n this.state.metamaskNotificationsList.some((n) => n.id === notification.id)\n ) {\n return;\n }\n\n const processedNotification = safeProcessNotification(notification);\n\n if (processedNotification) {\n this.update((state) => {\n const existingNotificationIds = new Set(\n state.metamaskNotificationsList.map((n) => n.id),\n );\n // Add the new notification only if its ID is not already present in the list\n if (!existingNotificationIds.has(notification.id)) {\n state.metamaskNotificationsList = [\n notification,\n ...state.metamaskNotificationsList,\n ];\n }\n });\n }\n }\n}\n"]}
|