@metamask-previews/preferences-controller 13.0.2-preview-9edcf0e0 → 13.0.2-preview-9d310688

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/PreferencesController.cjs +333 -0
  2. package/dist/PreferencesController.cjs.map +1 -0
  3. package/dist/{types/PreferencesController.d.ts → PreferencesController.d.cts} +4 -4
  4. package/dist/PreferencesController.d.cts.map +1 -0
  5. package/dist/PreferencesController.d.mts +271 -0
  6. package/dist/PreferencesController.d.mts.map +1 -0
  7. package/dist/PreferencesController.mjs +326 -10
  8. package/dist/PreferencesController.mjs.map +1 -1
  9. package/dist/constants.cjs +26 -0
  10. package/dist/constants.cjs.map +1 -0
  11. package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
  12. package/dist/constants.d.cts.map +1 -0
  13. package/dist/constants.d.mts +23 -0
  14. package/dist/constants.d.mts.map +1 -0
  15. package/dist/constants.mjs +21 -5
  16. package/dist/constants.mjs.map +1 -1
  17. package/dist/index.cjs +21 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.cts +3 -0
  20. package/dist/index.d.cts.map +1 -0
  21. package/dist/index.d.mts +3 -0
  22. package/dist/index.d.mts.map +1 -0
  23. package/dist/index.mjs +2 -12
  24. package/dist/index.mjs.map +1 -1
  25. package/package.json +12 -7
  26. package/dist/PreferencesController.js +0 -12
  27. package/dist/PreferencesController.js.map +0 -1
  28. package/dist/chunk-FT2APC4J.mjs +0 -44
  29. package/dist/chunk-FT2APC4J.mjs.map +0 -1
  30. package/dist/chunk-KFN3X2JE.mjs +0 -347
  31. package/dist/chunk-KFN3X2JE.mjs.map +0 -1
  32. package/dist/chunk-POA2PUW4.js +0 -44
  33. package/dist/chunk-POA2PUW4.js.map +0 -1
  34. package/dist/chunk-Z2JUHJIP.js +0 -347
  35. package/dist/chunk-Z2JUHJIP.js.map +0 -1
  36. package/dist/constants.js +0 -7
  37. package/dist/constants.js.map +0 -1
  38. package/dist/index.js +0 -13
  39. package/dist/index.js.map +0 -1
  40. package/dist/tsconfig.build.tsbuildinfo +0 -1
  41. package/dist/types/PreferencesController.d.ts.map +0 -1
  42. package/dist/types/constants.d.ts.map +0 -1
  43. package/dist/types/index.d.ts +0 -3
  44. package/dist/types/index.d.ts.map +0 -1
@@ -0,0 +1,333 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _PreferencesController_instances, _PreferencesController_syncIdentities;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PreferencesController = exports.getDefaultPreferencesState = void 0;
10
+ const base_controller_1 = require("@metamask/base-controller");
11
+ const controller_utils_1 = require("@metamask/controller-utils");
12
+ const constants_1 = require("./constants.cjs");
13
+ const metadata = {
14
+ featureFlags: { persist: true, anonymous: true },
15
+ identities: { persist: true, anonymous: false },
16
+ ipfsGateway: { persist: true, anonymous: false },
17
+ isIpfsGatewayEnabled: { persist: true, anonymous: true },
18
+ isMultiAccountBalancesEnabled: { persist: true, anonymous: true },
19
+ lostIdentities: { persist: true, anonymous: false },
20
+ openSeaEnabled: { persist: true, anonymous: true },
21
+ securityAlertsEnabled: { persist: true, anonymous: true },
22
+ selectedAddress: { persist: true, anonymous: false },
23
+ showTestNetworks: { persist: true, anonymous: true },
24
+ showIncomingTransactions: { persist: true, anonymous: true },
25
+ useNftDetection: { persist: true, anonymous: true },
26
+ useTokenDetection: { persist: true, anonymous: true },
27
+ smartTransactionsOptInStatus: { persist: true, anonymous: false },
28
+ useTransactionSimulations: { persist: true, anonymous: true },
29
+ };
30
+ const name = 'PreferencesController';
31
+ /**
32
+ * Get the default PreferencesController state.
33
+ *
34
+ * @returns The default PreferencesController state.
35
+ */
36
+ function getDefaultPreferencesState() {
37
+ return {
38
+ featureFlags: {},
39
+ identities: {},
40
+ ipfsGateway: 'https://ipfs.io/ipfs/',
41
+ isIpfsGatewayEnabled: true,
42
+ isMultiAccountBalancesEnabled: true,
43
+ lostIdentities: {},
44
+ openSeaEnabled: false,
45
+ securityAlertsEnabled: false,
46
+ selectedAddress: '',
47
+ showIncomingTransactions: {
48
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MAINNET]: true,
49
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.GOERLI]: true,
50
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC]: true,
51
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC_TESTNET]: true,
52
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM]: true,
53
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM_SEPOLIA]: true,
54
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON]: true,
55
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON_TESTNET]: true,
56
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE]: true,
57
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE_TESTNET]: true,
58
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM]: true,
59
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM_TESTNET]: true,
60
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.SEPOLIA]: true,
61
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_GOERLI]: true,
62
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_SEPOLIA]: true,
63
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_MAINNET]: true,
64
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM]: true,
65
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM_TESTNET]: true,
66
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONRIVER]: true,
67
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.GNOSIS]: true,
68
+ },
69
+ showTestNetworks: false,
70
+ useNftDetection: false,
71
+ useTokenDetection: true,
72
+ smartTransactionsOptInStatus: false,
73
+ useTransactionSimulations: true,
74
+ };
75
+ }
76
+ exports.getDefaultPreferencesState = getDefaultPreferencesState;
77
+ /**
78
+ * Controller that stores shared settings and exposes convenience methods
79
+ */
80
+ class PreferencesController extends base_controller_1.BaseController {
81
+ /**
82
+ * Creates a PreferencesController instance.
83
+ *
84
+ * @param args - Arguments
85
+ * @param args.messenger - The preferences controller messenger.
86
+ * @param args.state - Preferences controller state.
87
+ */
88
+ constructor({ messenger, state, }) {
89
+ super({
90
+ name,
91
+ metadata,
92
+ messenger,
93
+ state: {
94
+ ...getDefaultPreferencesState(),
95
+ ...state,
96
+ },
97
+ });
98
+ _PreferencesController_instances.add(this);
99
+ messenger.subscribe('KeyringController:stateChange', (keyringState) => {
100
+ const accounts = new Set();
101
+ for (const keyring of keyringState.keyrings) {
102
+ for (const account of keyring.accounts) {
103
+ accounts.add(account);
104
+ }
105
+ }
106
+ if (accounts.size > 0) {
107
+ __classPrivateFieldGet(this, _PreferencesController_instances, "m", _PreferencesController_syncIdentities).call(this, Array.from(accounts));
108
+ }
109
+ });
110
+ }
111
+ /**
112
+ * Adds identities to state.
113
+ *
114
+ * @param addresses - List of addresses to use to generate new identities.
115
+ */
116
+ addIdentities(addresses) {
117
+ const checksummedAddresses = addresses.map((address) => (0, controller_utils_1.toChecksumHexAddress)(address));
118
+ this.update((state) => {
119
+ const { identities } = state;
120
+ for (const address of checksummedAddresses) {
121
+ if (identities[address]) {
122
+ continue;
123
+ }
124
+ const identityCount = Object.keys(identities).length;
125
+ identities[address] = {
126
+ name: `Account ${identityCount + 1}`,
127
+ address,
128
+ importTime: Date.now(),
129
+ };
130
+ }
131
+ });
132
+ }
133
+ /**
134
+ * Removes an identity from state.
135
+ *
136
+ * @param address - Address of the identity to remove.
137
+ */
138
+ removeIdentity(address) {
139
+ address = (0, controller_utils_1.toChecksumHexAddress)(address);
140
+ const { identities } = this.state;
141
+ if (!identities[address]) {
142
+ return;
143
+ }
144
+ this.update((state) => {
145
+ delete state.identities[address];
146
+ if (address === state.selectedAddress) {
147
+ state.selectedAddress = Object.keys(state.identities)[0];
148
+ }
149
+ });
150
+ }
151
+ /**
152
+ * Associates a new label with an identity.
153
+ *
154
+ * @param address - Address of the identity to associate.
155
+ * @param label - New label to assign.
156
+ */
157
+ setAccountLabel(address, label) {
158
+ address = (0, controller_utils_1.toChecksumHexAddress)(address);
159
+ this.update((state) => {
160
+ const identity = state.identities[address] || {};
161
+ identity.name = label;
162
+ state.identities[address] = identity;
163
+ });
164
+ }
165
+ /**
166
+ * Enable or disable a specific feature flag.
167
+ *
168
+ * @param feature - Feature to toggle.
169
+ * @param activated - Value to assign.
170
+ */
171
+ setFeatureFlag(feature, activated) {
172
+ this.update((state) => {
173
+ state.featureFlags[feature] = activated;
174
+ });
175
+ }
176
+ /**
177
+ * Sets selected address.
178
+ *
179
+ * @param selectedAddress - Ethereum address.
180
+ */
181
+ setSelectedAddress(selectedAddress) {
182
+ this.update((state) => {
183
+ state.selectedAddress = (0, controller_utils_1.toChecksumHexAddress)(selectedAddress);
184
+ });
185
+ }
186
+ /**
187
+ * Sets new IPFS gateway.
188
+ *
189
+ * @param ipfsGateway - IPFS gateway string.
190
+ */
191
+ setIpfsGateway(ipfsGateway) {
192
+ this.update((state) => {
193
+ state.ipfsGateway = ipfsGateway;
194
+ });
195
+ }
196
+ /**
197
+ * Toggle the token detection setting.
198
+ *
199
+ * @param useTokenDetection - Boolean indicating user preference on token detection.
200
+ */
201
+ setUseTokenDetection(useTokenDetection) {
202
+ this.update((state) => {
203
+ state.useTokenDetection = useTokenDetection;
204
+ });
205
+ }
206
+ /**
207
+ * Toggle the NFT detection setting.
208
+ *
209
+ * @param useNftDetection - Boolean indicating user preference on NFT detection.
210
+ */
211
+ setUseNftDetection(useNftDetection) {
212
+ if (useNftDetection && !this.state.openSeaEnabled) {
213
+ throw new Error('useNftDetection cannot be enabled if openSeaEnabled is false');
214
+ }
215
+ this.update((state) => {
216
+ state.useNftDetection = useNftDetection;
217
+ });
218
+ }
219
+ /**
220
+ * Toggle the opensea enabled setting.
221
+ *
222
+ * @param openSeaEnabled - Boolean indicating user preference on using OpenSea's API.
223
+ */
224
+ setOpenSeaEnabled(openSeaEnabled) {
225
+ this.update((state) => {
226
+ state.openSeaEnabled = openSeaEnabled;
227
+ if (!openSeaEnabled) {
228
+ state.useNftDetection = false;
229
+ }
230
+ });
231
+ }
232
+ /**
233
+ * Toggle the security alert enabled setting.
234
+ *
235
+ * @param securityAlertsEnabled - Boolean indicating user preference on using security alerts.
236
+ */
237
+ setSecurityAlertsEnabled(securityAlertsEnabled) {
238
+ this.update((state) => {
239
+ state.securityAlertsEnabled = securityAlertsEnabled;
240
+ });
241
+ }
242
+ /**
243
+ * A setter for the user preferences to enable/disable fetch of multiple accounts balance.
244
+ *
245
+ * @param isMultiAccountBalancesEnabled - true to enable multiple accounts balance fetch, false to fetch only selectedAddress.
246
+ */
247
+ setIsMultiAccountBalancesEnabled(isMultiAccountBalancesEnabled) {
248
+ this.update((state) => {
249
+ state.isMultiAccountBalancesEnabled = isMultiAccountBalancesEnabled;
250
+ });
251
+ }
252
+ /**
253
+ * A setter for the user have the test networks visible/hidden.
254
+ *
255
+ * @param showTestNetworks - true to show test networks, false to hidden.
256
+ */
257
+ setShowTestNetworks(showTestNetworks) {
258
+ this.update((state) => {
259
+ state.showTestNetworks = showTestNetworks;
260
+ });
261
+ }
262
+ /**
263
+ * A setter for the user allow to be fetched IPFS content
264
+ *
265
+ * @param isIpfsGatewayEnabled - true to enable ipfs source
266
+ */
267
+ setIsIpfsGatewayEnabled(isIpfsGatewayEnabled) {
268
+ this.update((state) => {
269
+ state.isIpfsGatewayEnabled = isIpfsGatewayEnabled;
270
+ });
271
+ }
272
+ /**
273
+ * A setter for the user allow to be fetched IPFS content
274
+ *
275
+ * @param chainId - On hexadecimal format to enable the incoming transaction network
276
+ * @param isIncomingTransactionNetworkEnable - true to enable incoming transactions
277
+ */
278
+ setEnableNetworkIncomingTransactions(chainId, isIncomingTransactionNetworkEnable) {
279
+ if (Object.values(constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS).includes(chainId)) {
280
+ this.update((state) => {
281
+ state.showIncomingTransactions = {
282
+ ...this.state.showIncomingTransactions,
283
+ [chainId]: isIncomingTransactionNetworkEnable,
284
+ };
285
+ });
286
+ }
287
+ }
288
+ /**
289
+ * A setter for the user to opt into smart transactions
290
+ *
291
+ * @param smartTransactionsOptInStatus - true to opt into smart transactions
292
+ */
293
+ setSmartTransactionsOptInStatus(smartTransactionsOptInStatus) {
294
+ this.update((state) => {
295
+ state.smartTransactionsOptInStatus = smartTransactionsOptInStatus;
296
+ });
297
+ }
298
+ /**
299
+ * A setter for the user preferences to enable/disable transaction simulations.
300
+ *
301
+ * @param useTransactionSimulations - true to enable transaction simulations, false to disable it.
302
+ */
303
+ setUseTransactionSimulations(useTransactionSimulations) {
304
+ this.update((state) => {
305
+ state.useTransactionSimulations = useTransactionSimulations;
306
+ });
307
+ }
308
+ }
309
+ exports.PreferencesController = PreferencesController;
310
+ _PreferencesController_instances = new WeakSet(), _PreferencesController_syncIdentities = function _PreferencesController_syncIdentities(addresses) {
311
+ addresses = addresses.map((address) => (0, controller_utils_1.toChecksumHexAddress)(address));
312
+ this.update((state) => {
313
+ const { identities } = state;
314
+ const newlyLost = {};
315
+ for (const [address, identity] of Object.entries(identities)) {
316
+ if (!addresses.includes(address)) {
317
+ newlyLost[address] = identity;
318
+ delete identities[address];
319
+ }
320
+ }
321
+ for (const [address, identity] of Object.entries(newlyLost)) {
322
+ state.lostIdentities[address] = identity;
323
+ }
324
+ });
325
+ this.addIdentities(addresses);
326
+ if (!addresses.includes(this.state.selectedAddress)) {
327
+ this.update((state) => {
328
+ state.selectedAddress = addresses[0];
329
+ });
330
+ }
331
+ };
332
+ exports.default = PreferencesController;
333
+ //# sourceMappingURL=PreferencesController.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PreferencesController.cjs","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+DAKmC;AACnC,iEAAkE;AAMlE,+CAA4D;AAsG5D,MAAM,QAAQ,GAAG;IACf,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IAChD,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IAC/C,WAAW,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IAChD,oBAAoB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IACxD,6BAA6B,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IACjE,cAAc,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IACnD,cAAc,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IAClD,qBAAqB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IACzD,eAAe,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IACpD,gBAAgB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IACpD,wBAAwB,EAAE,EAAE,OAAO,EAAE,IAAI,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,GAAG,QAAQ,CAAC;gBAC9B,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;aAC5B;SACF;QAED,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YAC3D,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC;SAC1C;IACH,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAE9B,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE;QACnD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;AAwJH,kBAAe,qBAAqB,CAAC","sourcesContent":["import {\n BaseController,\n type ControllerStateChangeEvent,\n type ControllerGetStateAction,\n type RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { toChecksumHexAddress } from '@metamask/controller-utils';\nimport type {\n KeyringControllerState,\n KeyringControllerStateChangeEvent,\n} from '@metamask/keyring-controller';\n\nimport { ETHERSCAN_SUPPORTED_CHAIN_IDS } from './constants';\n\n/**\n * A representation of a MetaMask identity\n */\nexport type Identity = {\n /**\n * The address of the identity\n */\n address: string;\n /**\n * The timestamp for when this identity was first added\n */\n importTime?: number;\n /**\n * The name of the identity\n */\n name: string;\n};\n\n/**\n * A type union of the name for each chain that is supported by Etherscan or\n * an Etherscan-compatible service.\n */\nexport type EtherscanSupportedChains =\n keyof typeof ETHERSCAN_SUPPORTED_CHAIN_IDS;\n\n/**\n * A type union of the chain ID for each chain that is supported by Etherscan\n * or an Etherscan-compatible service.\n */\nexport type EtherscanSupportedHexChainId =\n (typeof ETHERSCAN_SUPPORTED_CHAIN_IDS)[EtherscanSupportedChains];\n\n/**\n * Preferences controller state\n */\nexport type PreferencesState = {\n /**\n * Map of specific features to enable or disable\n */\n featureFlags: { [feature: string]: boolean };\n /**\n * Map of addresses to Identity objects\n */\n identities: { [address: string]: Identity };\n /**\n * The configured IPFS gateway\n */\n ipfsGateway: string;\n /**\n * Controls whether IPFS is enabled or not\n */\n isIpfsGatewayEnabled: boolean;\n /**\n * Controls whether multi-account balances are enabled or not\n */\n isMultiAccountBalancesEnabled: boolean;\n /**\n * Map of lost addresses to Identity objects\n */\n lostIdentities: { [address: string]: Identity };\n /**\n * Controls whether the OpenSea API is used\n */\n openSeaEnabled: boolean;\n /**\n * Controls whether \"security alerts\" are enabled\n */\n securityAlertsEnabled: boolean;\n /**\n * The current selected address\n */\n selectedAddress: string;\n /**\n * Controls whether incoming transactions are enabled, per-chain (for Etherscan-supported chains)\n */\n showIncomingTransactions: {\n [chainId in EtherscanSupportedHexChainId]: boolean;\n };\n /**\n * Controls whether test networks are shown in the wallet\n */\n showTestNetworks: boolean;\n /**\n * Controls whether NFT detection is enabled\n */\n useNftDetection: boolean;\n /**\n * Controls whether token detection is enabled\n */\n useTokenDetection: boolean;\n /**\n * Controls whether smart transactions are opted into\n */\n smartTransactionsOptInStatus: boolean;\n /**\n * Controls whether transaction simulations are enabled\n */\n useTransactionSimulations: boolean;\n};\n\nconst metadata = {\n featureFlags: { persist: true, anonymous: true },\n identities: { persist: true, anonymous: false },\n ipfsGateway: { persist: true, anonymous: false },\n isIpfsGatewayEnabled: { persist: true, anonymous: true },\n isMultiAccountBalancesEnabled: { persist: true, anonymous: true },\n lostIdentities: { persist: true, anonymous: false },\n openSeaEnabled: { persist: true, anonymous: true },\n securityAlertsEnabled: { persist: true, anonymous: true },\n selectedAddress: { persist: true, anonymous: false },\n showTestNetworks: { persist: true, anonymous: true },\n showIncomingTransactions: { persist: true, anonymous: true },\n useNftDetection: { persist: true, anonymous: true },\n useTokenDetection: { persist: true, anonymous: true },\n smartTransactionsOptInStatus: { persist: true, anonymous: false },\n useTransactionSimulations: { persist: true, anonymous: true },\n};\n\nconst name = 'PreferencesController';\n\nexport type PreferencesControllerGetStateAction = ControllerGetStateAction<\n typeof name,\n PreferencesState\n>;\n\nexport type PreferencesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof name,\n PreferencesState\n>;\n\nexport type PreferencesControllerActions = PreferencesControllerGetStateAction;\n\nexport type PreferencesControllerEvents = PreferencesControllerStateChangeEvent;\n\nexport type AllowedEvents = KeyringControllerStateChangeEvent;\n\nexport type PreferencesControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n PreferencesControllerActions,\n PreferencesControllerEvents | AllowedEvents,\n never,\n AllowedEvents['type']\n>;\n\n/**\n * Get the default PreferencesController state.\n *\n * @returns The default PreferencesController state.\n */\nexport function getDefaultPreferencesState() {\n return {\n featureFlags: {},\n identities: {},\n ipfsGateway: 'https://ipfs.io/ipfs/',\n isIpfsGatewayEnabled: true,\n isMultiAccountBalancesEnabled: true,\n lostIdentities: {},\n openSeaEnabled: false,\n securityAlertsEnabled: false,\n selectedAddress: '',\n showIncomingTransactions: {\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.MAINNET]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.GOERLI]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC_TESTNET]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM_SEPOLIA]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON_TESTNET]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE_TESTNET]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM_TESTNET]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.SEPOLIA]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_GOERLI]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_SEPOLIA]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_MAINNET]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM_TESTNET]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONRIVER]: true,\n [ETHERSCAN_SUPPORTED_CHAIN_IDS.GNOSIS]: true,\n },\n showTestNetworks: false,\n useNftDetection: false,\n useTokenDetection: true,\n smartTransactionsOptInStatus: false,\n useTransactionSimulations: true,\n };\n}\n\n/**\n * Controller that stores shared settings and exposes convenience methods\n */\nexport class PreferencesController extends BaseController<\n typeof name,\n PreferencesState,\n PreferencesControllerMessenger\n> {\n /**\n * Creates a PreferencesController instance.\n *\n * @param args - Arguments\n * @param args.messenger - The preferences controller messenger.\n * @param args.state - Preferences controller state.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: PreferencesControllerMessenger;\n state?: Partial<PreferencesState>;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: {\n ...getDefaultPreferencesState(),\n ...state,\n },\n });\n\n messenger.subscribe(\n 'KeyringController:stateChange',\n (keyringState: KeyringControllerState) => {\n const accounts = new Set<string>();\n for (const keyring of keyringState.keyrings) {\n for (const account of keyring.accounts) {\n accounts.add(account);\n }\n }\n if (accounts.size > 0) {\n this.#syncIdentities(Array.from(accounts));\n }\n },\n );\n }\n\n /**\n * Adds identities to state.\n *\n * @param addresses - List of addresses to use to generate new identities.\n */\n addIdentities(addresses: string[]) {\n const checksummedAddresses = addresses.map((address) =>\n toChecksumHexAddress(address),\n );\n this.update((state) => {\n const { identities } = state;\n for (const address of checksummedAddresses) {\n if (identities[address]) {\n continue;\n }\n const identityCount = Object.keys(identities).length;\n\n identities[address] = {\n name: `Account ${identityCount + 1}`,\n address,\n importTime: Date.now(),\n };\n }\n });\n }\n\n /**\n * Removes an identity from state.\n *\n * @param address - Address of the identity to remove.\n */\n removeIdentity(address: string) {\n address = toChecksumHexAddress(address);\n const { identities } = this.state;\n if (!identities[address]) {\n return;\n }\n this.update((state) => {\n delete state.identities[address];\n if (address === state.selectedAddress) {\n state.selectedAddress = Object.keys(state.identities)[0];\n }\n });\n }\n\n /**\n * Associates a new label with an identity.\n *\n * @param address - Address of the identity to associate.\n * @param label - New label to assign.\n */\n setAccountLabel(address: string, label: string) {\n address = toChecksumHexAddress(address);\n this.update((state) => {\n const identity = state.identities[address] || {};\n identity.name = label;\n state.identities[address] = identity;\n });\n }\n\n /**\n * Enable or disable a specific feature flag.\n *\n * @param feature - Feature to toggle.\n * @param activated - Value to assign.\n */\n setFeatureFlag(feature: string, activated: boolean) {\n this.update((state) => {\n state.featureFlags[feature] = activated;\n });\n }\n\n /**\n * Synchronizes the current identity list with new identities.\n *\n * @param addresses - List of addresses corresponding to identities to sync.\n */\n #syncIdentities(addresses: string[]) {\n addresses = addresses.map((address: string) =>\n toChecksumHexAddress(address),\n );\n\n this.update((state) => {\n const { identities } = state;\n const newlyLost: { [address: string]: Identity } = {};\n\n for (const [address, identity] of Object.entries(identities)) {\n if (!addresses.includes(address)) {\n newlyLost[address] = identity;\n delete identities[address];\n }\n }\n\n for (const [address, identity] of Object.entries(newlyLost)) {\n state.lostIdentities[address] = identity;\n }\n });\n this.addIdentities(addresses);\n\n if (!addresses.includes(this.state.selectedAddress)) {\n this.update((state) => {\n state.selectedAddress = addresses[0];\n });\n }\n }\n\n /**\n * Sets selected address.\n *\n * @param selectedAddress - Ethereum address.\n */\n setSelectedAddress(selectedAddress: string) {\n this.update((state) => {\n state.selectedAddress = toChecksumHexAddress(selectedAddress);\n });\n }\n\n /**\n * Sets new IPFS gateway.\n *\n * @param ipfsGateway - IPFS gateway string.\n */\n setIpfsGateway(ipfsGateway: string) {\n this.update((state) => {\n state.ipfsGateway = ipfsGateway;\n });\n }\n\n /**\n * Toggle the token detection setting.\n *\n * @param useTokenDetection - Boolean indicating user preference on token detection.\n */\n setUseTokenDetection(useTokenDetection: boolean) {\n this.update((state) => {\n state.useTokenDetection = useTokenDetection;\n });\n }\n\n /**\n * Toggle the NFT detection setting.\n *\n * @param useNftDetection - Boolean indicating user preference on NFT detection.\n */\n setUseNftDetection(useNftDetection: boolean) {\n if (useNftDetection && !this.state.openSeaEnabled) {\n throw new Error(\n 'useNftDetection cannot be enabled if openSeaEnabled is false',\n );\n }\n this.update((state) => {\n state.useNftDetection = useNftDetection;\n });\n }\n\n /**\n * Toggle the opensea enabled setting.\n *\n * @param openSeaEnabled - Boolean indicating user preference on using OpenSea's API.\n */\n setOpenSeaEnabled(openSeaEnabled: boolean) {\n this.update((state) => {\n state.openSeaEnabled = openSeaEnabled;\n if (!openSeaEnabled) {\n state.useNftDetection = false;\n }\n });\n }\n\n /**\n * Toggle the security alert enabled setting.\n *\n * @param securityAlertsEnabled - Boolean indicating user preference on using security alerts.\n */\n setSecurityAlertsEnabled(securityAlertsEnabled: boolean) {\n this.update((state) => {\n state.securityAlertsEnabled = securityAlertsEnabled;\n });\n }\n\n /**\n * A setter for the user preferences to enable/disable fetch of multiple accounts balance.\n *\n * @param isMultiAccountBalancesEnabled - true to enable multiple accounts balance fetch, false to fetch only selectedAddress.\n */\n setIsMultiAccountBalancesEnabled(isMultiAccountBalancesEnabled: boolean) {\n this.update((state) => {\n state.isMultiAccountBalancesEnabled = isMultiAccountBalancesEnabled;\n });\n }\n\n /**\n * A setter for the user have the test networks visible/hidden.\n *\n * @param showTestNetworks - true to show test networks, false to hidden.\n */\n setShowTestNetworks(showTestNetworks: boolean) {\n this.update((state) => {\n state.showTestNetworks = showTestNetworks;\n });\n }\n\n /**\n * A setter for the user allow to be fetched IPFS content\n *\n * @param isIpfsGatewayEnabled - true to enable ipfs source\n */\n setIsIpfsGatewayEnabled(isIpfsGatewayEnabled: boolean) {\n this.update((state) => {\n state.isIpfsGatewayEnabled = isIpfsGatewayEnabled;\n });\n }\n\n /**\n * A setter for the user allow to be fetched IPFS content\n *\n * @param chainId - On hexadecimal format to enable the incoming transaction network\n * @param isIncomingTransactionNetworkEnable - true to enable incoming transactions\n */\n setEnableNetworkIncomingTransactions(\n chainId: EtherscanSupportedHexChainId,\n isIncomingTransactionNetworkEnable: boolean,\n ) {\n if (Object.values(ETHERSCAN_SUPPORTED_CHAIN_IDS).includes(chainId)) {\n this.update((state) => {\n state.showIncomingTransactions = {\n ...this.state.showIncomingTransactions,\n [chainId]: isIncomingTransactionNetworkEnable,\n };\n });\n }\n }\n\n /**\n * A setter for the user to opt into smart transactions\n *\n * @param smartTransactionsOptInStatus - true to opt into smart transactions\n */\n setSmartTransactionsOptInStatus(smartTransactionsOptInStatus: boolean) {\n this.update((state) => {\n state.smartTransactionsOptInStatus = smartTransactionsOptInStatus;\n });\n }\n\n /**\n * A setter for the user preferences to enable/disable transaction simulations.\n *\n * @param useTransactionSimulations - true to enable transaction simulations, false to disable it.\n */\n setUseTransactionSimulations(useTransactionSimulations: boolean) {\n this.update((state) => {\n state.useTransactionSimulations = useTransactionSimulations;\n });\n }\n}\n\nexport default PreferencesController;\n"]}
@@ -1,6 +1,6 @@
1
- import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction, type RestrictedControllerMessenger } from '@metamask/base-controller';
2
- import type { KeyringControllerStateChangeEvent } from '@metamask/keyring-controller';
3
- import { ETHERSCAN_SUPPORTED_CHAIN_IDS } from './constants';
1
+ import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction, type RestrictedControllerMessenger } from "@metamask/base-controller";
2
+ import type { KeyringControllerStateChangeEvent } from "@metamask/keyring-controller";
3
+ import { ETHERSCAN_SUPPORTED_CHAIN_IDS } from "./constants.cjs";
4
4
  /**
5
5
  * A representation of a MetaMask identity
6
6
  */
@@ -268,4 +268,4 @@ export declare class PreferencesController extends BaseController<typeof name, P
268
268
  setUseTransactionSimulations(useTransactionSimulations: boolean): void;
269
269
  }
270
270
  export default PreferencesController;
271
- //# sourceMappingURL=PreferencesController.d.ts.map
271
+ //# sourceMappingURL=PreferencesController.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PreferencesController.d.cts","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,EACnC,kCAAkC;AAEnC,OAAO,KAAK,EAEV,iCAAiC,EAClC,qCAAqC;AAEtC,OAAO,EAAE,6BAA6B,EAAE,wBAAoB;AAE5D;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAClC,MAAM,OAAO,6BAA6B,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GACtC,CAAC,OAAO,6BAA6B,CAAC,CAAC,wBAAwB,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,YAAY,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC7C;;OAEG;IACH,UAAU,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE,CAAC;IAC5C;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAC9B;;OAEG;IACH,6BAA6B,EAAE,OAAO,CAAC;IACvC;;OAEG;IACH,cAAc,EAAE;QAAE,CAAC,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K,GACN,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,KAAK,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;KACnC;IA2BD;;;;OAIG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE;IAqBjC;;;;OAIG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM;IAc9B;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAS9C;;;;;OAKG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO;IAwClD;;;;OAIG;IACH,kBAAkB,CAAC,eAAe,EAAE,MAAM;IAM1C;;;;OAIG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM;IAMlC;;;;OAIG;IACH,oBAAoB,CAAC,iBAAiB,EAAE,OAAO;IAM/C;;;;OAIG;IACH,kBAAkB,CAAC,eAAe,EAAE,OAAO;IAW3C;;;;OAIG;IACH,iBAAiB,CAAC,cAAc,EAAE,OAAO;IASzC;;;;OAIG;IACH,wBAAwB,CAAC,qBAAqB,EAAE,OAAO;IAMvD;;;;OAIG;IACH,gCAAgC,CAAC,6BAA6B,EAAE,OAAO;IAMvE;;;;OAIG;IACH,mBAAmB,CAAC,gBAAgB,EAAE,OAAO;IAM7C;;;;OAIG;IACH,uBAAuB,CAAC,oBAAoB,EAAE,OAAO;IAMrD;;;;;OAKG;IACH,oCAAoC,CAClC,OAAO,EAAE,4BAA4B,EACrC,kCAAkC,EAAE,OAAO;IAY7C;;;;OAIG;IACH,+BAA+B,CAAC,4BAA4B,EAAE,OAAO;IAMrE;;;;OAIG;IACH,4BAA4B,CAAC,yBAAyB,EAAE,OAAO;CAKhE;AAED,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,271 @@
1
+ import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction, type RestrictedControllerMessenger } from "@metamask/base-controller";
2
+ import type { KeyringControllerStateChangeEvent } from "@metamask/keyring-controller";
3
+ import { ETHERSCAN_SUPPORTED_CHAIN_IDS } from "./constants.mjs";
4
+ /**
5
+ * A representation of a MetaMask identity
6
+ */
7
+ export type Identity = {
8
+ /**
9
+ * The address of the identity
10
+ */
11
+ address: string;
12
+ /**
13
+ * The timestamp for when this identity was first added
14
+ */
15
+ importTime?: number;
16
+ /**
17
+ * The name of the identity
18
+ */
19
+ name: string;
20
+ };
21
+ /**
22
+ * A type union of the name for each chain that is supported by Etherscan or
23
+ * an Etherscan-compatible service.
24
+ */
25
+ export type EtherscanSupportedChains = keyof typeof ETHERSCAN_SUPPORTED_CHAIN_IDS;
26
+ /**
27
+ * A type union of the chain ID for each chain that is supported by Etherscan
28
+ * or an Etherscan-compatible service.
29
+ */
30
+ export type EtherscanSupportedHexChainId = (typeof ETHERSCAN_SUPPORTED_CHAIN_IDS)[EtherscanSupportedChains];
31
+ /**
32
+ * Preferences controller state
33
+ */
34
+ export type PreferencesState = {
35
+ /**
36
+ * Map of specific features to enable or disable
37
+ */
38
+ featureFlags: {
39
+ [feature: string]: boolean;
40
+ };
41
+ /**
42
+ * Map of addresses to Identity objects
43
+ */
44
+ identities: {
45
+ [address: string]: Identity;
46
+ };
47
+ /**
48
+ * The configured IPFS gateway
49
+ */
50
+ ipfsGateway: string;
51
+ /**
52
+ * Controls whether IPFS is enabled or not
53
+ */
54
+ isIpfsGatewayEnabled: boolean;
55
+ /**
56
+ * Controls whether multi-account balances are enabled or not
57
+ */
58
+ isMultiAccountBalancesEnabled: boolean;
59
+ /**
60
+ * Map of lost addresses to Identity objects
61
+ */
62
+ lostIdentities: {
63
+ [address: string]: Identity;
64
+ };
65
+ /**
66
+ * Controls whether the OpenSea API is used
67
+ */
68
+ openSeaEnabled: boolean;
69
+ /**
70
+ * Controls whether "security alerts" are enabled
71
+ */
72
+ securityAlertsEnabled: boolean;
73
+ /**
74
+ * The current selected address
75
+ */
76
+ selectedAddress: string;
77
+ /**
78
+ * Controls whether incoming transactions are enabled, per-chain (for Etherscan-supported chains)
79
+ */
80
+ showIncomingTransactions: {
81
+ [chainId in EtherscanSupportedHexChainId]: boolean;
82
+ };
83
+ /**
84
+ * Controls whether test networks are shown in the wallet
85
+ */
86
+ showTestNetworks: boolean;
87
+ /**
88
+ * Controls whether NFT detection is enabled
89
+ */
90
+ useNftDetection: boolean;
91
+ /**
92
+ * Controls whether token detection is enabled
93
+ */
94
+ useTokenDetection: boolean;
95
+ /**
96
+ * Controls whether smart transactions are opted into
97
+ */
98
+ smartTransactionsOptInStatus: boolean;
99
+ /**
100
+ * Controls whether transaction simulations are enabled
101
+ */
102
+ useTransactionSimulations: boolean;
103
+ };
104
+ declare const name = "PreferencesController";
105
+ export type PreferencesControllerGetStateAction = ControllerGetStateAction<typeof name, PreferencesState>;
106
+ export type PreferencesControllerStateChangeEvent = ControllerStateChangeEvent<typeof name, PreferencesState>;
107
+ export type PreferencesControllerActions = PreferencesControllerGetStateAction;
108
+ export type PreferencesControllerEvents = PreferencesControllerStateChangeEvent;
109
+ export type AllowedEvents = KeyringControllerStateChangeEvent;
110
+ export type PreferencesControllerMessenger = RestrictedControllerMessenger<typeof name, PreferencesControllerActions, PreferencesControllerEvents | AllowedEvents, never, AllowedEvents['type']>;
111
+ /**
112
+ * Get the default PreferencesController state.
113
+ *
114
+ * @returns The default PreferencesController state.
115
+ */
116
+ export declare function getDefaultPreferencesState(): {
117
+ featureFlags: {};
118
+ identities: {};
119
+ ipfsGateway: string;
120
+ isIpfsGatewayEnabled: boolean;
121
+ isMultiAccountBalancesEnabled: boolean;
122
+ lostIdentities: {};
123
+ openSeaEnabled: boolean;
124
+ securityAlertsEnabled: boolean;
125
+ selectedAddress: string;
126
+ showIncomingTransactions: {
127
+ "0x1": boolean;
128
+ "0x5": boolean;
129
+ "0x38": boolean;
130
+ "0x61": boolean;
131
+ "0xa": boolean;
132
+ "0xaa37dc": boolean;
133
+ "0x89": boolean;
134
+ "0x13881": boolean;
135
+ "0xa86a": boolean;
136
+ "0xa869": boolean;
137
+ "0xfa": boolean;
138
+ "0xfa2": boolean;
139
+ "0xaa36a7": boolean;
140
+ "0xe704": boolean;
141
+ "0xe705": boolean;
142
+ "0xe708": boolean;
143
+ "0x504": boolean;
144
+ "0x507": boolean;
145
+ "0x505": boolean;
146
+ "0x64": boolean;
147
+ };
148
+ showTestNetworks: boolean;
149
+ useNftDetection: boolean;
150
+ useTokenDetection: boolean;
151
+ smartTransactionsOptInStatus: boolean;
152
+ useTransactionSimulations: boolean;
153
+ };
154
+ /**
155
+ * Controller that stores shared settings and exposes convenience methods
156
+ */
157
+ export declare class PreferencesController extends BaseController<typeof name, PreferencesState, PreferencesControllerMessenger> {
158
+ #private;
159
+ /**
160
+ * Creates a PreferencesController instance.
161
+ *
162
+ * @param args - Arguments
163
+ * @param args.messenger - The preferences controller messenger.
164
+ * @param args.state - Preferences controller state.
165
+ */
166
+ constructor({ messenger, state, }: {
167
+ messenger: PreferencesControllerMessenger;
168
+ state?: Partial<PreferencesState>;
169
+ });
170
+ /**
171
+ * Adds identities to state.
172
+ *
173
+ * @param addresses - List of addresses to use to generate new identities.
174
+ */
175
+ addIdentities(addresses: string[]): void;
176
+ /**
177
+ * Removes an identity from state.
178
+ *
179
+ * @param address - Address of the identity to remove.
180
+ */
181
+ removeIdentity(address: string): void;
182
+ /**
183
+ * Associates a new label with an identity.
184
+ *
185
+ * @param address - Address of the identity to associate.
186
+ * @param label - New label to assign.
187
+ */
188
+ setAccountLabel(address: string, label: string): void;
189
+ /**
190
+ * Enable or disable a specific feature flag.
191
+ *
192
+ * @param feature - Feature to toggle.
193
+ * @param activated - Value to assign.
194
+ */
195
+ setFeatureFlag(feature: string, activated: boolean): void;
196
+ /**
197
+ * Sets selected address.
198
+ *
199
+ * @param selectedAddress - Ethereum address.
200
+ */
201
+ setSelectedAddress(selectedAddress: string): void;
202
+ /**
203
+ * Sets new IPFS gateway.
204
+ *
205
+ * @param ipfsGateway - IPFS gateway string.
206
+ */
207
+ setIpfsGateway(ipfsGateway: string): void;
208
+ /**
209
+ * Toggle the token detection setting.
210
+ *
211
+ * @param useTokenDetection - Boolean indicating user preference on token detection.
212
+ */
213
+ setUseTokenDetection(useTokenDetection: boolean): void;
214
+ /**
215
+ * Toggle the NFT detection setting.
216
+ *
217
+ * @param useNftDetection - Boolean indicating user preference on NFT detection.
218
+ */
219
+ setUseNftDetection(useNftDetection: boolean): void;
220
+ /**
221
+ * Toggle the opensea enabled setting.
222
+ *
223
+ * @param openSeaEnabled - Boolean indicating user preference on using OpenSea's API.
224
+ */
225
+ setOpenSeaEnabled(openSeaEnabled: boolean): void;
226
+ /**
227
+ * Toggle the security alert enabled setting.
228
+ *
229
+ * @param securityAlertsEnabled - Boolean indicating user preference on using security alerts.
230
+ */
231
+ setSecurityAlertsEnabled(securityAlertsEnabled: boolean): void;
232
+ /**
233
+ * A setter for the user preferences to enable/disable fetch of multiple accounts balance.
234
+ *
235
+ * @param isMultiAccountBalancesEnabled - true to enable multiple accounts balance fetch, false to fetch only selectedAddress.
236
+ */
237
+ setIsMultiAccountBalancesEnabled(isMultiAccountBalancesEnabled: boolean): void;
238
+ /**
239
+ * A setter for the user have the test networks visible/hidden.
240
+ *
241
+ * @param showTestNetworks - true to show test networks, false to hidden.
242
+ */
243
+ setShowTestNetworks(showTestNetworks: boolean): void;
244
+ /**
245
+ * A setter for the user allow to be fetched IPFS content
246
+ *
247
+ * @param isIpfsGatewayEnabled - true to enable ipfs source
248
+ */
249
+ setIsIpfsGatewayEnabled(isIpfsGatewayEnabled: boolean): void;
250
+ /**
251
+ * A setter for the user allow to be fetched IPFS content
252
+ *
253
+ * @param chainId - On hexadecimal format to enable the incoming transaction network
254
+ * @param isIncomingTransactionNetworkEnable - true to enable incoming transactions
255
+ */
256
+ setEnableNetworkIncomingTransactions(chainId: EtherscanSupportedHexChainId, isIncomingTransactionNetworkEnable: boolean): void;
257
+ /**
258
+ * A setter for the user to opt into smart transactions
259
+ *
260
+ * @param smartTransactionsOptInStatus - true to opt into smart transactions
261
+ */
262
+ setSmartTransactionsOptInStatus(smartTransactionsOptInStatus: boolean): void;
263
+ /**
264
+ * A setter for the user preferences to enable/disable transaction simulations.
265
+ *
266
+ * @param useTransactionSimulations - true to enable transaction simulations, false to disable it.
267
+ */
268
+ setUseTransactionSimulations(useTransactionSimulations: boolean): void;
269
+ }
270
+ export default PreferencesController;
271
+ //# sourceMappingURL=PreferencesController.d.mts.map