@metamask-previews/preferences-controller 4.3.0-preview.3dbf14f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,67 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [4.3.0]
10
+ ### Added
11
+ - Add preference for security alerts ([#1589](https://github.com/MetaMask/core/pull/1589))
12
+
13
+ ## [4.2.0]
14
+ ### Added
15
+ - Add controller state property `showTestNetworks` along with a setter method, `setShowTestNetworks` ([#1418](https://github.com/MetaMask/core/pull/1418))
16
+
17
+ ## [4.1.0]
18
+ ### Added
19
+ - Add `isMultiAccountBalancesEnabled` to state (default: true) along with a `setIsMultiAccountBalancesEnabled` method to set it
20
+
21
+ ## [4.0.0]
22
+ ### Changed
23
+ - **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
24
+
25
+ ## [3.0.0]
26
+ ### Changed
27
+ - **BREAKING:** Migrate network configurations from `PreferencesController` to `NetworkController` ([#1064](https://github.com/MetaMask/core/pull/1064))
28
+ - Consumers will need to adapt by reading network data from `NetworkConfigurations` state on `NetworkController` rather than `frequentRpcList` on `PreferencesController`. See `NetworkController` v6.0.0 changelog entry for more details.
29
+
30
+ ## [2.1.0]
31
+ ### Added
32
+ - `disabledRpcMethodPreferences` state to PreferencesController ([#1109](https://github.com/MetaMask/core/pull/1109)). See [this PR on extension](https://github.com/MetaMask/metamask-extension/pull/17308) and [this ticket](https://github.com/MetaMask/metamask-mobile/issues/5676)
33
+
34
+ ## [2.0.0]
35
+ ### Removed
36
+ - **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))
37
+ - Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`
38
+
39
+ ## [1.0.2]
40
+ ### Changed
41
+ - Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
42
+ - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
43
+
44
+ ## [1.0.1]
45
+ ### Changed
46
+ - Relax dependencies on `@metamask/base-controller` and `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
47
+
48
+ ## [1.0.0]
49
+ ### Added
50
+ - Initial release
51
+ - As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/core/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/core/tree/v33.0.0), namely:
52
+ - `src/user/PreferencesController.ts` (plus `ContactEntry` copied from `src/user/AddressBookController.ts`)
53
+ - `src/user/PreferencesController.test.ts`
54
+
55
+ All changes listed after this point were applied to this package following the monorepo conversion.
56
+
57
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.3.0...HEAD
58
+ [4.3.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.2.0...@metamask/preferences-controller@4.3.0
59
+ [4.2.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.1.0...@metamask/preferences-controller@4.2.0
60
+ [4.1.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.0.0...@metamask/preferences-controller@4.1.0
61
+ [4.0.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@3.0.0...@metamask/preferences-controller@4.0.0
62
+ [3.0.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@2.1.0...@metamask/preferences-controller@3.0.0
63
+ [2.1.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@2.0.0...@metamask/preferences-controller@2.1.0
64
+ [2.0.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@1.0.2...@metamask/preferences-controller@2.0.0
65
+ [1.0.2]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@1.0.1...@metamask/preferences-controller@1.0.2
66
+ [1.0.1]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@1.0.0...@metamask/preferences-controller@1.0.1
67
+ [1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/preferences-controller@1.0.0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 MetaMask
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # `@metamask/preferences-controller`
2
+
3
+ Manages user-configurable settings for MetaMask.
4
+
5
+ ## Installation
6
+
7
+ `yarn add @metamask/preferences-controller`
8
+
9
+ or
10
+
11
+ `npm install @metamask/preferences-controller`
12
+
13
+ ## Contributing
14
+
15
+ This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
@@ -0,0 +1,166 @@
1
+ import type { BaseConfig, BaseState } from '@metamask/base-controller';
2
+ import { BaseController } from '@metamask/base-controller';
3
+ /**
4
+ * ContactEntry representation.
5
+ *
6
+ * @property address - Hex address of a recipient account
7
+ * @property name - Nickname associated with this address
8
+ * @property importTime - Data time when an account as created/imported
9
+ */
10
+ export interface ContactEntry {
11
+ address: string;
12
+ name: string;
13
+ importTime?: number;
14
+ }
15
+ /**
16
+ * @type PreferencesState
17
+ *
18
+ * Preferences controller state
19
+ * @property featureFlags - Map of specific features to enable or disable
20
+ * @property identities - Map of addresses to ContactEntry objects
21
+ * @property lostIdentities - Map of lost addresses to ContactEntry objects
22
+ * @property selectedAddress - Current coinbase account
23
+ */
24
+ export interface PreferencesState extends BaseState {
25
+ featureFlags: {
26
+ [feature: string]: boolean;
27
+ };
28
+ ipfsGateway: string;
29
+ identities: {
30
+ [address: string]: ContactEntry;
31
+ };
32
+ lostIdentities: {
33
+ [address: string]: ContactEntry;
34
+ };
35
+ selectedAddress: string;
36
+ useTokenDetection: boolean;
37
+ useNftDetection: boolean;
38
+ openSeaEnabled: boolean;
39
+ securityAlertsEnabled: boolean;
40
+ isMultiAccountBalancesEnabled: boolean;
41
+ disabledRpcMethodPreferences: {
42
+ [methodName: string]: boolean;
43
+ };
44
+ showTestNetworks: boolean;
45
+ isIpfsGatewayEnabled: boolean;
46
+ }
47
+ /**
48
+ * Controller that stores shared settings and exposes convenience methods
49
+ */
50
+ export declare class PreferencesController extends BaseController<BaseConfig, PreferencesState> {
51
+ /**
52
+ * Name of this controller used during composition
53
+ */
54
+ name: string;
55
+ /**
56
+ * Creates a PreferencesController instance.
57
+ *
58
+ * @param config - Initial options used to configure this controller.
59
+ * @param state - Initial state to set on this controller.
60
+ */
61
+ constructor(config?: Partial<BaseConfig>, state?: Partial<PreferencesState>);
62
+ /**
63
+ * Adds identities to state.
64
+ *
65
+ * @param addresses - List of addresses to use to generate new identities.
66
+ */
67
+ addIdentities(addresses: string[]): void;
68
+ /**
69
+ * Removes an identity from state.
70
+ *
71
+ * @param address - Address of the identity to remove.
72
+ */
73
+ removeIdentity(address: string): void;
74
+ /**
75
+ * Associates a new label with an identity.
76
+ *
77
+ * @param address - Address of the identity to associate.
78
+ * @param label - New label to assign.
79
+ */
80
+ setAccountLabel(address: string, label: string): void;
81
+ /**
82
+ * Enable or disable a specific feature flag.
83
+ *
84
+ * @param feature - Feature to toggle.
85
+ * @param activated - Value to assign.
86
+ */
87
+ setFeatureFlag(feature: string, activated: boolean): void;
88
+ /**
89
+ * Synchronizes the current identity list with new identities.
90
+ *
91
+ * @param addresses - List of addresses corresponding to identities to sync.
92
+ * @returns Newly-selected address after syncing.
93
+ */
94
+ syncIdentities(addresses: string[]): string;
95
+ /**
96
+ * Generates and stores a new list of stored identities based on address. If the selected address
97
+ * is unset, or if it refers to an identity that was removed, it will be set to the first
98
+ * identity.
99
+ *
100
+ * @param addresses - List of addresses to use as a basis for each identity.
101
+ */
102
+ updateIdentities(addresses: string[]): void;
103
+ /**
104
+ * Sets selected address.
105
+ *
106
+ * @param selectedAddress - Ethereum address.
107
+ */
108
+ setSelectedAddress(selectedAddress: string): void;
109
+ /**
110
+ * Sets new IPFS gateway.
111
+ *
112
+ * @param ipfsGateway - IPFS gateway string.
113
+ */
114
+ setIpfsGateway(ipfsGateway: string): void;
115
+ /**
116
+ * Toggle the token detection setting.
117
+ *
118
+ * @param useTokenDetection - Boolean indicating user preference on token detection.
119
+ */
120
+ setUseTokenDetection(useTokenDetection: boolean): void;
121
+ /**
122
+ * Toggle the NFT detection setting.
123
+ *
124
+ * @param useNftDetection - Boolean indicating user preference on NFT detection.
125
+ */
126
+ setUseNftDetection(useNftDetection: boolean): void;
127
+ /**
128
+ * Toggle the opensea enabled setting.
129
+ *
130
+ * @param openSeaEnabled - Boolean indicating user preference on using OpenSea's API.
131
+ */
132
+ setOpenSeaEnabled(openSeaEnabled: boolean): void;
133
+ /**
134
+ * Toggle the security alert enabled setting.
135
+ *
136
+ * @param securityAlertsEnabled - Boolean indicating user preference on using security alerts.
137
+ */
138
+ setSecurityAlertsEnabled(securityAlertsEnabled: boolean): void;
139
+ /**
140
+ * A setter for the user preferences to enable/disable rpc methods.
141
+ *
142
+ * @param methodName - The RPC method name to change the setting of.
143
+ * @param isEnabled - true to enable the rpc method, false to disable it.
144
+ */
145
+ setDisabledRpcMethodPreference(methodName: string, isEnabled: boolean): void;
146
+ /**
147
+ * A setter for the user preferences to enable/disable fetch of multiple accounts balance.
148
+ *
149
+ * @param isMultiAccountBalancesEnabled - true to enable multiple accounts balance fetch, false to fetch only selectedAddress.
150
+ */
151
+ setIsMultiAccountBalancesEnabled(isMultiAccountBalancesEnabled: boolean): void;
152
+ /**
153
+ * A setter for the user have the test networks visible/hidden.
154
+ *
155
+ * @param showTestNetworks - true to show test networks, false to hidden.
156
+ */
157
+ setShowTestNetworks(showTestNetworks: boolean): void;
158
+ /**
159
+ * A setter for the user allow to be fetched IPFS content
160
+ *
161
+ * @param isIpfsGatewayEnabled - true to enable ipfs source
162
+ */
163
+ setIsIpfsGatewayEnabled(isIpfsGatewayEnabled: boolean): void;
164
+ }
165
+ export default PreferencesController;
166
+ //# sourceMappingURL=PreferencesController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PreferencesController.d.ts","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD,YAAY,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC7C,WAAW,EAAE,MAAM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C;;;;OAIG;IACH,oBAAoB,CAAC,iBAAiB,EAAE,OAAO;IAI/C;;;;OAIG;IACH,kBAAkB,CAAC,eAAe,EAAE,OAAO;IAS3C;;;;OAIG;IACH,iBAAiB,CAAC,cAAc,EAAE,OAAO;IAOzC;;;;OAIG;IACH,wBAAwB,CAAC,qBAAqB,EAAE,OAAO;IAIvD;;;;;OAKG;IACH,8BAA8B,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO;IASrE;;;;OAIG;IACH,gCAAgC,CAAC,6BAA6B,EAAE,OAAO;IAIvE;;;;OAIG;IACH,mBAAmB,CAAC,gBAAgB,EAAE,OAAO;IAI7C;;;;OAIG;IACH,uBAAuB,CAAC,oBAAoB,EAAE,OAAO;CAGtD;AAED,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PreferencesController = void 0;
4
+ const base_controller_1 = require("@metamask/base-controller");
5
+ const controller_utils_1 = require("@metamask/controller-utils");
6
+ /**
7
+ * Controller that stores shared settings and exposes convenience methods
8
+ */
9
+ class PreferencesController extends base_controller_1.BaseController {
10
+ /**
11
+ * Creates a PreferencesController instance.
12
+ *
13
+ * @param config - Initial options used to configure this controller.
14
+ * @param state - Initial state to set on this controller.
15
+ */
16
+ constructor(config, state) {
17
+ super(config, state);
18
+ /**
19
+ * Name of this controller used during composition
20
+ */
21
+ this.name = 'PreferencesController';
22
+ this.defaultState = {
23
+ featureFlags: {},
24
+ identities: {},
25
+ ipfsGateway: 'https://ipfs.io/ipfs/',
26
+ lostIdentities: {},
27
+ selectedAddress: '',
28
+ useTokenDetection: true,
29
+ useNftDetection: false,
30
+ openSeaEnabled: false,
31
+ securityAlertsEnabled: false,
32
+ isMultiAccountBalancesEnabled: true,
33
+ disabledRpcMethodPreferences: {
34
+ eth_sign: false,
35
+ },
36
+ showTestNetworks: false,
37
+ isIpfsGatewayEnabled: true,
38
+ };
39
+ this.initialize();
40
+ }
41
+ /**
42
+ * Adds identities to state.
43
+ *
44
+ * @param addresses - List of addresses to use to generate new identities.
45
+ */
46
+ addIdentities(addresses) {
47
+ const { identities } = this.state;
48
+ addresses.forEach((address) => {
49
+ address = (0, controller_utils_1.toChecksumHexAddress)(address);
50
+ if (identities[address]) {
51
+ return;
52
+ }
53
+ const identityCount = Object.keys(identities).length;
54
+ identities[address] = {
55
+ name: `Account ${identityCount + 1}`,
56
+ address,
57
+ importTime: Date.now(),
58
+ };
59
+ });
60
+ this.update({ identities: Object.assign({}, identities) });
61
+ }
62
+ /**
63
+ * Removes an identity from state.
64
+ *
65
+ * @param address - Address of the identity to remove.
66
+ */
67
+ removeIdentity(address) {
68
+ address = (0, controller_utils_1.toChecksumHexAddress)(address);
69
+ const { identities } = this.state;
70
+ if (!identities[address]) {
71
+ return;
72
+ }
73
+ delete identities[address];
74
+ this.update({ identities: Object.assign({}, identities) });
75
+ if (address === this.state.selectedAddress) {
76
+ this.update({ selectedAddress: Object.keys(identities)[0] });
77
+ }
78
+ }
79
+ /**
80
+ * Associates a new label with an identity.
81
+ *
82
+ * @param address - Address of the identity to associate.
83
+ * @param label - New label to assign.
84
+ */
85
+ setAccountLabel(address, label) {
86
+ address = (0, controller_utils_1.toChecksumHexAddress)(address);
87
+ const { identities } = this.state;
88
+ identities[address] = identities[address] || {};
89
+ identities[address].name = label;
90
+ this.update({ identities: Object.assign({}, identities) });
91
+ }
92
+ /**
93
+ * Enable or disable a specific feature flag.
94
+ *
95
+ * @param feature - Feature to toggle.
96
+ * @param activated - Value to assign.
97
+ */
98
+ setFeatureFlag(feature, activated) {
99
+ const oldFeatureFlags = this.state.featureFlags;
100
+ const featureFlags = Object.assign(Object.assign({}, oldFeatureFlags), { [feature]: activated });
101
+ this.update({ featureFlags: Object.assign({}, featureFlags) });
102
+ }
103
+ /**
104
+ * Synchronizes the current identity list with new identities.
105
+ *
106
+ * @param addresses - List of addresses corresponding to identities to sync.
107
+ * @returns Newly-selected address after syncing.
108
+ */
109
+ syncIdentities(addresses) {
110
+ addresses = addresses.map((address) => (0, controller_utils_1.toChecksumHexAddress)(address));
111
+ const { identities, lostIdentities } = this.state;
112
+ const newlyLost = {};
113
+ for (const identity in identities) {
114
+ if (!addresses.includes(identity)) {
115
+ newlyLost[identity] = identities[identity];
116
+ delete identities[identity];
117
+ }
118
+ }
119
+ if (Object.keys(newlyLost).length > 0) {
120
+ for (const key in newlyLost) {
121
+ lostIdentities[key] = newlyLost[key];
122
+ }
123
+ }
124
+ this.update({
125
+ identities: Object.assign({}, identities),
126
+ lostIdentities: Object.assign({}, lostIdentities),
127
+ });
128
+ this.addIdentities(addresses);
129
+ if (!addresses.includes(this.state.selectedAddress)) {
130
+ this.update({ selectedAddress: addresses[0] });
131
+ }
132
+ return this.state.selectedAddress;
133
+ }
134
+ /**
135
+ * Generates and stores a new list of stored identities based on address. If the selected address
136
+ * is unset, or if it refers to an identity that was removed, it will be set to the first
137
+ * identity.
138
+ *
139
+ * @param addresses - List of addresses to use as a basis for each identity.
140
+ */
141
+ updateIdentities(addresses) {
142
+ addresses = addresses.map((address) => (0, controller_utils_1.toChecksumHexAddress)(address));
143
+ const oldIdentities = this.state.identities;
144
+ const identities = addresses.reduce((ids, address, index) => {
145
+ ids[address] = oldIdentities[address] || {
146
+ address,
147
+ name: `Account ${index + 1}`,
148
+ importTime: Date.now(),
149
+ };
150
+ return ids;
151
+ }, {});
152
+ let { selectedAddress } = this.state;
153
+ if (!Object.keys(identities).includes(selectedAddress)) {
154
+ selectedAddress = Object.keys(identities)[0];
155
+ }
156
+ this.update({ identities: Object.assign({}, identities), selectedAddress });
157
+ }
158
+ /**
159
+ * Sets selected address.
160
+ *
161
+ * @param selectedAddress - Ethereum address.
162
+ */
163
+ setSelectedAddress(selectedAddress) {
164
+ this.update({ selectedAddress: (0, controller_utils_1.toChecksumHexAddress)(selectedAddress) });
165
+ }
166
+ /**
167
+ * Sets new IPFS gateway.
168
+ *
169
+ * @param ipfsGateway - IPFS gateway string.
170
+ */
171
+ setIpfsGateway(ipfsGateway) {
172
+ this.update({ ipfsGateway });
173
+ }
174
+ /**
175
+ * Toggle the token detection setting.
176
+ *
177
+ * @param useTokenDetection - Boolean indicating user preference on token detection.
178
+ */
179
+ setUseTokenDetection(useTokenDetection) {
180
+ this.update({ useTokenDetection });
181
+ }
182
+ /**
183
+ * Toggle the NFT detection setting.
184
+ *
185
+ * @param useNftDetection - Boolean indicating user preference on NFT detection.
186
+ */
187
+ setUseNftDetection(useNftDetection) {
188
+ if (useNftDetection && !this.state.openSeaEnabled) {
189
+ throw new Error('useNftDetection cannot be enabled if openSeaEnabled is false');
190
+ }
191
+ this.update({ useNftDetection });
192
+ }
193
+ /**
194
+ * Toggle the opensea enabled setting.
195
+ *
196
+ * @param openSeaEnabled - Boolean indicating user preference on using OpenSea's API.
197
+ */
198
+ setOpenSeaEnabled(openSeaEnabled) {
199
+ this.update({ openSeaEnabled });
200
+ if (!openSeaEnabled) {
201
+ this.update({ useNftDetection: false });
202
+ }
203
+ }
204
+ /**
205
+ * Toggle the security alert enabled setting.
206
+ *
207
+ * @param securityAlertsEnabled - Boolean indicating user preference on using security alerts.
208
+ */
209
+ setSecurityAlertsEnabled(securityAlertsEnabled) {
210
+ this.update({ securityAlertsEnabled });
211
+ }
212
+ /**
213
+ * A setter for the user preferences to enable/disable rpc methods.
214
+ *
215
+ * @param methodName - The RPC method name to change the setting of.
216
+ * @param isEnabled - true to enable the rpc method, false to disable it.
217
+ */
218
+ setDisabledRpcMethodPreference(methodName, isEnabled) {
219
+ const { disabledRpcMethodPreferences } = this.state;
220
+ const newDisabledRpcMethods = Object.assign(Object.assign({}, disabledRpcMethodPreferences), { [methodName]: isEnabled });
221
+ this.update({ disabledRpcMethodPreferences: newDisabledRpcMethods });
222
+ }
223
+ /**
224
+ * A setter for the user preferences to enable/disable fetch of multiple accounts balance.
225
+ *
226
+ * @param isMultiAccountBalancesEnabled - true to enable multiple accounts balance fetch, false to fetch only selectedAddress.
227
+ */
228
+ setIsMultiAccountBalancesEnabled(isMultiAccountBalancesEnabled) {
229
+ this.update({ isMultiAccountBalancesEnabled });
230
+ }
231
+ /**
232
+ * A setter for the user have the test networks visible/hidden.
233
+ *
234
+ * @param showTestNetworks - true to show test networks, false to hidden.
235
+ */
236
+ setShowTestNetworks(showTestNetworks) {
237
+ this.update({ showTestNetworks });
238
+ }
239
+ /**
240
+ * A setter for the user allow to be fetched IPFS content
241
+ *
242
+ * @param isIpfsGatewayEnabled - true to enable ipfs source
243
+ */
244
+ setIsIpfsGatewayEnabled(isIpfsGatewayEnabled) {
245
+ this.update({ isIpfsGatewayEnabled });
246
+ }
247
+ }
248
+ exports.PreferencesController = PreferencesController;
249
+ exports.default = PreferencesController;
250
+ //# sourceMappingURL=PreferencesController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PreferencesController.js","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":";;;AACA,+DAA2D;AAC3D,iEAAkE;AA0ClE;;GAEG;AACH,MAAa,qBAAsB,SAAQ,gCAG1C;IAMC;;;;;OAKG;IACH,YAAY,MAA4B,EAAE,KAAiC;QACzE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAZvB;;WAEG;QACM,SAAI,GAAG,uBAAuB,CAAC;QAUtC,IAAI,CAAC,YAAY,GAAG;YAClB,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,uBAAuB;YACpC,cAAc,EAAE,EAAE;YAClB,eAAe,EAAE,EAAE;YACnB,iBAAiB,EAAE,IAAI;YACvB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;YACrB,qBAAqB,EAAE,KAAK;YAC5B,6BAA6B,EAAE,IAAI;YACnC,4BAA4B,EAAE;gBAC5B,QAAQ,EAAE,KAAK;aAChB;YACD,gBAAgB,EAAE,KAAK;YACvB,oBAAoB,EAAE,IAAI;SAC3B,CAAC;QACF,IAAI,CAAC,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AAI,CAAC,KAAK,CAAC;QACpD,MAAM,qBAAqB,mCACtB,4BAA4B,KAC/B,CAAC,UAAU,CAAC,EAAE,SAAS,GACxB,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,CAAC,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACH,gCAAgC,CAAC,6BAAsC;QACrE,IAAI,CAAC,MAAM,CAAC,EAAE,6BAA6B,EAAE,CAAC,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,gBAAyB;QAC3C,IAAI,CAAC,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,uBAAuB,CAAC,oBAA6B;QACnD,IAAI,CAAC,MAAM,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC;IACxC,CAAC;CACF;AApRD,sDAoRC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { toChecksumHexAddress } from '@metamask/controller-utils';\n\n/**\n * ContactEntry representation.\n *\n * @property address - Hex address of a recipient account\n * @property name - Nickname associated with this address\n * @property importTime - Data time when an account as created/imported\n */\nexport interface ContactEntry {\n address: string;\n name: string;\n importTime?: number;\n}\n\n/**\n * @type PreferencesState\n *\n * Preferences controller state\n * @property featureFlags - Map of specific features to enable or disable\n * @property identities - Map of addresses to ContactEntry objects\n * @property lostIdentities - Map of lost addresses to ContactEntry objects\n * @property selectedAddress - Current coinbase account\n */\nexport interface PreferencesState extends BaseState {\n featureFlags: { [feature: string]: boolean };\n ipfsGateway: string;\n identities: { [address: string]: ContactEntry };\n lostIdentities: { [address: string]: ContactEntry };\n selectedAddress: string;\n useTokenDetection: boolean;\n useNftDetection: boolean;\n openSeaEnabled: boolean;\n securityAlertsEnabled: boolean;\n isMultiAccountBalancesEnabled: boolean;\n disabledRpcMethodPreferences: {\n [methodName: string]: boolean;\n };\n showTestNetworks: boolean;\n isIpfsGatewayEnabled: boolean;\n}\n\n/**\n * Controller that stores shared settings and exposes convenience methods\n */\nexport class PreferencesController extends BaseController<\n BaseConfig,\n PreferencesState\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'PreferencesController';\n\n /**\n * Creates a PreferencesController instance.\n *\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(config?: Partial<BaseConfig>, state?: Partial<PreferencesState>) {\n super(config, state);\n this.defaultState = {\n featureFlags: {},\n identities: {},\n ipfsGateway: 'https://ipfs.io/ipfs/',\n lostIdentities: {},\n selectedAddress: '',\n useTokenDetection: true,\n useNftDetection: false,\n openSeaEnabled: false,\n securityAlertsEnabled: false,\n isMultiAccountBalancesEnabled: true,\n disabledRpcMethodPreferences: {\n eth_sign: false,\n },\n showTestNetworks: false,\n isIpfsGatewayEnabled: true,\n };\n this.initialize();\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 { identities } = this.state;\n addresses.forEach((address) => {\n address = toChecksumHexAddress(address);\n if (identities[address]) {\n return;\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 this.update({ identities: { ...identities } });\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 delete identities[address];\n this.update({ identities: { ...identities } });\n if (address === this.state.selectedAddress) {\n this.update({ selectedAddress: Object.keys(identities)[0] });\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 const { identities } = this.state;\n identities[address] = identities[address] || {};\n identities[address].name = label;\n this.update({ identities: { ...identities } });\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 const oldFeatureFlags = this.state.featureFlags;\n const featureFlags = { ...oldFeatureFlags, ...{ [feature]: activated } };\n this.update({ featureFlags: { ...featureFlags } });\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 * @returns Newly-selected address after syncing.\n */\n syncIdentities(addresses: string[]) {\n addresses = addresses.map((address: string) =>\n toChecksumHexAddress(address),\n );\n const { identities, lostIdentities } = this.state;\n const newlyLost: { [address: string]: ContactEntry } = {};\n\n for (const identity in identities) {\n if (!addresses.includes(identity)) {\n newlyLost[identity] = identities[identity];\n delete identities[identity];\n }\n }\n\n if (Object.keys(newlyLost).length > 0) {\n for (const key in newlyLost) {\n lostIdentities[key] = newlyLost[key];\n }\n }\n\n this.update({\n identities: { ...identities },\n lostIdentities: { ...lostIdentities },\n });\n this.addIdentities(addresses);\n\n if (!addresses.includes(this.state.selectedAddress)) {\n this.update({ selectedAddress: addresses[0] });\n }\n\n return this.state.selectedAddress;\n }\n\n /**\n * Generates and stores a new list of stored identities based on address. If the selected address\n * is unset, or if it refers to an identity that was removed, it will be set to the first\n * identity.\n *\n * @param addresses - List of addresses to use as a basis for each identity.\n */\n updateIdentities(addresses: string[]) {\n addresses = addresses.map((address: string) =>\n toChecksumHexAddress(address),\n );\n const oldIdentities = this.state.identities;\n const identities = addresses.reduce(\n (ids: { [address: string]: ContactEntry }, address, index) => {\n ids[address] = oldIdentities[address] || {\n address,\n name: `Account ${index + 1}`,\n importTime: Date.now(),\n };\n return ids;\n },\n {},\n );\n let { selectedAddress } = this.state;\n if (!Object.keys(identities).includes(selectedAddress)) {\n selectedAddress = Object.keys(identities)[0];\n }\n this.update({ identities: { ...identities }, selectedAddress });\n }\n\n /**\n * Sets selected address.\n *\n * @param selectedAddress - Ethereum address.\n */\n setSelectedAddress(selectedAddress: string) {\n this.update({ selectedAddress: toChecksumHexAddress(selectedAddress) });\n }\n\n /**\n * Sets new IPFS gateway.\n *\n * @param ipfsGateway - IPFS gateway string.\n */\n setIpfsGateway(ipfsGateway: string) {\n this.update({ ipfsGateway });\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({ useTokenDetection });\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({ useNftDetection });\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({ openSeaEnabled });\n if (!openSeaEnabled) {\n this.update({ useNftDetection: false });\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({ securityAlertsEnabled });\n }\n\n /**\n * A setter for the user preferences to enable/disable rpc methods.\n *\n * @param methodName - The RPC method name to change the setting of.\n * @param isEnabled - true to enable the rpc method, false to disable it.\n */\n setDisabledRpcMethodPreference(methodName: string, isEnabled: boolean) {\n const { disabledRpcMethodPreferences } = this.state;\n const newDisabledRpcMethods = {\n ...disabledRpcMethodPreferences,\n [methodName]: isEnabled,\n };\n this.update({ disabledRpcMethodPreferences: newDisabledRpcMethods });\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({ isMultiAccountBalancesEnabled });\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({ showTestNetworks });\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({ isIpfsGatewayEnabled });\n }\n}\n\nexport default PreferencesController;\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './PreferencesController';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./PreferencesController"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC","sourcesContent":["export * from './PreferencesController';\n"]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@metamask-previews/preferences-controller",
3
+ "version": "4.3.0-preview.3dbf14f",
4
+ "description": "Manages user-configurable settings for MetaMask",
5
+ "keywords": [
6
+ "MetaMask",
7
+ "Ethereum"
8
+ ],
9
+ "homepage": "https://github.com/MetaMask/core/tree/main/packages/preferences-controller#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/MetaMask/core/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/MetaMask/core.git"
16
+ },
17
+ "license": "MIT",
18
+ "main": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "files": [
21
+ "dist/"
22
+ ],
23
+ "scripts": {
24
+ "build:docs": "typedoc",
25
+ "changelog:validate": "../../scripts/validate-changelog.sh @metamask/preferences-controller",
26
+ "publish:preview": "yarn npm publish --tag preview",
27
+ "test": "jest",
28
+ "test:watch": "jest --watch"
29
+ },
30
+ "dependencies": {
31
+ "@metamask-previews/base-controller": "3.2.0-preview.3dbf14f",
32
+ "@metamask-previews/controller-utils": "4.3.1-preview.3dbf14f"
33
+ },
34
+ "devDependencies": {
35
+ "@metamask/auto-changelog": "^3.1.0",
36
+ "@types/jest": "^27.4.1",
37
+ "deepmerge": "^4.2.2",
38
+ "jest": "^27.5.1",
39
+ "ts-jest": "^27.1.4",
40
+ "typedoc": "^0.22.15",
41
+ "typedoc-plugin-missing-exports": "^0.22.6",
42
+ "typescript": "~4.6.3"
43
+ },
44
+ "engines": {
45
+ "node": ">=16.0.0"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public",
49
+ "registry": "https://registry.npmjs.org/"
50
+ }
51
+ }