@metamask-previews/preferences-controller 4.3.0-preview.d32a7cc → 4.4.0-preview.0f6a2fb
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,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [4.4.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add `isIpfsGatewayEnabled` property to PreferencesController state ([#1577](https://github.com/MetaMask/core/pull/1577))
|
|
12
|
+
- Add `setIsIpfsGatewayEnabled` to set `isIpfsGatewayEnabled` ([#1577](https://github.com/MetaMask/core/pull/1577))
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Bump dependency on `@metamask/base-controller` to ^3.2.1
|
|
16
|
+
- Bump dependency on `@metamask/controller-utils` to ^4.3.2
|
|
17
|
+
|
|
9
18
|
## [4.3.0]
|
|
10
19
|
### Added
|
|
11
20
|
- Add preference for security alerts ([#1589](https://github.com/MetaMask/core/pull/1589))
|
|
@@ -54,7 +63,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
54
63
|
|
|
55
64
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
56
65
|
|
|
57
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.
|
|
66
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.4.0...HEAD
|
|
67
|
+
[4.4.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.3.0...@metamask/preferences-controller@4.4.0
|
|
58
68
|
[4.3.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.2.0...@metamask/preferences-controller@4.3.0
|
|
59
69
|
[4.2.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.1.0...@metamask/preferences-controller@4.2.0
|
|
60
70
|
[4.1.0]: https://github.com/MetaMask/core/compare/@metamask/preferences-controller@4.0.0...@metamask/preferences-controller@4.1.0
|
|
@@ -42,6 +42,7 @@ export interface PreferencesState extends BaseState {
|
|
|
42
42
|
[methodName: string]: boolean;
|
|
43
43
|
};
|
|
44
44
|
showTestNetworks: boolean;
|
|
45
|
+
isIpfsGatewayEnabled: boolean;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Controller that stores shared settings and exposes convenience methods
|
|
@@ -154,6 +155,12 @@ export declare class PreferencesController extends BaseController<BaseConfig, Pr
|
|
|
154
155
|
* @param showTestNetworks - true to show test networks, false to hidden.
|
|
155
156
|
*/
|
|
156
157
|
setShowTestNetworks(showTestNetworks: boolean): void;
|
|
158
|
+
/**
|
|
159
|
+
* A setter for the user allow to be fetched IPFS content
|
|
160
|
+
*
|
|
161
|
+
* @param isIpfsGatewayEnabled - true to enable ipfs source
|
|
162
|
+
*/
|
|
163
|
+
setIsIpfsGatewayEnabled(isIpfsGatewayEnabled: boolean): void;
|
|
157
164
|
}
|
|
158
165
|
export default PreferencesController;
|
|
159
166
|
//# sourceMappingURL=PreferencesController.d.ts.map
|
|
@@ -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;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD,YAAY,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC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AKG;IACH,8BAA8B,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO;IASrE;;;;OAIG;IACH,gCAAgC,CAAC,6BAA6B,EAAE,OAAO;IAIvE;;;;OAIG;IACH,mBAAmB,CAAC,gBAAgB,EAAE,OAAO;IAI7C;;;;OAIG;IACH,uBAAuB,CAAC,oBAAoB,EAAE,OAAO;CAGtD;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -34,6 +34,7 @@ class PreferencesController extends base_controller_1.BaseController {
|
|
|
34
34
|
eth_sign: false,
|
|
35
35
|
},
|
|
36
36
|
showTestNetworks: false,
|
|
37
|
+
isIpfsGatewayEnabled: true,
|
|
37
38
|
};
|
|
38
39
|
this.initialize();
|
|
39
40
|
}
|
|
@@ -235,6 +236,14 @@ class PreferencesController extends base_controller_1.BaseController {
|
|
|
235
236
|
setShowTestNetworks(showTestNetworks) {
|
|
236
237
|
this.update({ showTestNetworks });
|
|
237
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* A setter for the user allow to be fetched IPFS content
|
|
241
|
+
*
|
|
242
|
+
* @param isIpfsGatewayEnabled - true to enable ipfs source
|
|
243
|
+
*/
|
|
244
|
+
setIsIpfsGatewayEnabled(isIpfsGatewayEnabled) {
|
|
245
|
+
this.update({ isIpfsGatewayEnabled });
|
|
246
|
+
}
|
|
238
247
|
}
|
|
239
248
|
exports.PreferencesController = PreferencesController;
|
|
240
249
|
exports.default = PreferencesController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreferencesController.js","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":";;;AACA,+DAA2D;AAC3D,iEAAkE;AAyClE;;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;QAUt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IAAI,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,cAAc,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;SACzC;IACH,CAAC;IAED;;;;OAIG;IACH,wBAAwB,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;CACF;AA1QD,sDA0QC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { toChecksumHexAddress } from '@metamask/controller-utils';\n\n/**\n * ContactEntry representation.\n *\n * @property address - Hex address of a recipient account\n * @property name - Nickname associated with this address\n * @property importTime - Data time when an account as created/imported\n */\nexport interface ContactEntry {\n address: string;\n name: string;\n importTime?: number;\n}\n\n/**\n * @type PreferencesState\n *\n * Preferences controller state\n * @property featureFlags - Map of specific features to enable or disable\n * @property identities - Map of addresses to ContactEntry objects\n * @property lostIdentities - Map of lost addresses to ContactEntry objects\n * @property selectedAddress - Current coinbase account\n */\nexport interface PreferencesState extends BaseState {\n featureFlags: { [feature: string]: boolean };\n ipfsGateway: string;\n identities: { [address: string]: ContactEntry };\n lostIdentities: { [address: string]: ContactEntry };\n selectedAddress: string;\n useTokenDetection: boolean;\n useNftDetection: boolean;\n openSeaEnabled: boolean;\n securityAlertsEnabled: boolean;\n isMultiAccountBalancesEnabled: boolean;\n disabledRpcMethodPreferences: {\n [methodName: string]: boolean;\n };\n showTestNetworks: boolean;\n}\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 };\n this.initialize();\n }\n\n /**\n * Adds identities to state.\n *\n * @param addresses - List of addresses to use to generate new identities.\n */\n addIdentities(addresses: string[]) {\n const { identities } = this.state;\n addresses.forEach((address) => {\n address = toChecksumHexAddress(address);\n if (identities[address]) {\n return;\n }\n const identityCount = Object.keys(identities).length;\n\n identities[address] = {\n name: `Account ${identityCount + 1}`,\n address,\n importTime: Date.now(),\n };\n });\n this.update({ identities: { ...identities } });\n }\n\n /**\n * Removes an identity from state.\n *\n * @param address - Address of the identity to remove.\n */\n removeIdentity(address: string) {\n address = toChecksumHexAddress(address);\n const { identities } = this.state;\n if (!identities[address]) {\n return;\n }\n delete identities[address];\n this.update({ identities: { ...identities } });\n if (address === this.state.selectedAddress) {\n this.update({ selectedAddress: Object.keys(identities)[0] });\n }\n }\n\n /**\n * Associates a new label with an identity.\n *\n * @param address - Address of the identity to associate.\n * @param label - New label to assign.\n */\n setAccountLabel(address: string, label: string) {\n address = toChecksumHexAddress(address);\n const { identities } = this.state;\n identities[address] = identities[address] || {};\n identities[address].name = label;\n this.update({ identities: { ...identities } });\n }\n\n /**\n * Enable or disable a specific feature flag.\n *\n * @param feature - Feature to toggle.\n * @param activated - Value to assign.\n */\n setFeatureFlag(feature: string, activated: boolean) {\n const oldFeatureFlags = this.state.featureFlags;\n const featureFlags = { ...oldFeatureFlags, ...{ [feature]: activated } };\n this.update({ featureFlags: { ...featureFlags } });\n }\n\n /**\n * Synchronizes the current identity list with new identities.\n *\n * @param addresses - List of addresses corresponding to identities to sync.\n * @returns Newly-selected address after syncing.\n */\n syncIdentities(addresses: string[]) {\n addresses = addresses.map((address: string) =>\n toChecksumHexAddress(address),\n );\n const { identities, lostIdentities } = this.state;\n const newlyLost: { [address: string]: ContactEntry } = {};\n\n for (const identity in identities) {\n if (!addresses.includes(identity)) {\n newlyLost[identity] = identities[identity];\n delete identities[identity];\n }\n }\n\n if (Object.keys(newlyLost).length > 0) {\n for (const key in newlyLost) {\n lostIdentities[key] = newlyLost[key];\n }\n }\n\n this.update({\n identities: { ...identities },\n lostIdentities: { ...lostIdentities },\n });\n this.addIdentities(addresses);\n\n if (!addresses.includes(this.state.selectedAddress)) {\n this.update({ selectedAddress: addresses[0] });\n }\n\n return this.state.selectedAddress;\n }\n\n /**\n * Generates and stores a new list of stored identities based on address. If the selected address\n * is unset, or if it refers to an identity that was removed, it will be set to the first\n * identity.\n *\n * @param addresses - List of addresses to use as a basis for each identity.\n */\n updateIdentities(addresses: string[]) {\n addresses = addresses.map((address: string) =>\n toChecksumHexAddress(address),\n );\n const oldIdentities = this.state.identities;\n const identities = addresses.reduce(\n (ids: { [address: string]: ContactEntry }, address, index) => {\n ids[address] = oldIdentities[address] || {\n address,\n name: `Account ${index + 1}`,\n importTime: Date.now(),\n };\n return ids;\n },\n {},\n );\n let { selectedAddress } = this.state;\n if (!Object.keys(identities).includes(selectedAddress)) {\n selectedAddress = Object.keys(identities)[0];\n }\n this.update({ identities: { ...identities }, selectedAddress });\n }\n\n /**\n * Sets selected address.\n *\n * @param selectedAddress - Ethereum address.\n */\n setSelectedAddress(selectedAddress: string) {\n this.update({ selectedAddress: toChecksumHexAddress(selectedAddress) });\n }\n\n /**\n * Sets new IPFS gateway.\n *\n * @param ipfsGateway - IPFS gateway string.\n */\n setIpfsGateway(ipfsGateway: string) {\n this.update({ ipfsGateway });\n }\n\n /**\n * Toggle the token detection setting.\n *\n * @param useTokenDetection - Boolean indicating user preference on token detection.\n */\n setUseTokenDetection(useTokenDetection: boolean) {\n this.update({ useTokenDetection });\n }\n\n /**\n * Toggle the NFT detection setting.\n *\n * @param useNftDetection - Boolean indicating user preference on NFT detection.\n */\n setUseNftDetection(useNftDetection: boolean) {\n if (useNftDetection && !this.state.openSeaEnabled) {\n throw new Error(\n 'useNftDetection cannot be enabled if openSeaEnabled is false',\n );\n }\n this.update({ useNftDetection });\n }\n\n /**\n * Toggle the opensea enabled setting.\n *\n * @param openSeaEnabled - Boolean indicating user preference on using OpenSea's API.\n */\n setOpenSeaEnabled(openSeaEnabled: boolean) {\n this.update({ openSeaEnabled });\n if (!openSeaEnabled) {\n this.update({ useNftDetection: false });\n }\n }\n\n /**\n * Toggle the security alert enabled setting.\n *\n * @param securityAlertsEnabled - Boolean indicating user preference on using security alerts.\n */\n setSecurityAlertsEnabled(securityAlertsEnabled: boolean) {\n this.update({ securityAlertsEnabled });\n }\n\n /**\n * A setter for the user preferences to enable/disable rpc methods.\n *\n * @param methodName - The RPC method name to change the setting of.\n * @param isEnabled - true to enable the rpc method, false to disable it.\n */\n setDisabledRpcMethodPreference(methodName: string, isEnabled: boolean) {\n const { disabledRpcMethodPreferences } = this.state;\n const newDisabledRpcMethods = {\n ...disabledRpcMethodPreferences,\n [methodName]: isEnabled,\n };\n this.update({ disabledRpcMethodPreferences: newDisabledRpcMethods });\n }\n\n /**\n * A setter for the user preferences to enable/disable fetch of multiple accounts balance.\n *\n * @param isMultiAccountBalancesEnabled - true to enable multiple accounts balance fetch, false to fetch only selectedAddress.\n */\n setIsMultiAccountBalancesEnabled(isMultiAccountBalancesEnabled: boolean) {\n this.update({ isMultiAccountBalancesEnabled });\n }\n\n /**\n * A setter for the user have the test networks visible/hidden.\n *\n * @param showTestNetworks - true to show test networks, false to hidden.\n */\n setShowTestNetworks(showTestNetworks: boolean) {\n this.update({ showTestNetworks });\n }\n}\n\nexport default PreferencesController;\n"]}
|
|
1
|
+
{"version":3,"file":"PreferencesController.js","sourceRoot":"","sources":["../src/PreferencesController.ts"],"names":[],"mappings":";;;AACA,+DAA2D;AAC3D,iEAAkE;AA0ClE;;GAEG;AACH,MAAa,qBAAsB,SAAQ,gCAG1C;IAMC;;;;;OAKG;IACH,YAAY,MAA4B,EAAE,KAAiC;QACzE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAZvB;;WAEG;QACM,SAAI,GAAG,uBAAuB,CAAC;QAUtC,IAAI,CAAC,YAAY,GAAG;YAClB,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,uBAAuB;YACpC,cAAc,EAAE,EAAE;YAClB,eAAe,EAAE,EAAE;YACnB,iBAAiB,EAAE,IAAI;YACvB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;YACrB,qBAAqB,EAAE,KAAK;YAC5B,6BAA6B,EAAE,IAAI;YACnC,4BAA4B,EAAE;gBAC5B,QAAQ,EAAE,KAAK;aAChB;YACD,gBAAgB,EAAE,KAAK;YACvB,oBAAoB,EAAE,IAAI;SAC3B,CAAC;QACF,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,SAAmB;QAC/B,MAAM,EAAE,UAAU,EAAE,GAAG,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C;QACF,IAAI,CAAC,MAAM,CAAC,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,CAAC,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACH,gCAAgC,CAAC,6BAAsC;QACrE,IAAI,CAAC,MAAM,CAAC,EAAE,6BAA6B,EAAE,CAAC,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,gBAAyB;QAC3C,IAAI,CAAC,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,uBAAuB,CAAC,oBAA6B;QACnD,IAAI,CAAC,MAAM,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC;IACxC,CAAC;CACF;AApRD,sDAoRC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { toChecksumHexAddress } from '@metamask/controller-utils';\n\n/**\n * ContactEntry representation.\n *\n * @property address - Hex address of a recipient account\n * @property name - Nickname associated with this address\n * @property importTime - Data time when an account as created/imported\n */\nexport interface ContactEntry {\n address: string;\n name: string;\n importTime?: number;\n}\n\n/**\n * @type PreferencesState\n *\n * Preferences controller state\n * @property featureFlags - Map of specific features to enable or disable\n * @property identities - Map of addresses to ContactEntry objects\n * @property lostIdentities - Map of lost addresses to ContactEntry objects\n * @property selectedAddress - Current coinbase account\n */\nexport interface PreferencesState extends BaseState {\n featureFlags: { [feature: string]: boolean };\n ipfsGateway: string;\n identities: { [address: string]: ContactEntry };\n lostIdentities: { [address: string]: ContactEntry };\n selectedAddress: string;\n useTokenDetection: boolean;\n useNftDetection: boolean;\n openSeaEnabled: boolean;\n securityAlertsEnabled: boolean;\n isMultiAccountBalancesEnabled: boolean;\n disabledRpcMethodPreferences: {\n [methodName: string]: boolean;\n };\n showTestNetworks: boolean;\n isIpfsGatewayEnabled: boolean;\n}\n\n/**\n * Controller that stores shared settings and exposes convenience methods\n */\nexport class PreferencesController extends BaseController<\n BaseConfig,\n PreferencesState\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'PreferencesController';\n\n /**\n * Creates a PreferencesController instance.\n *\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(config?: Partial<BaseConfig>, state?: Partial<PreferencesState>) {\n super(config, state);\n this.defaultState = {\n featureFlags: {},\n identities: {},\n ipfsGateway: 'https://ipfs.io/ipfs/',\n lostIdentities: {},\n selectedAddress: '',\n useTokenDetection: true,\n useNftDetection: false,\n openSeaEnabled: false,\n securityAlertsEnabled: false,\n isMultiAccountBalancesEnabled: true,\n disabledRpcMethodPreferences: {\n eth_sign: false,\n },\n showTestNetworks: false,\n isIpfsGatewayEnabled: true,\n };\n this.initialize();\n }\n\n /**\n * Adds identities to state.\n *\n * @param addresses - List of addresses to use to generate new identities.\n */\n addIdentities(addresses: string[]) {\n const { identities } = this.state;\n addresses.forEach((address) => {\n address = toChecksumHexAddress(address);\n if (identities[address]) {\n return;\n }\n const identityCount = Object.keys(identities).length;\n\n identities[address] = {\n name: `Account ${identityCount + 1}`,\n address,\n importTime: Date.now(),\n };\n });\n this.update({ identities: { ...identities } });\n }\n\n /**\n * Removes an identity from state.\n *\n * @param address - Address of the identity to remove.\n */\n removeIdentity(address: string) {\n address = toChecksumHexAddress(address);\n const { identities } = this.state;\n if (!identities[address]) {\n return;\n }\n delete identities[address];\n this.update({ identities: { ...identities } });\n if (address === this.state.selectedAddress) {\n this.update({ selectedAddress: Object.keys(identities)[0] });\n }\n }\n\n /**\n * Associates a new label with an identity.\n *\n * @param address - Address of the identity to associate.\n * @param label - New label to assign.\n */\n setAccountLabel(address: string, label: string) {\n address = toChecksumHexAddress(address);\n const { identities } = this.state;\n identities[address] = identities[address] || {};\n identities[address].name = label;\n this.update({ identities: { ...identities } });\n }\n\n /**\n * Enable or disable a specific feature flag.\n *\n * @param feature - Feature to toggle.\n * @param activated - Value to assign.\n */\n setFeatureFlag(feature: string, activated: boolean) {\n const oldFeatureFlags = this.state.featureFlags;\n const featureFlags = { ...oldFeatureFlags, ...{ [feature]: activated } };\n this.update({ featureFlags: { ...featureFlags } });\n }\n\n /**\n * Synchronizes the current identity list with new identities.\n *\n * @param addresses - List of addresses corresponding to identities to sync.\n * @returns Newly-selected address after syncing.\n */\n syncIdentities(addresses: string[]) {\n addresses = addresses.map((address: string) =>\n toChecksumHexAddress(address),\n );\n const { identities, lostIdentities } = this.state;\n const newlyLost: { [address: string]: ContactEntry } = {};\n\n for (const identity in identities) {\n if (!addresses.includes(identity)) {\n newlyLost[identity] = identities[identity];\n delete identities[identity];\n }\n }\n\n if (Object.keys(newlyLost).length > 0) {\n for (const key in newlyLost) {\n lostIdentities[key] = newlyLost[key];\n }\n }\n\n this.update({\n identities: { ...identities },\n lostIdentities: { ...lostIdentities },\n });\n this.addIdentities(addresses);\n\n if (!addresses.includes(this.state.selectedAddress)) {\n this.update({ selectedAddress: addresses[0] });\n }\n\n return this.state.selectedAddress;\n }\n\n /**\n * Generates and stores a new list of stored identities based on address. If the selected address\n * is unset, or if it refers to an identity that was removed, it will be set to the first\n * identity.\n *\n * @param addresses - List of addresses to use as a basis for each identity.\n */\n updateIdentities(addresses: string[]) {\n addresses = addresses.map((address: string) =>\n toChecksumHexAddress(address),\n );\n const oldIdentities = this.state.identities;\n const identities = addresses.reduce(\n (ids: { [address: string]: ContactEntry }, address, index) => {\n ids[address] = oldIdentities[address] || {\n address,\n name: `Account ${index + 1}`,\n importTime: Date.now(),\n };\n return ids;\n },\n {},\n );\n let { selectedAddress } = this.state;\n if (!Object.keys(identities).includes(selectedAddress)) {\n selectedAddress = Object.keys(identities)[0];\n }\n this.update({ identities: { ...identities }, selectedAddress });\n }\n\n /**\n * Sets selected address.\n *\n * @param selectedAddress - Ethereum address.\n */\n setSelectedAddress(selectedAddress: string) {\n this.update({ selectedAddress: toChecksumHexAddress(selectedAddress) });\n }\n\n /**\n * Sets new IPFS gateway.\n *\n * @param ipfsGateway - IPFS gateway string.\n */\n setIpfsGateway(ipfsGateway: string) {\n this.update({ ipfsGateway });\n }\n\n /**\n * Toggle the token detection setting.\n *\n * @param useTokenDetection - Boolean indicating user preference on token detection.\n */\n setUseTokenDetection(useTokenDetection: boolean) {\n this.update({ useTokenDetection });\n }\n\n /**\n * Toggle the NFT detection setting.\n *\n * @param useNftDetection - Boolean indicating user preference on NFT detection.\n */\n setUseNftDetection(useNftDetection: boolean) {\n if (useNftDetection && !this.state.openSeaEnabled) {\n throw new Error(\n 'useNftDetection cannot be enabled if openSeaEnabled is false',\n );\n }\n this.update({ useNftDetection });\n }\n\n /**\n * Toggle the opensea enabled setting.\n *\n * @param openSeaEnabled - Boolean indicating user preference on using OpenSea's API.\n */\n setOpenSeaEnabled(openSeaEnabled: boolean) {\n this.update({ openSeaEnabled });\n if (!openSeaEnabled) {\n this.update({ useNftDetection: false });\n }\n }\n\n /**\n * Toggle the security alert enabled setting.\n *\n * @param securityAlertsEnabled - Boolean indicating user preference on using security alerts.\n */\n setSecurityAlertsEnabled(securityAlertsEnabled: boolean) {\n this.update({ securityAlertsEnabled });\n }\n\n /**\n * A setter for the user preferences to enable/disable rpc methods.\n *\n * @param methodName - The RPC method name to change the setting of.\n * @param isEnabled - true to enable the rpc method, false to disable it.\n */\n setDisabledRpcMethodPreference(methodName: string, isEnabled: boolean) {\n const { disabledRpcMethodPreferences } = this.state;\n const newDisabledRpcMethods = {\n ...disabledRpcMethodPreferences,\n [methodName]: isEnabled,\n };\n this.update({ disabledRpcMethodPreferences: newDisabledRpcMethods });\n }\n\n /**\n * A setter for the user preferences to enable/disable fetch of multiple accounts balance.\n *\n * @param isMultiAccountBalancesEnabled - true to enable multiple accounts balance fetch, false to fetch only selectedAddress.\n */\n setIsMultiAccountBalancesEnabled(isMultiAccountBalancesEnabled: boolean) {\n this.update({ isMultiAccountBalancesEnabled });\n }\n\n /**\n * A setter for the user have the test networks visible/hidden.\n *\n * @param showTestNetworks - true to show test networks, false to hidden.\n */\n setShowTestNetworks(showTestNetworks: boolean) {\n this.update({ showTestNetworks });\n }\n\n /**\n * A setter for the user allow to be fetched IPFS content\n *\n * @param isIpfsGatewayEnabled - true to enable ipfs source\n */\n setIsIpfsGatewayEnabled(isIpfsGatewayEnabled: boolean) {\n this.update({ isIpfsGatewayEnabled });\n }\n}\n\nexport default PreferencesController;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/preferences-controller",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0-preview.0f6a2fb",
|
|
4
4
|
"description": "Manages user-configurable settings for MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"test:watch": "jest --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@metamask
|
|
32
|
-
"@metamask
|
|
31
|
+
"@metamask/base-controller": "^3.2.1",
|
|
32
|
+
"@metamask/controller-utils": "^4.3.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@metamask/auto-changelog": "^3.1.0",
|