@metamask-previews/preferences-controller 6.0.0-preview.d357889 → 7.0.0-preview.0dea691a

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  # Changelog
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -6,11 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
7
 
7
8
  ## [Unreleased]
8
9
 
10
+ ## [7.0.0]
11
+
12
+ ### Changed
13
+
14
+ - **BREAKING:** Keep `PreferencesController` state synchronized with `KeyringController` state ([#3799](https://github.com/MetaMask/core/pull/3799))
15
+ - The `KeyringController:stateChange` event is now required by the `PreferencesController` messenger, which is a breaking change.
16
+ - The package `@metamask/keyring-controller` has been added as a `peerDependency` and as a `devDependency`, which is a breaking change.
17
+ - Previously the state was synchronized manually by calling `syncIdentities` or `updateIdentities`. Calling these methods is no longer required.
18
+ - Bump `@metamask/base-controller` to `^4.1.1` ([#3760](https://github.com/MetaMask/core/pull/3760), [#3821](https://github.com/MetaMask/core/pull/3821))
19
+ - Bump `@metamask/controller-utils` to `^8.0.2` ([#3821](https://github.com/MetaMask/core/pull/3821))
20
+
9
21
  ## [6.0.0]
22
+
10
23
  ### Added
24
+
11
25
  - Added `getDefaultPreferencesState` function ([#3736](https://github.com/MetaMask/core/pull/3736))
12
26
 
13
27
  ### Changed
28
+
14
29
  - **BREAKING** Clean up types ([#3712](https://github.com/MetaMask/core/pull/3712))
15
30
  - Replace `ContactEntry` interface with `Identity` type
16
31
  - Convert `PreferencesState` from an interface to a type
@@ -19,12 +34,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
34
  - Additional type exports have been added for the controller messenger and associated types
20
35
 
21
36
  ## [5.0.1]
37
+
22
38
  ### Changed
39
+
23
40
  - Bump `@metamask/base-controller` to `^4.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
24
41
  - Bump `@metamask/controller-utils` to `^8.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695), [#3678](https://github.com/MetaMask/core/pull/3678), [#3667](https://github.com/MetaMask/core/pull/3667), [#3580](https://github.com/MetaMask/core/pull/3580))
25
42
 
26
43
  ## [5.0.0]
44
+
27
45
  ### Added
46
+
28
47
  - **BREAKING** Add required property `showIncomingTransactions` to `PreferencesState` ([#1659](https://github.com/MetaMask/core/pull/1659))
29
48
  - Add types `EtherscanSupportedChains`, `EtherscanSupportedHexChainId` ([#1659](https://github.com/MetaMask/core/pull/1659))
30
49
  - Add constant `ETHERSCAN_SUPPORTED_CHAIN_IDS` ([#1659](https://github.com/MetaMask/core/pull/1659))
@@ -32,81 +51,114 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
32
51
  - This can be used to set the `showIncomingTransactions` preference for the given chain ID.
33
52
 
34
53
  ### Changed
54
+
35
55
  - Bump `@metamask/base-controller` to ^4.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
36
56
  - This is not breaking because this controller still inherits from BaseController v1.
37
57
  - Bump `@metamask/controller-utils` to ^6.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
38
58
 
39
59
  ## [4.4.3]
60
+
40
61
  ### Changed
62
+
41
63
  - Bump dependency on `@metamask/base-controller` to ^3.2.3 ([#1747](https://github.com/MetaMask/core/pull/1747))
42
64
  - Bump dependency on `@metamask/controller-utils` to ^5.0.2 ([#1747](https://github.com/MetaMask/core/pull/1747))
43
65
 
44
66
  ## [4.4.2]
67
+
45
68
  ### Changed
69
+
46
70
  - Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
47
71
 
48
72
  ## [4.4.1]
73
+
49
74
  ### Changed
75
+
50
76
  - Bump dependency on `@metamask/controller-utils` to ^5.0.0
51
77
 
52
78
  ## [4.4.0]
79
+
53
80
  ### Added
81
+
54
82
  - Add `isIpfsGatewayEnabled` property to PreferencesController state ([#1577](https://github.com/MetaMask/core/pull/1577))
55
83
  - Add `setIsIpfsGatewayEnabled` to set `isIpfsGatewayEnabled` ([#1577](https://github.com/MetaMask/core/pull/1577))
56
84
 
57
85
  ### Changed
86
+
58
87
  - Bump dependency on `@metamask/base-controller` to ^3.2.1
59
88
  - Bump dependency on `@metamask/controller-utils` to ^4.3.2
60
89
 
61
90
  ## [4.3.0]
91
+
62
92
  ### Added
93
+
63
94
  - Add preference for security alerts ([#1589](https://github.com/MetaMask/core/pull/1589))
64
95
 
65
96
  ## [4.2.0]
97
+
66
98
  ### Added
99
+
67
100
  - Add controller state property `showTestNetworks` along with a setter method, `setShowTestNetworks` ([#1418](https://github.com/MetaMask/core/pull/1418))
68
101
 
69
102
  ## [4.1.0]
103
+
70
104
  ### Added
105
+
71
106
  - Add `isMultiAccountBalancesEnabled` to state (default: true) along with a `setIsMultiAccountBalancesEnabled` method to set it
72
107
 
73
108
  ## [4.0.0]
109
+
74
110
  ### Changed
111
+
75
112
  - **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
76
113
 
77
114
  ## [3.0.0]
115
+
78
116
  ### Changed
117
+
79
118
  - **BREAKING:** Migrate network configurations from `PreferencesController` to `NetworkController` ([#1064](https://github.com/MetaMask/core/pull/1064))
80
119
  - 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.
81
120
 
82
121
  ## [2.1.0]
122
+
83
123
  ### Added
124
+
84
125
  - `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)
85
126
 
86
127
  ## [2.0.0]
128
+
87
129
  ### Removed
130
+
88
131
  - **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))
89
132
  - Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`
90
133
 
91
134
  ## [1.0.2]
135
+
92
136
  ### Changed
137
+
93
138
  - Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
94
139
  - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
95
140
 
96
141
  ## [1.0.1]
142
+
97
143
  ### Changed
144
+
98
145
  - Relax dependencies on `@metamask/base-controller` and `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
99
146
 
100
147
  ## [1.0.0]
148
+
101
149
  ### Added
150
+
102
151
  - Initial release
152
+
103
153
  - 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:
154
+
104
155
  - `src/user/PreferencesController.ts` (plus `ContactEntry` copied from `src/user/AddressBookController.ts`)
105
156
  - `src/user/PreferencesController.test.ts`
106
157
 
107
158
  All changes listed after this point were applied to this package following the monorepo conversion.
108
159
 
109
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@6.0.0...HEAD
160
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@7.0.0...HEAD
161
+ [7.0.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@6.0.0...@metamask/preferences-controller@7.0.0
110
162
  [6.0.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@5.0.1...@metamask/preferences-controller@6.0.0
111
163
  [5.0.1]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@5.0.0...@metamask/preferences-controller@5.0.1
112
164
  [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.4.3...@metamask/preferences-controller@5.0.0
@@ -1,4 +1,5 @@
1
1
  import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction, type RestrictedControllerMessenger } from '@metamask/base-controller';
2
+ import type { KeyringControllerStateChangeEvent } from '@metamask/keyring-controller';
2
3
  import { ETHERSCAN_SUPPORTED_CHAIN_IDS } from './constants';
3
4
  /**
4
5
  * A representation of a MetaMask identity
@@ -103,7 +104,8 @@ export declare type PreferencesControllerGetStateAction = ControllerGetStateActi
103
104
  export declare type PreferencesControllerStateChangeEvent = ControllerStateChangeEvent<typeof name, PreferencesState>;
104
105
  export declare type PreferencesControllerActions = PreferencesControllerGetStateAction;
105
106
  export declare type PreferencesControllerEvents = PreferencesControllerStateChangeEvent;
106
- export declare type PreferencesControllerMessenger = RestrictedControllerMessenger<typeof name, PreferencesControllerActions, PreferencesControllerEvents, never, never>;
107
+ export declare type AllowedEvents = KeyringControllerStateChangeEvent;
108
+ export declare type PreferencesControllerMessenger = RestrictedControllerMessenger<typeof name, PreferencesControllerActions, PreferencesControllerEvents | AllowedEvents, never, AllowedEvents['type']>;
107
109
  /**
108
110
  * Get the default PreferencesController state.
109
111
  *
@@ -193,6 +195,7 @@ export declare class PreferencesController extends BaseController<typeof name, P
193
195
  *
194
196
  * @param addresses - List of addresses corresponding to identities to sync.
195
197
  * @returns Newly-selected address after syncing.
198
+ * @deprecated This will be removed in a future release
196
199
  */
197
200
  syncIdentities(addresses: string[]): string;
198
201
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"PreferencesController.d.ts","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,EACnC,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAE5D;;GAEG;AACH,oBAAY,QAAQ,GAAG;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC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AE,OAAO;IAM7C;;;;OAIG;IACH,uBAAuB,CAAC,oBAAoB,EAAE,OAAO;IAMrD;;;;;OAKG;IACH,oCAAoC,CAClC,OAAO,EAAE,4BAA4B,EACrC,kCAAkC,EAAE,OAAO;CAW9C;AAED,eAAe,qBAAqB,CAAC"}
@@ -85,6 +85,15 @@ class PreferencesController extends base_controller_1.BaseController {
85
85
  messenger,
86
86
  state: Object.assign(Object.assign({}, getDefaultPreferencesState()), state),
87
87
  });
88
+ messenger.subscribe('KeyringController:stateChange', (keyringState) => {
89
+ const accounts = new Set();
90
+ for (const keyring of keyringState.keyrings) {
91
+ for (const account of keyring.accounts) {
92
+ accounts.add(account);
93
+ }
94
+ }
95
+ this.syncIdentities(Array.from(accounts));
96
+ });
88
97
  }
89
98
  /**
90
99
  * Adds identities to state.
@@ -156,6 +165,7 @@ class PreferencesController extends base_controller_1.BaseController {
156
165
  *
157
166
  * @param addresses - List of addresses corresponding to identities to sync.
158
167
  * @returns Newly-selected address after syncing.
168
+ * @deprecated This will be removed in a future release
159
169
  */
160
170
  syncIdentities(addresses) {
161
171
  addresses = addresses.map((address) => (0, controller_utils_1.toChecksumHexAddress)(address));
@@ -1 +1 @@
1
- {"version":3,"file":"PreferencesController.js","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":";;;AAAA,+DAKmC;AACnC,iEAAkE;AAElE,2CAA4D;AAoG5D,MAAM,QAAQ,GAAG;IACf,4BAA4B,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IAChE,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,SAA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["import {\n BaseController,\n type ControllerStateChangeEvent,\n type ControllerGetStateAction,\n type RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { toChecksumHexAddress } from '@metamask/controller-utils';\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 * A map of RPC method names to enabled state (true is enabled, false is disabled)\n */\n disabledRpcMethodPreferences: {\n [methodName: string]: boolean;\n };\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\nconst metadata = {\n disabledRpcMethodPreferences: { persist: true, anonymous: true },\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};\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 PreferencesControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n PreferencesControllerActions,\n PreferencesControllerEvents,\n never,\n never\n>;\n\n/**\n * Get the default PreferencesController state.\n *\n * @returns The default PreferencesController state.\n */\nexport function getDefaultPreferencesState() {\n return {\n disabledRpcMethodPreferences: {\n eth_sign: false,\n },\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_TESTNET]: 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_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 };\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\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(toChecksumHexAddress);\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 * @returns Newly-selected address after syncing.\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 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 this.update((state) => {\n const identities = addresses.reduce(\n (ids: { [address: string]: Identity }, address, index) => {\n ids[address] = state.identities[address] || {\n address,\n name: `Account ${index + 1}`,\n importTime: Date.now(),\n };\n return ids;\n },\n {},\n );\n state.identities = identities;\n if (!Object.keys(identities).includes(state.selectedAddress)) {\n state.selectedAddress = Object.keys(identities)[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 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((state) => {\n state.disabledRpcMethodPreferences = newDisabledRpcMethods;\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\nexport default PreferencesController;\n"]}
1
+ {"version":3,"file":"PreferencesController.js","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":";;;AAAA,+DAKmC;AACnC,iEAAkE;AAMlE,2CAA4D;AAoG5D,MAAM,QAAQ,GAAG;IACf,4BAA4B,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IAChE,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,EAAE,SAAS,EAAE,IAAI,EAAE;IAC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CAAC;QACF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,4BAA4B,GAAG,qBAAqB,CAAC;QAC7D,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,gCAAgC,CAAC,6BAAsC;QACrE,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,6BAA6B,GAAG,6BAA6B,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,gBAAyB;QAC3C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,uBAAuB,CAAC,oBAA6B;QACnD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,oCAAoC,CAClC,OAAqC,EACrC,kCAA2C;QAE3C,IAAI,MAAM,CAAC,MAAM,CAAC,yCAA6B,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAClE,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;gBACpB,KAAK,CAAC,wBAAwB,mCACzB,IAAI,CAAC,KAAK,CAAC,wBAAwB,KACtC,CAAC,OAAO,CAAC,EAAE,kCAAkC,GAC9C,CAAC;YACJ,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AApUD,sDAoUC;AAED,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 * A map of RPC method names to enabled state (true is enabled, false is disabled)\n */\n disabledRpcMethodPreferences: {\n [methodName: string]: boolean;\n };\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\nconst metadata = {\n disabledRpcMethodPreferences: { persist: true, anonymous: true },\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};\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 disabledRpcMethodPreferences: {\n eth_sign: false,\n },\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_TESTNET]: 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_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 };\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 this.syncIdentities(Array.from(accounts));\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(toChecksumHexAddress);\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 * @returns Newly-selected address after syncing.\n * @deprecated This will be removed in a future release\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 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 this.update((state) => {\n const identities = addresses.reduce(\n (ids: { [address: string]: Identity }, address, index) => {\n ids[address] = state.identities[address] || {\n address,\n name: `Account ${index + 1}`,\n importTime: Date.now(),\n };\n return ids;\n },\n {},\n );\n state.identities = identities;\n if (!Object.keys(identities).includes(state.selectedAddress)) {\n state.selectedAddress = Object.keys(identities)[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 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((state) => {\n state.disabledRpcMethodPreferences = newDisabledRpcMethods;\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\nexport default PreferencesController;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/preferences-controller",
3
- "version": "6.0.0-preview.d357889",
3
+ "version": "7.0.0-preview.0dea691a",
4
4
  "description": "Manages user-configurable settings for MetaMask",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -31,19 +31,24 @@
31
31
  "test:watch": "jest --watch"
32
32
  },
33
33
  "dependencies": {
34
- "@metamask/base-controller": "^4.1.0",
35
- "@metamask/controller-utils": "^8.0.1"
34
+ "@metamask/base-controller": "^4.1.1",
35
+ "@metamask/controller-utils": "^8.0.3"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@metamask/auto-changelog": "^3.4.4",
39
+ "@metamask/keyring-controller": "^12.2.0",
39
40
  "@types/jest": "^27.4.1",
40
41
  "deepmerge": "^4.2.2",
41
42
  "jest": "^27.5.1",
43
+ "lodash": "^4.17.21",
42
44
  "ts-jest": "^27.1.4",
43
45
  "typedoc": "^0.24.8",
44
46
  "typedoc-plugin-missing-exports": "^2.0.0",
45
47
  "typescript": "~4.8.4"
46
48
  },
49
+ "peerDependencies": {
50
+ "@metamask/keyring-controller": "^12.2.0"
51
+ },
47
52
  "engines": {
48
53
  "node": ">=16.0.0"
49
54
  },