@metamask-previews/preferences-controller 4.4.3-preview.eb58a59 → 5.0.1-preview.353ee83b

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
@@ -6,6 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [5.0.1]
10
+ ### Changed
11
+ - Bump `@metamask/base-controller` to `^4.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
12
+ - 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))
13
+
14
+ ## [5.0.0]
15
+ ### Added
16
+ - **BREAKING** Add required property `showIncomingTransactions` to `PreferencesState` ([#1659](https://github.com/MetaMask/core/pull/1659))
17
+ - Add types `EtherscanSupportedChains`, `EtherscanSupportedHexChainId` ([#1659](https://github.com/MetaMask/core/pull/1659))
18
+ - Add constant `ETHERSCAN_SUPPORTED_CHAIN_IDS` ([#1659](https://github.com/MetaMask/core/pull/1659))
19
+ - Add `setEnabledNetworkIncomingTransactions` method ([#1659](https://github.com/MetaMask/core/pull/1659))
20
+ - This can be used to set the `showIncomingTransactions` preference for the given chain ID.
21
+
22
+ ### Changed
23
+ - Bump `@metamask/base-controller` to ^4.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
24
+ - This is not breaking because this controller still inherits from BaseController v1.
25
+ - Bump `@metamask/controller-utils` to ^6.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
26
+
9
27
  ## [4.4.3]
10
28
  ### Changed
11
29
  - Bump dependency on `@metamask/base-controller` to ^3.2.3 ([#1747](https://github.com/MetaMask/core/pull/1747))
@@ -76,7 +94,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
76
94
 
77
95
  All changes listed after this point were applied to this package following the monorepo conversion.
78
96
 
79
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.4.3...HEAD
97
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@5.0.1...HEAD
98
+ [5.0.1]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@5.0.0...@metamask/preferences-controller@5.0.1
99
+ [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.4.3...@metamask/preferences-controller@5.0.0
80
100
  [4.4.3]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.4.2...@metamask/preferences-controller@4.4.3
81
101
  [4.4.2]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.4.1...@metamask/preferences-controller@4.4.2
82
102
  [4.4.1]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.4.0...@metamask/preferences-controller@4.4.1
@@ -1,59 +1,157 @@
1
- import type { BaseConfig, BaseState } from '@metamask/base-controller';
2
- import { BaseController } from '@metamask/base-controller';
1
+ import type { BaseConfig } from '@metamask/base-controller';
2
+ import { BaseControllerV1 } from '@metamask/base-controller';
3
3
  import { ETHERSCAN_SUPPORTED_CHAIN_IDS } from './constants';
4
4
  /**
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
5
+ * A representation of a MetaMask identity
10
6
  */
11
- export interface ContactEntry {
7
+ export declare type Identity = {
8
+ /**
9
+ * The address of the identity
10
+ */
12
11
  address: string;
13
- name: string;
12
+ /**
13
+ * The timestamp for when this identity was first added
14
+ */
14
15
  importTime?: number;
15
- }
16
+ /**
17
+ * The name of the identity
18
+ */
19
+ name: string;
20
+ };
21
+ /**
22
+ * A type union of the name for each chain that is supported by Etherscan or
23
+ * an Etherscan-compatible service.
24
+ */
16
25
  export declare type EtherscanSupportedChains = keyof typeof ETHERSCAN_SUPPORTED_CHAIN_IDS;
26
+ /**
27
+ * A type union of the chain ID for each chain that is supported by Etherscan
28
+ * or an Etherscan-compatible service.
29
+ */
17
30
  export declare type EtherscanSupportedHexChainId = (typeof ETHERSCAN_SUPPORTED_CHAIN_IDS)[EtherscanSupportedChains];
18
31
  /**
19
- * @type PreferencesState
20
- *
21
32
  * 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
33
  */
27
- export interface PreferencesState extends BaseState {
34
+ export declare type PreferencesState = {
35
+ /**
36
+ * A map of RPC method names to enabled state (true is enabled, false is disabled)
37
+ */
38
+ disabledRpcMethodPreferences: {
39
+ [methodName: string]: boolean;
40
+ };
41
+ /**
42
+ * Map of specific features to enable or disable
43
+ */
28
44
  featureFlags: {
29
45
  [feature: string]: boolean;
30
46
  };
31
- ipfsGateway: string;
47
+ /**
48
+ * Map of addresses to Identity objects
49
+ */
32
50
  identities: {
33
- [address: string]: ContactEntry;
51
+ [address: string]: Identity;
34
52
  };
53
+ /**
54
+ * The configured IPFS gateway
55
+ */
56
+ ipfsGateway: string;
57
+ /**
58
+ * Controls whether IPFS is enabled or not
59
+ */
60
+ isIpfsGatewayEnabled: boolean;
61
+ /**
62
+ * Controls whether multi-account balances are enabled or not
63
+ */
64
+ isMultiAccountBalancesEnabled: boolean;
65
+ /**
66
+ * Map of lost addresses to Identity objects
67
+ */
35
68
  lostIdentities: {
36
- [address: string]: ContactEntry;
69
+ [address: string]: Identity;
37
70
  };
38
- selectedAddress: string;
39
- useTokenDetection: boolean;
40
- useNftDetection: boolean;
71
+ /**
72
+ * The name of the controller
73
+ *
74
+ * @deprecated This property is never set, and will be removed in a future release
75
+ */
76
+ name?: string;
77
+ /**
78
+ * Controls whether the OpenSea API is used
79
+ */
41
80
  openSeaEnabled: boolean;
81
+ /**
82
+ * Controls whether "security alerts" are enabled
83
+ */
42
84
  securityAlertsEnabled: boolean;
43
- isMultiAccountBalancesEnabled: boolean;
44
- disabledRpcMethodPreferences: {
45
- [methodName: string]: boolean;
85
+ /**
86
+ * The current selected address
87
+ */
88
+ selectedAddress: string;
89
+ /**
90
+ * Controls whether incoming transactions are enabled, per-chain (for Etherscan-supported chains)
91
+ */
92
+ showIncomingTransactions: {
93
+ [chainId in EtherscanSupportedHexChainId]: boolean;
46
94
  };
95
+ /**
96
+ * Controls whether test networks are shown in the wallet
97
+ */
47
98
  showTestNetworks: boolean;
99
+ /**
100
+ * Controls whether NFT detection is enabled
101
+ */
102
+ useNftDetection: boolean;
103
+ /**
104
+ * Controls whether token detection is enabled
105
+ */
106
+ useTokenDetection: boolean;
107
+ };
108
+ /**
109
+ * Get the default PreferencesController state.
110
+ *
111
+ * @returns The default PreferencesController state.
112
+ */
113
+ export declare function getDefaultPreferencesState(): {
114
+ disabledRpcMethodPreferences: {
115
+ eth_sign: boolean;
116
+ };
117
+ featureFlags: {};
118
+ identities: {};
119
+ ipfsGateway: string;
48
120
  isIpfsGatewayEnabled: boolean;
121
+ isMultiAccountBalancesEnabled: boolean;
122
+ lostIdentities: {};
123
+ openSeaEnabled: boolean;
124
+ securityAlertsEnabled: boolean;
125
+ selectedAddress: string;
49
126
  showIncomingTransactions: {
50
- [chainId in EtherscanSupportedHexChainId]: boolean;
127
+ "0x1": boolean;
128
+ "0x5": boolean;
129
+ "0x38": boolean;
130
+ "0x61": boolean;
131
+ "0xa": boolean;
132
+ "0x1a4": boolean;
133
+ "0x89": boolean;
134
+ "0x13881": boolean;
135
+ "0xa86a": boolean;
136
+ "0xa869": boolean;
137
+ "0xfa": boolean;
138
+ "0xfa2": boolean;
139
+ "0xaa36a7": boolean;
140
+ "0xe704": boolean;
141
+ "0xe708": boolean;
142
+ "0x504": boolean;
143
+ "0x507": boolean;
144
+ "0x505": boolean;
145
+ "0x64": boolean;
51
146
  };
52
- }
147
+ showTestNetworks: boolean;
148
+ useNftDetection: boolean;
149
+ useTokenDetection: boolean;
150
+ };
53
151
  /**
54
152
  * Controller that stores shared settings and exposes convenience methods
55
153
  */
56
- export declare class PreferencesController extends BaseController<BaseConfig, PreferencesState> {
154
+ export declare class PreferencesController extends BaseControllerV1<BaseConfig, PreferencesState> {
57
155
  /**
58
156
  * Name of this controller used during composition
59
157
  */
@@ -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,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,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;IACpD,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,6BAA6B,EAA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,SAAS,EAAE,MAAM,EAAE;IA+BlC;;;;;;OAMG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE;IAuBpC;;;;OAIG;IACH,kBAAkB,CAAC,eAAe,EAAE,MAAM;IAI1C;;;;OAIG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM;IAIlC;;;;OAIG;IACH,oBAAoB,CAAC,iBAAiB,EAAE,OAAO;IAI/C;;;;OAIG;IACH,kBAAkB,CAAC,eAAe,EAAE,OAAO;IAS3C;;;;OAIG;IACH,iBAAiB,CAAC,cAAc,EAAE,OAAO;IAOzC;;;;OAIG;IACH,wBAAwB,CAAC,qBAAqB,EAAE,OAAO;IAIvD;;;;;OAKG;IACH,8BAA8B,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO;IASrE;;;;OAIG;IACH,gCAAgC,CAAC,6BAA6B,EAAE,OAAO;IAIvE;;;;OAIG;IACH,mBAAmB,CAAC,gBAAgB,EAAE,OAAO;IAI7C;;;;OAIG;IACH,uBAAuB,CAAC,oBAAoB,EAAE,OAAO;IAIrD;;;;;OAKG;IACH,oCAAoC,CAClC,OAAO,EAAE,4BAA4B,EACrC,kCAAkC,EAAE,OAAO;CAW9C;AAED,eAAe,qBAAqB,CAAC"}
@@ -1,13 +1,59 @@
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
+ /**
8
+ * Get the default PreferencesController state.
9
+ *
10
+ * @returns The default PreferencesController state.
11
+ */
12
+ function getDefaultPreferencesState() {
13
+ return {
14
+ disabledRpcMethodPreferences: {
15
+ eth_sign: false,
16
+ },
17
+ featureFlags: {},
18
+ identities: {},
19
+ ipfsGateway: 'https://ipfs.io/ipfs/',
20
+ isIpfsGatewayEnabled: true,
21
+ isMultiAccountBalancesEnabled: true,
22
+ lostIdentities: {},
23
+ openSeaEnabled: false,
24
+ securityAlertsEnabled: false,
25
+ selectedAddress: '',
26
+ showIncomingTransactions: {
27
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MAINNET]: true,
28
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.GOERLI]: true,
29
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC]: true,
30
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.BSC_TESTNET]: true,
31
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM]: true,
32
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.OPTIMISM_TESTNET]: true,
33
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON]: true,
34
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.POLYGON_TESTNET]: true,
35
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE]: true,
36
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.AVALANCHE_TESTNET]: true,
37
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM]: true,
38
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM_TESTNET]: true,
39
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.SEPOLIA]: true,
40
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_GOERLI]: true,
41
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_MAINNET]: true,
42
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM]: true,
43
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM_TESTNET]: true,
44
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONRIVER]: true,
45
+ [constants_1.ETHERSCAN_SUPPORTED_CHAIN_IDS.GNOSIS]: true,
46
+ },
47
+ showTestNetworks: false,
48
+ useNftDetection: false,
49
+ useTokenDetection: true,
50
+ };
51
+ }
52
+ exports.getDefaultPreferencesState = getDefaultPreferencesState;
7
53
  /**
8
54
  * Controller that stores shared settings and exposes convenience methods
9
55
  */
10
- class PreferencesController extends base_controller_1.BaseController {
56
+ class PreferencesController extends base_controller_1.BaseControllerV1 {
11
57
  /**
12
58
  * Creates a PreferencesController instance.
13
59
  *
@@ -20,44 +66,7 @@ class PreferencesController extends base_controller_1.BaseController {
20
66
  * Name of this controller used during composition
21
67
  */
22
68
  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
- };
69
+ this.defaultState = getDefaultPreferencesState();
61
70
  this.initialize();
62
71
  }
63
72
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"PreferencesController.js","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":";;;AACA,+DAA2D;AAC3D,iEAAkE;AAElE,2CAA4D;AAyD5D;;GAEG;AACH,MAAa,qBAAsB,SAAQ,gCAG1C;IAMC;;;;;OAKG;IACH,YAAY,MAA4B,EAAE,KAAiC;QACzE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAZvB;;WAEG;QACM,SAAI,GAAG,uBAAuB,CAAC;QAUtC,IAAI,CAAC,YAAY,GAAG;YAClB,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,uBAAuB;YACpC,cAAc,EAAE,EAAE;YAClB,eAAe,EAAE,EAAE;YACnB,iBAAiB,EAAE,IAAI;YACvB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK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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 { BaseController } 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 BaseController<\n BaseConfig,\n PreferencesState\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'PreferencesController';\n\n /**\n * Creates a PreferencesController instance.\n *\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(config?: Partial<BaseConfig>, state?: Partial<PreferencesState>) {\n super(config, state);\n this.defaultState = {\n featureFlags: {},\n identities: {},\n ipfsGateway: 'https://ipfs.io/ipfs/',\n lostIdentities: {},\n selectedAddress: '',\n useTokenDetection: true,\n useNftDetection: false,\n openSeaEnabled: false,\n securityAlertsEnabled: false,\n isMultiAccountBalancesEnabled: true,\n disabledRpcMethodPreferences: {\n eth_sign: false,\n },\n showTestNetworks: false,\n isIpfsGatewayEnabled: true,\n 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":";;;AACA,+DAA6D;AAC7D,iEAAkE;AAElE,2CAA4D;AA0G5D;;;;GAIG;AAC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C,OAAO,CAAC,EAAE,kCAAkC,GAC9C;aACF,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AAtRD,sDAsRC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import type { BaseConfig } 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 * 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 * The name of the controller\n *\n * @deprecated This property is never set, and will be removed in a future release\n */\n name?: string;\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\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 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 = getDefaultPreferencesState();\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]: 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 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]: Identity }, 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/preferences-controller",
3
- "version": "4.4.3-preview.eb58a59",
3
+ "version": "5.0.1-preview.353ee83b",
4
4
  "description": "Manages user-configurable settings for MetaMask",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -22,6 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "build:docs": "typedoc",
25
+ "changelog:update": "../../scripts/update-changelog.sh @metamask/preferences-controller",
25
26
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/preferences-controller",
26
27
  "publish:preview": "yarn npm publish --tag preview",
27
28
  "test": "jest --reporters=jest-silent-reporter",
@@ -30,11 +31,11 @@
30
31
  "test:watch": "jest --watch"
31
32
  },
32
33
  "dependencies": {
33
- "@metamask/base-controller": "^3.2.3",
34
- "@metamask/controller-utils": "^5.0.2"
34
+ "@metamask/base-controller": "^4.0.1",
35
+ "@metamask/controller-utils": "^8.0.1"
35
36
  },
36
37
  "devDependencies": {
37
- "@metamask/auto-changelog": "^3.4.3",
38
+ "@metamask/auto-changelog": "^3.4.4",
38
39
  "@types/jest": "^27.4.1",
39
40
  "deepmerge": "^4.2.2",
40
41
  "jest": "^27.5.1",