@metamask-previews/preferences-controller 5.0.1-preview.c9a5f6a5 → 5.0.1-preview.fa529884

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.
@@ -1,70 +1,167 @@
1
- import type { BaseConfig, BaseState } from '@metamask/base-controller';
2
- import { BaseControllerV1 } from '@metamask/base-controller';
1
+ import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction, type RestrictedControllerMessenger } from '@metamask/base-controller';
3
2
  import { ETHERSCAN_SUPPORTED_CHAIN_IDS } from './constants';
4
3
  /**
5
- * ContactEntry representation.
6
- *
7
- * @property address - Hex address of a recipient account
8
- * @property name - Nickname associated with this address
9
- * @property importTime - Data time when an account as created/imported
4
+ * A representation of a MetaMask identity
10
5
  */
11
- export interface ContactEntry {
6
+ export declare type Identity = {
7
+ /**
8
+ * The address of the identity
9
+ */
12
10
  address: string;
13
- name: string;
11
+ /**
12
+ * The timestamp for when this identity was first added
13
+ */
14
14
  importTime?: number;
15
- }
15
+ /**
16
+ * The name of the identity
17
+ */
18
+ name: string;
19
+ };
20
+ /**
21
+ * A type union of the name for each chain that is supported by Etherscan or
22
+ * an Etherscan-compatible service.
23
+ */
16
24
  export declare type EtherscanSupportedChains = keyof typeof ETHERSCAN_SUPPORTED_CHAIN_IDS;
25
+ /**
26
+ * A type union of the chain ID for each chain that is supported by Etherscan
27
+ * or an Etherscan-compatible service.
28
+ */
17
29
  export declare type EtherscanSupportedHexChainId = (typeof ETHERSCAN_SUPPORTED_CHAIN_IDS)[EtherscanSupportedChains];
18
30
  /**
19
- * @type PreferencesState
20
- *
21
31
  * Preferences controller state
22
- * @property featureFlags - Map of specific features to enable or disable
23
- * @property identities - Map of addresses to ContactEntry objects
24
- * @property lostIdentities - Map of lost addresses to ContactEntry objects
25
- * @property selectedAddress - Current coinbase account
26
32
  */
27
- export interface PreferencesState extends BaseState {
33
+ export declare type PreferencesState = {
34
+ /**
35
+ * A map of RPC method names to enabled state (true is enabled, false is disabled)
36
+ */
37
+ disabledRpcMethodPreferences: {
38
+ [methodName: string]: boolean;
39
+ };
40
+ /**
41
+ * Map of specific features to enable or disable
42
+ */
28
43
  featureFlags: {
29
44
  [feature: string]: boolean;
30
45
  };
31
- ipfsGateway: string;
46
+ /**
47
+ * Map of addresses to Identity objects
48
+ */
32
49
  identities: {
33
- [address: string]: ContactEntry;
50
+ [address: string]: Identity;
34
51
  };
52
+ /**
53
+ * The configured IPFS gateway
54
+ */
55
+ ipfsGateway: string;
56
+ /**
57
+ * Controls whether IPFS is enabled or not
58
+ */
59
+ isIpfsGatewayEnabled: boolean;
60
+ /**
61
+ * Controls whether multi-account balances are enabled or not
62
+ */
63
+ isMultiAccountBalancesEnabled: boolean;
64
+ /**
65
+ * Map of lost addresses to Identity objects
66
+ */
35
67
  lostIdentities: {
36
- [address: string]: ContactEntry;
68
+ [address: string]: Identity;
37
69
  };
38
- selectedAddress: string;
39
- useTokenDetection: boolean;
40
- useNftDetection: boolean;
70
+ /**
71
+ * Controls whether the OpenSea API is used
72
+ */
41
73
  openSeaEnabled: boolean;
74
+ /**
75
+ * Controls whether "security alerts" are enabled
76
+ */
42
77
  securityAlertsEnabled: boolean;
43
- isMultiAccountBalancesEnabled: boolean;
44
- disabledRpcMethodPreferences: {
45
- [methodName: string]: boolean;
78
+ /**
79
+ * The current selected address
80
+ */
81
+ selectedAddress: string;
82
+ /**
83
+ * Controls whether incoming transactions are enabled, per-chain (for Etherscan-supported chains)
84
+ */
85
+ showIncomingTransactions: {
86
+ [chainId in EtherscanSupportedHexChainId]: boolean;
46
87
  };
88
+ /**
89
+ * Controls whether test networks are shown in the wallet
90
+ */
47
91
  showTestNetworks: boolean;
92
+ /**
93
+ * Controls whether NFT detection is enabled
94
+ */
95
+ useNftDetection: boolean;
96
+ /**
97
+ * Controls whether token detection is enabled
98
+ */
99
+ useTokenDetection: boolean;
100
+ };
101
+ declare const name = "PreferencesController";
102
+ export declare type PreferencesControllerGetStateAction = ControllerGetStateAction<typeof name, PreferencesState>;
103
+ export declare type PreferencesControllerStateChangeEvent = ControllerStateChangeEvent<typeof name, PreferencesState>;
104
+ export declare type PreferencesControllerActions = PreferencesControllerGetStateAction;
105
+ export declare type PreferencesControllerEvents = PreferencesControllerStateChangeEvent;
106
+ export declare type PreferencesControllerMessenger = RestrictedControllerMessenger<typeof name, PreferencesControllerActions, PreferencesControllerEvents, never, never>;
107
+ /**
108
+ * Get the default PreferencesController state.
109
+ *
110
+ * @returns The default PreferencesController state.
111
+ */
112
+ export declare function getDefaultPreferencesState(): {
113
+ disabledRpcMethodPreferences: {
114
+ eth_sign: boolean;
115
+ };
116
+ featureFlags: {};
117
+ identities: {};
118
+ ipfsGateway: string;
48
119
  isIpfsGatewayEnabled: boolean;
120
+ isMultiAccountBalancesEnabled: boolean;
121
+ lostIdentities: {};
122
+ openSeaEnabled: boolean;
123
+ securityAlertsEnabled: boolean;
124
+ selectedAddress: string;
49
125
  showIncomingTransactions: {
50
- [chainId in EtherscanSupportedHexChainId]: boolean;
126
+ "0x1": boolean;
127
+ "0x5": boolean;
128
+ "0x38": boolean;
129
+ "0x61": boolean;
130
+ "0xa": boolean;
131
+ "0x1a4": boolean;
132
+ "0x89": boolean;
133
+ "0x13881": boolean;
134
+ "0xa86a": boolean;
135
+ "0xa869": boolean;
136
+ "0xfa": boolean;
137
+ "0xfa2": boolean;
138
+ "0xaa36a7": boolean;
139
+ "0xe704": boolean;
140
+ "0xe708": boolean;
141
+ "0x504": boolean;
142
+ "0x507": boolean;
143
+ "0x505": boolean;
144
+ "0x64": boolean;
51
145
  };
52
- }
146
+ showTestNetworks: boolean;
147
+ useNftDetection: boolean;
148
+ useTokenDetection: boolean;
149
+ };
53
150
  /**
54
151
  * Controller that stores shared settings and exposes convenience methods
55
152
  */
56
- export declare class PreferencesController extends BaseControllerV1<BaseConfig, PreferencesState> {
57
- /**
58
- * Name of this controller used during composition
59
- */
60
- name: string;
153
+ export declare class PreferencesController extends BaseController<typeof name, PreferencesState, PreferencesControllerMessenger> {
61
154
  /**
62
155
  * Creates a PreferencesController instance.
63
156
  *
64
- * @param config - Initial options used to configure this controller.
65
- * @param state - Initial state to set on this controller.
157
+ * @param args - Arguments
158
+ * @param args.messenger - The preferences controller messenger.
159
+ * @param args.state - Preferences controller state.
66
160
  */
67
- constructor(config?: Partial<BaseConfig>, state?: Partial<PreferencesState>);
161
+ constructor({ messenger, state, }: {
162
+ messenger: PreferencesControllerMessenger;
163
+ state?: Partial<PreferencesState>;
164
+ });
68
165
  /**
69
166
  * Adds identities to state.
70
167
  *
@@ -1 +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,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;;GAMG;AAIH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,oBAAY,wBAAwB,GAClC,MAAM,OAAO,6BAA6B,CAAC;AAE7C,oBAAY,4BAA4B,GACtC,CAAC,OAAO,6BAA6B,CAAC,CAAC,wBAAwB,CAAC,CAAC;AAEnE;;;;;;;;GAQG;AAIH,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD,YAAY,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAC;IAChD,cAAc,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAC;I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e,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;IAIrD;;;;;OAKG;IACH,oCAAoC,CAClC,OAAO,EAAE,4BAA4B,EACrC,kCAAkC,EAAE,OAAO;CAW9C;AAED,eAAe,qBAAqB,CAAC"}
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;CACd,CAAC;AAEF;;;GAGG;AACH,oBAAY,wBAAwB,GAClC,MAAM,OAAO,6BAA6B,CAAC;AAE7C;;;GAGG;AACH,oBAAY,4BAA4B,GACtC,CAAC,OAAO,6BAA6B,CAAC,CAAC,wBAAwB,CAAC,CAAC;AAEnE;;GAEG;AACH,oBAAY,gBAAgB,GAAG;IAC7B;;OAEG;IACH,4BAA4B,EAAE;QAC5B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;KAC/B,CAAC;IACF;;OAEG;IACH,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OAKG;IACH,oCAAoC,CAClC,OAAO,EAAE,4BAA4B,EACrC,kCAAkC,EAAE,OAAO;CAW9C;AAED,eAAe,qBAAqB,CAAC"}
@@ -1,64 +1,90 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PreferencesController = void 0;
3
+ exports.PreferencesController = exports.getDefaultPreferencesState = void 0;
4
4
  const base_controller_1 = require("@metamask/base-controller");
5
5
  const controller_utils_1 = require("@metamask/controller-utils");
6
6
  const constants_1 = require("./constants");
7
+ const metadata = {
8
+ disabledRpcMethodPreferences: { persist: true, anonymous: true },
9
+ featureFlags: { persist: true, anonymous: true },
10
+ identities: { persist: true, anonymous: false },
11
+ ipfsGateway: { persist: true, anonymous: false },
12
+ isIpfsGatewayEnabled: { persist: true, anonymous: true },
13
+ isMultiAccountBalancesEnabled: { persist: true, anonymous: true },
14
+ lostIdentities: { persist: true, anonymous: false },
15
+ openSeaEnabled: { persist: true, anonymous: true },
16
+ securityAlertsEnabled: { persist: true, anonymous: true },
17
+ selectedAddress: { persist: true, anonymous: false },
18
+ showTestNetworks: { persist: true, anonymous: true },
19
+ showIncomingTransactions: { persist: true, anonymous: true },
20
+ useNftDetection: { persist: true, anonymous: true },
21
+ useTokenDetection: { persist: true, anonymous: true },
22
+ };
23
+ const name = 'PreferencesController';
24
+ /**
25
+ * Get the default PreferencesController state.
26
+ *
27
+ * @returns The default PreferencesController state.
28
+ */
29
+ function getDefaultPreferencesState() {
30
+ return {
31
+ disabledRpcMethodPreferences: {
32
+ eth_sign: false,
33
+ },
34
+ featureFlags: {},
35
+ identities: {},
36
+ ipfsGateway: 'https://ipfs.io/ipfs/',
37
+ isIpfsGatewayEnabled: true,
38
+ isMultiAccountBalancesEnabled: true,
39
+ lostIdentities: {},
40
+ openSeaEnabled: false,
41
+ securityAlertsEnabled: false,
42
+ selectedAddress: '',
43
+ showIncomingTransactions: {
44
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MAINNET]: true,
45
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.GOERLI]: true,
46
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC]: true,
47
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC_TESTNET]: true,
48
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM]: true,
49
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM_TESTNET]: true,
50
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON]: true,
51
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON_TESTNET]: true,
52
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE]: true,
53
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE_TESTNET]: true,
54
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM]: true,
55
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM_TESTNET]: true,
56
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.SEPOLIA]: true,
57
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_GOERLI]: true,
58
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_MAINNET]: true,
59
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM]: true,
60
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM_TESTNET]: true,
61
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONRIVER]: true,
62
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.GNOSIS]: true,
63
+ },
64
+ showTestNetworks: false,
65
+ useNftDetection: false,
66
+ useTokenDetection: true,
67
+ };
68
+ }
69
+ exports.getDefaultPreferencesState = getDefaultPreferencesState;
7
70
  /**
8
71
  * Controller that stores shared settings and exposes convenience methods
9
72
  */
10
- class PreferencesController extends base_controller_1.BaseControllerV1 {
73
+ class PreferencesController extends base_controller_1.BaseController {
11
74
  /**
12
75
  * Creates a PreferencesController instance.
13
76
  *
14
- * @param config - Initial options used to configure this controller.
15
- * @param state - Initial state to set on this controller.
77
+ * @param args - Arguments
78
+ * @param args.messenger - The preferences controller messenger.
79
+ * @param args.state - Preferences controller state.
16
80
  */
17
- constructor(config, state) {
18
- super(config, state);
19
- /**
20
- * Name of this controller used during composition
21
- */
22
- this.name = 'PreferencesController';
23
- this.defaultState = {
24
- featureFlags: {},
25
- identities: {},
26
- ipfsGateway: 'https://ipfs.io/ipfs/',
27
- lostIdentities: {},
28
- selectedAddress: '',
29
- useTokenDetection: true,
30
- useNftDetection: false,
31
- openSeaEnabled: false,
32
- securityAlertsEnabled: false,
33
- isMultiAccountBalancesEnabled: true,
34
- disabledRpcMethodPreferences: {
35
- eth_sign: false,
36
- },
37
- showTestNetworks: false,
38
- isIpfsGatewayEnabled: true,
39
- showIncomingTransactions: {
40
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MAINNET]: true,
41
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.GOERLI]: true,
42
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC]: true,
43
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC_TESTNET]: true,
44
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM]: true,
45
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM_TESTNET]: true,
46
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON]: true,
47
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON_TESTNET]: true,
48
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE]: true,
49
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE_TESTNET]: true,
50
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM]: true,
51
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM_TESTNET]: true,
52
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.SEPOLIA]: true,
53
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_GOERLI]: true,
54
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_MAINNET]: true,
55
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM]: true,
56
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM_TESTNET]: true,
57
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONRIVER]: true,
58
- [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.GNOSIS]: true,
59
- },
60
- };
61
- this.initialize();
81
+ constructor({ messenger, state, }) {
82
+ super({
83
+ name,
84
+ metadata,
85
+ messenger,
86
+ state: Object.assign(Object.assign({}, getDefaultPreferencesState()), state),
87
+ });
62
88
  }
63
89
  /**
64
90
  * Adds identities to state.
@@ -66,20 +92,21 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
66
92
  * @param addresses - List of addresses to use to generate new identities.
67
93
  */
68
94
  addIdentities(addresses) {
69
- const { identities } = this.state;
70
- addresses.forEach((address) => {
71
- address = (0, controller_utils_1.toChecksumHexAddress)(address);
72
- if (identities[address]) {
73
- return;
95
+ const checksummedAddresses = addresses.map(controller_utils_1.toChecksumHexAddress);
96
+ this.update((state) => {
97
+ const { identities } = state;
98
+ for (const address of checksummedAddresses) {
99
+ if (identities[address]) {
100
+ continue;
101
+ }
102
+ const identityCount = Object.keys(identities).length;
103
+ identities[address] = {
104
+ name: `Account ${identityCount + 1}`,
105
+ address,
106
+ importTime: Date.now(),
107
+ };
74
108
  }
75
- const identityCount = Object.keys(identities).length;
76
- identities[address] = {
77
- name: `Account ${identityCount + 1}`,
78
- address,
79
- importTime: Date.now(),
80
- };
81
109
  });
82
- this.update({ identities: Object.assign({}, identities) });
83
110
  }
84
111
  /**
85
112
  * Removes an identity from state.
@@ -92,11 +119,12 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
92
119
  if (!identities[address]) {
93
120
  return;
94
121
  }
95
- delete identities[address];
96
- this.update({ identities: Object.assign({}, identities) });
97
- if (address === this.state.selectedAddress) {
98
- this.update({ selectedAddress: Object.keys(identities)[0] });
99
- }
122
+ this.update((state) => {
123
+ delete state.identities[address];
124
+ if (address === state.selectedAddress) {
125
+ state.selectedAddress = Object.keys(state.identities)[0];
126
+ }
127
+ });
100
128
  }
101
129
  /**
102
130
  * Associates a new label with an identity.
@@ -106,10 +134,11 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
106
134
  */
107
135
  setAccountLabel(address, label) {
108
136
  address = (0, controller_utils_1.toChecksumHexAddress)(address);
109
- const { identities } = this.state;
110
- identities[address] = identities[address] || {};
111
- identities[address].name = label;
112
- this.update({ identities: Object.assign({}, identities) });
137
+ this.update((state) => {
138
+ const identity = state.identities[address] || {};
139
+ identity.name = label;
140
+ state.identities[address] = identity;
141
+ });
113
142
  }
114
143
  /**
115
144
  * Enable or disable a specific feature flag.
@@ -118,9 +147,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
118
147
  * @param activated - Value to assign.
119
148
  */
120
149
  setFeatureFlag(feature, activated) {
121
- const oldFeatureFlags = this.state.featureFlags;
122
- const featureFlags = Object.assign(Object.assign({}, oldFeatureFlags), { [feature]: activated });
123
- this.update({ featureFlags: Object.assign({}, featureFlags) });
150
+ this.update((state) => {
151
+ state.featureFlags[feature] = activated;
152
+ });
124
153
  }
125
154
  /**
126
155
  * Synchronizes the current identity list with new identities.
@@ -130,24 +159,24 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
130
159
  */
131
160
  syncIdentities(addresses) {
132
161
  addresses = addresses.map((address) => (0, controller_utils_1.toChecksumHexAddress)(address));
133
- const { identities, lostIdentities } = this.state;
134
- const newlyLost = {};
135
- for (const [address, identity] of Object.entries(identities)) {
136
- if (!addresses.includes(address)) {
137
- newlyLost[address] = identity;
138
- delete identities[address];
162
+ this.update((state) => {
163
+ const { identities } = state;
164
+ const newlyLost = {};
165
+ for (const [address, identity] of Object.entries(identities)) {
166
+ if (!addresses.includes(address)) {
167
+ newlyLost[address] = identity;
168
+ delete identities[address];
169
+ }
170
+ }
171
+ for (const [address, identity] of Object.entries(newlyLost)) {
172
+ state.lostIdentities[address] = identity;
139
173
  }
140
- }
141
- for (const [address, identity] of Object.entries(newlyLost)) {
142
- lostIdentities[address] = identity;
143
- }
144
- this.update({
145
- identities: Object.assign({}, identities),
146
- lostIdentities: Object.assign({}, lostIdentities),
147
174
  });
148
175
  this.addIdentities(addresses);
149
176
  if (!addresses.includes(this.state.selectedAddress)) {
150
- this.update({ selectedAddress: addresses[0] });
177
+ this.update((state) => {
178
+ state.selectedAddress = addresses[0];
179
+ });
151
180
  }
152
181
  return this.state.selectedAddress;
153
182
  }
@@ -160,20 +189,20 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
160
189
  */
161
190
  updateIdentities(addresses) {
162
191
  addresses = addresses.map((address) => (0, controller_utils_1.toChecksumHexAddress)(address));
163
- const oldIdentities = this.state.identities;
164
- const identities = addresses.reduce((ids, address, index) => {
165
- ids[address] = oldIdentities[address] || {
166
- address,
167
- name: `Account ${index + 1}`,
168
- importTime: Date.now(),
169
- };
170
- return ids;
171
- }, {});
172
- let { selectedAddress } = this.state;
173
- if (!Object.keys(identities).includes(selectedAddress)) {
174
- selectedAddress = Object.keys(identities)[0];
175
- }
176
- this.update({ identities: Object.assign({}, identities), selectedAddress });
192
+ this.update((state) => {
193
+ const identities = addresses.reduce((ids, address, index) => {
194
+ ids[address] = state.identities[address] || {
195
+ address,
196
+ name: `Account ${index + 1}`,
197
+ importTime: Date.now(),
198
+ };
199
+ return ids;
200
+ }, {});
201
+ state.identities = identities;
202
+ if (!Object.keys(identities).includes(state.selectedAddress)) {
203
+ state.selectedAddress = Object.keys(identities)[0];
204
+ }
205
+ });
177
206
  }
178
207
  /**
179
208
  * Sets selected address.
@@ -181,7 +210,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
181
210
  * @param selectedAddress - Ethereum address.
182
211
  */
183
212
  setSelectedAddress(selectedAddress) {
184
- this.update({ selectedAddress: (0, controller_utils_1.toChecksumHexAddress)(selectedAddress) });
213
+ this.update((state) => {
214
+ state.selectedAddress = (0, controller_utils_1.toChecksumHexAddress)(selectedAddress);
215
+ });
185
216
  }
186
217
  /**
187
218
  * Sets new IPFS gateway.
@@ -189,7 +220,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
189
220
  * @param ipfsGateway - IPFS gateway string.
190
221
  */
191
222
  setIpfsGateway(ipfsGateway) {
192
- this.update({ ipfsGateway });
223
+ this.update((state) => {
224
+ state.ipfsGateway = ipfsGateway;
225
+ });
193
226
  }
194
227
  /**
195
228
  * Toggle the token detection setting.
@@ -197,7 +230,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
197
230
  * @param useTokenDetection - Boolean indicating user preference on token detection.
198
231
  */
199
232
  setUseTokenDetection(useTokenDetection) {
200
- this.update({ useTokenDetection });
233
+ this.update((state) => {
234
+ state.useTokenDetection = useTokenDetection;
235
+ });
201
236
  }
202
237
  /**
203
238
  * Toggle the NFT detection setting.
@@ -208,7 +243,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
208
243
  if (useNftDetection && !this.state.openSeaEnabled) {
209
244
  throw new Error('useNftDetection cannot be enabled if openSeaEnabled is false');
210
245
  }
211
- this.update({ useNftDetection });
246
+ this.update((state) => {
247
+ state.useNftDetection = useNftDetection;
248
+ });
212
249
  }
213
250
  /**
214
251
  * Toggle the opensea enabled setting.
@@ -216,10 +253,12 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
216
253
  * @param openSeaEnabled - Boolean indicating user preference on using OpenSea's API.
217
254
  */
218
255
  setOpenSeaEnabled(openSeaEnabled) {
219
- this.update({ openSeaEnabled });
220
- if (!openSeaEnabled) {
221
- this.update({ useNftDetection: false });
222
- }
256
+ this.update((state) => {
257
+ state.openSeaEnabled = openSeaEnabled;
258
+ if (!openSeaEnabled) {
259
+ state.useNftDetection = false;
260
+ }
261
+ });
223
262
  }
224
263
  /**
225
264
  * Toggle the security alert enabled setting.
@@ -227,7 +266,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
227
266
  * @param securityAlertsEnabled - Boolean indicating user preference on using security alerts.
228
267
  */
229
268
  setSecurityAlertsEnabled(securityAlertsEnabled) {
230
- this.update({ securityAlertsEnabled });
269
+ this.update((state) => {
270
+ state.securityAlertsEnabled = securityAlertsEnabled;
271
+ });
231
272
  }
232
273
  /**
233
274
  * A setter for the user preferences to enable/disable rpc methods.
@@ -238,7 +279,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
238
279
  setDisabledRpcMethodPreference(methodName, isEnabled) {
239
280
  const { disabledRpcMethodPreferences } = this.state;
240
281
  const newDisabledRpcMethods = Object.assign(Object.assign({}, disabledRpcMethodPreferences), { [methodName]: isEnabled });
241
- this.update({ disabledRpcMethodPreferences: newDisabledRpcMethods });
282
+ this.update((state) => {
283
+ state.disabledRpcMethodPreferences = newDisabledRpcMethods;
284
+ });
242
285
  }
243
286
  /**
244
287
  * A setter for the user preferences to enable/disable fetch of multiple accounts balance.
@@ -246,7 +289,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
246
289
  * @param isMultiAccountBalancesEnabled - true to enable multiple accounts balance fetch, false to fetch only selectedAddress.
247
290
  */
248
291
  setIsMultiAccountBalancesEnabled(isMultiAccountBalancesEnabled) {
249
- this.update({ isMultiAccountBalancesEnabled });
292
+ this.update((state) => {
293
+ state.isMultiAccountBalancesEnabled = isMultiAccountBalancesEnabled;
294
+ });
250
295
  }
251
296
  /**
252
297
  * A setter for the user have the test networks visible/hidden.
@@ -254,7 +299,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
254
299
  * @param showTestNetworks - true to show test networks, false to hidden.
255
300
  */
256
301
  setShowTestNetworks(showTestNetworks) {
257
- this.update({ showTestNetworks });
302
+ this.update((state) => {
303
+ state.showTestNetworks = showTestNetworks;
304
+ });
258
305
  }
259
306
  /**
260
307
  * A setter for the user allow to be fetched IPFS content
@@ -262,7 +309,9 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
262
309
  * @param isIpfsGatewayEnabled - true to enable ipfs source
263
310
  */
264
311
  setIsIpfsGatewayEnabled(isIpfsGatewayEnabled) {
265
- this.update({ isIpfsGatewayEnabled });
312
+ this.update((state) => {
313
+ state.isIpfsGatewayEnabled = isIpfsGatewayEnabled;
314
+ });
266
315
  }
267
316
  /**
268
317
  * A setter for the user allow to be fetched IPFS content
@@ -272,8 +321,8 @@ class PreferencesController extends base_controller_1.BaseControllerV1 {
272
321
  */
273
322
  setEnableNetworkIncomingTransactions(chainId, isIncomingTransactionNetworkEnable) {
274
323
  if (Object.values(constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS).includes(chainId)) {
275
- this.update({
276
- showIncomingTransactions: Object.assign(Object.assign({}, this.state.showIncomingTransactions), { [chainId]: isIncomingTransactionNetworkEnable }),
324
+ this.update((state) => {
325
+ state.showIncomingTransactions = Object.assign(Object.assign({}, this.state.showIncomingTransactions), { [chainId]: isIncomingTransactionNetworkEnable });
277
326
  });
278
327
  }
279
328
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PreferencesController.js","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":";;;AACA,+DAA6D;AAC7D,iEAAkE;AAElE,2CAA4D;AAyD5D;;GAEG;AACH,MAAa,qBAAsB,SAAQ,kCAG1C;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,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CAAC,qBAA8B;QACrD,IAAI,CAAC,MAAM,CAAC,EAAE,qBAAqB,EAAE,CAAC,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,8BAA8B,CAAC,UAAkB,EAAE,SAAkB;QACnE,MAAM,EAAE,4BAA4B,EAAE,GAAG,IAAI,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;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;gBACV,wBAAwB,kCACnB,IAAI,CAAC,KAAK,CAAC,wBAAwB,KACtC,CAAC,OAAO,CAAC,EAAE,kCAAkC,GAC9C;aACF,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AA3TD,sDA2TC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { BaseControllerV1 } from '@metamask/base-controller';\nimport { toChecksumHexAddress } from '@metamask/controller-utils';\n\nimport { ETHERSCAN_SUPPORTED_CHAIN_IDS } from './constants';\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 */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface ContactEntry {\n address: string;\n name: string;\n importTime?: number;\n}\n\nexport type EtherscanSupportedChains =\n keyof typeof ETHERSCAN_SUPPORTED_CHAIN_IDS;\n\nexport type EtherscanSupportedHexChainId =\n (typeof ETHERSCAN_SUPPORTED_CHAIN_IDS)[EtherscanSupportedChains];\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 */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\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 showIncomingTransactions: {\n [chainId in EtherscanSupportedHexChainId]: boolean;\n };\n}\n\n/**\n * Controller that stores shared settings and exposes convenience methods\n */\nexport class PreferencesController extends BaseControllerV1<\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 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 };\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 [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 lostIdentities[address] = identity;\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 /**\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({\n 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;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,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;IAC5D,eAAe,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;IACnD,iBAAiB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SA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AuB,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;AAtTD,sDAsTC;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';\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/preferences-controller",
3
- "version": "5.0.1-preview.c9a5f6a5",
3
+ "version": "5.0.1-preview.fa529884",
4
4
  "description": "Manages user-configurable settings for MetaMask",
5
5
  "keywords": [
6
6
  "MetaMask",