@metamask/assets-controllers 76.0.0 → 77.0.0

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
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [77.0.0]
11
+
12
+ ### Changed
13
+
14
+ - **BREAKING:** Rename `openSeaEnabled` to `displayNftMedia` in `NftController` ([#4774](https://github.com/MetaMask/core/pull/4774))
15
+ - Ensure compatibility for extension preferences controller state
16
+ - **BREAKING:** Remove `setApiKey` function and `openSeaApiKey` from `NftController` since opensea is not used anymore for NFT data ([#4774](https://github.com/MetaMask/core/pull/4774))
17
+ - Bump `@metamask/phishing-controller` from `^13.1.0` to `^14.0.0` ([#6716](https://github.com/MetaMask/core/pull/6716), [#6629](https://github.com/MetaMask/core/pull/6716))
18
+ - Bump `@metamask/preferences-controller` from `^19.0.0` to `^20.0.0` ([#6716](https://github.com/MetaMask/core/pull/6716), [#6629](https://github.com/MetaMask/core/pull/6716))
19
+
10
20
  ## [76.0.0]
11
21
 
12
22
  ### Added
@@ -2014,7 +2024,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2014
2024
 
2015
2025
  - Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
2016
2026
 
2017
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@76.0.0...HEAD
2027
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@77.0.0...HEAD
2028
+ [77.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@76.0.0...@metamask/assets-controllers@77.0.0
2018
2029
  [76.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@75.2.0...@metamask/assets-controllers@76.0.0
2019
2030
  [75.2.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@75.1.0...@metamask/assets-controllers@75.2.0
2020
2031
  [75.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@75.0.0...@metamask/assets-controllers@75.1.0
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _NftController_instances, _NftController_mutex, _NftController_selectedAccountId, _NftController_ipfsGateway, _NftController_openSeaEnabled, _NftController_useIpfsSubdomains, _NftController_isIpfsGatewayEnabled, _NftController_onNftAdded, _NftController_onPreferencesControllerStateChange, _NftController_onSelectedAccountChange, _NftController_updateNestedNftState, _NftController_getNftCollectionApi, _NftController_getNftInformationFromApi, _NftController_getNftInformationFromTokenURI, _NftController_getNftURIAndStandard, _NftController_getNftInformation, _NftController_getNftContractInformationFromContract, _NftController_getNftContractInformation, _NftController_addIndividualNft, _NftController_addNftContract, _NftController_removeAndIgnoreIndividualNft, _NftController_removeIndividualNft, _NftController_removeNftContract, _NftController_validateWatchNft, _NftController_getAddressOrSelectedAddress, _NftController_updateNftUpdateForAccount, _NftController_bulkSanitizeNftMetadata, _NftController_sanitizeNftMetadata;
16
+ var _NftController_instances, _NftController_mutex, _NftController_selectedAccountId, _NftController_ipfsGateway, _NftController_displayNftMedia, _NftController_useIpfsSubdomains, _NftController_isIpfsGatewayEnabled, _NftController_onNftAdded, _NftController_onPreferencesControllerStateChange, _NftController_onSelectedAccountChange, _NftController_updateNestedNftState, _NftController_getNftCollectionApi, _NftController_getNftInformationFromApi, _NftController_getNftInformationFromTokenURI, _NftController_getNftURIAndStandard, _NftController_getNftInformation, _NftController_getNftContractInformationFromContract, _NftController_getNftContractInformation, _NftController_addIndividualNft, _NftController_addNftContract, _NftController_removeAndIgnoreIndividualNft, _NftController_removeIndividualNft, _NftController_removeNftContract, _NftController_validateWatchNft, _NftController_getAddressOrSelectedAddress, _NftController_updateNftUpdateForAccount, _NftController_bulkSanitizeNftMetadata, _NftController_sanitizeNftMetadata;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.NftController = exports.getDefaultNftControllerState = void 0;
19
19
  const address_1 = require("@ethersproject/address");
@@ -69,7 +69,7 @@ class NftController extends base_controller_1.BaseController {
69
69
  *
70
70
  * @param options - The controller options.
71
71
  * @param options.ipfsGateway - The configured IPFS gateway.
72
- * @param options.openSeaEnabled - Controls whether the OpenSea API is used.
72
+ * @param options.displayNftMedia - Controls whether the NFT API is used.
73
73
  * @param options.useIpfsSubdomains - Controls whether IPFS subdomains are used.
74
74
  * @param options.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not.
75
75
  * @param options.onNftAdded - Callback that is called when an NFT is added. Currently used pass data
@@ -77,7 +77,7 @@ class NftController extends base_controller_1.BaseController {
77
77
  * @param options.messenger - The messenger.
78
78
  * @param options.state - Initial state to set on this controller.
79
79
  */
80
- constructor({ ipfsGateway = controller_utils_1.IPFS_DEFAULT_GATEWAY_URL, openSeaEnabled = false, useIpfsSubdomains = true, isIpfsGatewayEnabled = true, onNftAdded, messenger, state = {}, }) {
80
+ constructor({ ipfsGateway = controller_utils_1.IPFS_DEFAULT_GATEWAY_URL, displayNftMedia = false, useIpfsSubdomains = true, isIpfsGatewayEnabled = true, onNftAdded, messenger, state = {}, }) {
81
81
  super({
82
82
  name: controllerName,
83
83
  metadata: nftControllerMetadata,
@@ -91,28 +91,20 @@ class NftController extends base_controller_1.BaseController {
91
91
  _NftController_mutex.set(this, new async_mutex_1.Mutex());
92
92
  _NftController_selectedAccountId.set(this, void 0);
93
93
  _NftController_ipfsGateway.set(this, void 0);
94
- _NftController_openSeaEnabled.set(this, void 0);
94
+ _NftController_displayNftMedia.set(this, void 0);
95
95
  _NftController_useIpfsSubdomains.set(this, void 0);
96
96
  _NftController_isIpfsGatewayEnabled.set(this, void 0);
97
97
  _NftController_onNftAdded.set(this, void 0);
98
98
  __classPrivateFieldSet(this, _NftController_selectedAccountId, this.messagingSystem.call('AccountsController:getSelectedAccount').id, "f");
99
99
  __classPrivateFieldSet(this, _NftController_ipfsGateway, ipfsGateway, "f");
100
- __classPrivateFieldSet(this, _NftController_openSeaEnabled, openSeaEnabled, "f");
100
+ __classPrivateFieldSet(this, _NftController_displayNftMedia, displayNftMedia, "f");
101
101
  __classPrivateFieldSet(this, _NftController_useIpfsSubdomains, useIpfsSubdomains, "f");
102
102
  __classPrivateFieldSet(this, _NftController_isIpfsGatewayEnabled, isIpfsGatewayEnabled, "f");
103
103
  __classPrivateFieldSet(this, _NftController_onNftAdded, onNftAdded, "f");
104
- this.messagingSystem.subscribe('PreferencesController:stateChange',
105
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
106
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
107
- __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_onPreferencesControllerStateChange).bind(this));
108
- this.messagingSystem.subscribe('AccountsController:selectedEvmAccountChange',
109
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
110
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
111
- __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_onSelectedAccountChange).bind(this));
104
+ this.messagingSystem.subscribe('PreferencesController:stateChange', __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_onPreferencesControllerStateChange).bind(this));
105
+ this.messagingSystem.subscribe('AccountsController:selectedEvmAccountChange', __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_onSelectedAccountChange).bind(this));
112
106
  }
113
107
  getNftApi() {
114
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
115
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
116
108
  return `${controller_utils_1.NFT_API_BASE_URL}/tokens`;
117
109
  }
118
110
  /**
@@ -166,14 +158,6 @@ class NftController extends base_controller_1.BaseController {
166
158
  source: constants_1.Source.Dapp,
167
159
  });
168
160
  }
169
- /**
170
- * Sets an OpenSea API key to retrieve NFT information.
171
- *
172
- * @param openSeaApiKey - OpenSea API key.
173
- */
174
- setApiKey(openSeaApiKey) {
175
- this.openSeaApiKey = openSeaApiKey;
176
- }
177
161
  /**
178
162
  * Checks the ownership of a ERC-721 or ERC-1155 NFT for a given address.
179
163
  *
@@ -188,7 +172,6 @@ class NftController extends base_controller_1.BaseController {
188
172
  try {
189
173
  const owner = await this.messagingSystem.call('AssetsContractController:getERC721OwnerOf', nftAddress, tokenId, networkClientId);
190
174
  return ownerAddress.toLowerCase() === owner.toLowerCase();
191
- // eslint-disable-next-line no-empty
192
175
  }
193
176
  catch {
194
177
  // Ignore ERC-721 contract error
@@ -197,7 +180,6 @@ class NftController extends base_controller_1.BaseController {
197
180
  try {
198
181
  const balance = await this.messagingSystem.call('AssetsContractController:getERC1155BalanceOf', ownerAddress, nftAddress, tokenId, networkClientId);
199
182
  return !balance.isZero();
200
- // eslint-disable-next-line no-empty
201
183
  }
202
184
  catch {
203
185
  // Ignore ERC-1155 contract error
@@ -630,26 +612,28 @@ class NftController extends base_controller_1.BaseController {
630
612
  }
631
613
  }
632
614
  exports.NftController = NftController;
633
- _NftController_mutex = new WeakMap(), _NftController_selectedAccountId = new WeakMap(), _NftController_ipfsGateway = new WeakMap(), _NftController_openSeaEnabled = new WeakMap(), _NftController_useIpfsSubdomains = new WeakMap(), _NftController_isIpfsGatewayEnabled = new WeakMap(), _NftController_onNftAdded = new WeakMap(), _NftController_instances = new WeakSet(), _NftController_onPreferencesControllerStateChange =
615
+ _NftController_mutex = new WeakMap(), _NftController_selectedAccountId = new WeakMap(), _NftController_ipfsGateway = new WeakMap(), _NftController_displayNftMedia = new WeakMap(), _NftController_useIpfsSubdomains = new WeakMap(), _NftController_isIpfsGatewayEnabled = new WeakMap(), _NftController_onNftAdded = new WeakMap(), _NftController_instances = new WeakSet(), _NftController_onPreferencesControllerStateChange =
634
616
  /**
635
617
  * Handles the state change of the preference controller.
636
618
  *
637
619
  * @param preferencesState - The new state of the preference controller.
638
620
  * @param preferencesState.ipfsGateway - The configured IPFS gateway.
639
- * @param preferencesState.openSeaEnabled - Controls whether the OpenSea API is used.
640
621
  * @param preferencesState.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not.
622
+ * @param preferencesState.displayNftMedia - Controls whether the NFT API is used (mobile).
623
+ * @param preferencesState.openSeaEnabled - Controls whether the NFT API is used (extension).
641
624
  */
642
- async function _NftController_onPreferencesControllerStateChange({ ipfsGateway, openSeaEnabled, isIpfsGatewayEnabled, }) {
625
+ async function _NftController_onPreferencesControllerStateChange({ ipfsGateway, isIpfsGatewayEnabled, displayNftMedia, openSeaEnabled, }) {
643
626
  const selectedAccount = this.messagingSystem.call('AccountsController:getSelectedAccount');
644
627
  __classPrivateFieldSet(this, _NftController_selectedAccountId, selectedAccount.id, "f");
628
+ const newDisplayNftMedia = Boolean(displayNftMedia || openSeaEnabled);
645
629
  // Get current state values
646
630
  if (__classPrivateFieldGet(this, _NftController_ipfsGateway, "f") !== ipfsGateway ||
647
- __classPrivateFieldGet(this, _NftController_openSeaEnabled, "f") !== openSeaEnabled ||
631
+ __classPrivateFieldGet(this, _NftController_displayNftMedia, "f") !== newDisplayNftMedia ||
648
632
  __classPrivateFieldGet(this, _NftController_isIpfsGatewayEnabled, "f") !== isIpfsGatewayEnabled) {
649
633
  __classPrivateFieldSet(this, _NftController_ipfsGateway, ipfsGateway, "f");
650
- __classPrivateFieldSet(this, _NftController_openSeaEnabled, openSeaEnabled, "f");
634
+ __classPrivateFieldSet(this, _NftController_displayNftMedia, newDisplayNftMedia, "f");
651
635
  __classPrivateFieldSet(this, _NftController_isIpfsGatewayEnabled, isIpfsGatewayEnabled, "f");
652
- const needsUpdateNftMetadata = (isIpfsGatewayEnabled && ipfsGateway !== '') || openSeaEnabled;
636
+ const needsUpdateNftMetadata = (isIpfsGatewayEnabled && ipfsGateway !== '') || newDisplayNftMedia;
653
637
  if (needsUpdateNftMetadata && selectedAccount) {
654
638
  await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNftUpdateForAccount).call(this, selectedAccount);
655
639
  }
@@ -664,7 +648,7 @@ async function _NftController_onSelectedAccountChange(internalAccount) {
664
648
  const oldSelectedAccountId = __classPrivateFieldGet(this, _NftController_selectedAccountId, "f");
665
649
  __classPrivateFieldSet(this, _NftController_selectedAccountId, internalAccount.id, "f");
666
650
  const needsUpdateNftMetadata = ((__classPrivateFieldGet(this, _NftController_isIpfsGatewayEnabled, "f") && __classPrivateFieldGet(this, _NftController_ipfsGateway, "f") !== '') ||
667
- __classPrivateFieldGet(this, _NftController_openSeaEnabled, "f")) &&
651
+ __classPrivateFieldGet(this, _NftController_displayNftMedia, "f")) &&
668
652
  oldSelectedAccountId !== internalAccount.id;
669
653
  if (needsUpdateNftMetadata) {
670
654
  await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNftUpdateForAccount).call(this, internalAccount);
@@ -689,7 +673,6 @@ async function _NftController_onSelectedAccountChange(internalAccount) {
689
673
  });
690
674
  }, _NftController_getNftCollectionApi = function _NftController_getNftCollectionApi() {
691
675
  // False negative.
692
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
693
676
  return `${controller_utils_1.NFT_API_BASE_URL}/collections`;
694
677
  }, _NftController_getNftInformationFromApi =
695
678
  /**
@@ -783,7 +766,7 @@ async function _NftController_getNftInformationFromTokenURI(contractAddress, tok
783
766
  tokenURI: tokenURI ?? null,
784
767
  };
785
768
  }
786
- const isDisplayNFTMediaToggleEnabled = __classPrivateFieldGet(this, _NftController_openSeaEnabled, "f");
769
+ const isDisplayNFTMediaToggleEnabled = __classPrivateFieldGet(this, _NftController_displayNftMedia, "f");
787
770
  if (!hasIpfsTokenURI && !isDisplayNFTMediaToggleEnabled) {
788
771
  return {
789
772
  image: null,
@@ -883,7 +866,7 @@ async function _NftController_getNftInformation(contractAddress, tokenId, networ
883
866
  const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
884
867
  const [blockchainMetadata, nftApiMetadata] = await Promise.all([
885
868
  (0, controller_utils_1.safelyExecute)(() => __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftInformationFromTokenURI).call(this, contractAddress, tokenId, networkClientId)),
886
- __classPrivateFieldGet(this, _NftController_openSeaEnabled, "f") && chainId === '0x1'
869
+ __classPrivateFieldGet(this, _NftController_displayNftMedia, "f") && chainId === '0x1'
887
870
  ? (0, controller_utils_1.safelyExecute)(() => __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftInformationFromApi).call(this, contractAddress, tokenId))
888
871
  : undefined,
889
872
  ]);
@@ -933,13 +916,9 @@ async function _NftController_getNftContractInformation(contractAddress, nftMeta
933
916
  return {
934
917
  address: contractAddress,
935
918
  ...blockchainContractData,
936
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
937
- // eslint-disable-next-line @typescript-eslint/naming-convention
938
919
  schema_name: nftMetadataFromApi?.standard ?? null,
939
920
  collection: {
940
921
  name: null,
941
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
942
- // eslint-disable-next-line @typescript-eslint/naming-convention
943
922
  image_url: nftMetadataFromApi?.collection?.image ??
944
923
  nftMetadataFromApi?.collection?.imageUrl ??
945
924
  null,
@@ -952,25 +931,13 @@ async function _NftController_getNftContractInformation(contractAddress, nftMeta
952
931
  /* istanbul ignore next */
953
932
  return {
954
933
  address: contractAddress,
955
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
956
- // eslint-disable-next-line @typescript-eslint/naming-convention
957
934
  asset_contract_type: null,
958
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
959
- // eslint-disable-next-line @typescript-eslint/naming-convention
960
935
  created_date: null,
961
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
962
- // eslint-disable-next-line @typescript-eslint/naming-convention
963
936
  schema_name: null,
964
937
  symbol: null,
965
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
966
- // eslint-disable-next-line @typescript-eslint/naming-convention
967
938
  total_supply: null,
968
939
  description: null,
969
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
970
- // eslint-disable-next-line @typescript-eslint/naming-convention
971
940
  external_link: null,
972
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
973
- // eslint-disable-next-line @typescript-eslint/naming-convention
974
941
  collection: { name: null, image_url: null },
975
942
  };
976
943
  }, _NftController_addIndividualNft =
@@ -1066,22 +1033,7 @@ async function _NftController_addNftContract(networkClientId, { tokenAddress, us
1066
1033
  // will be fixed once detection uses networkClientIds
1067
1034
  // get name and symbol if ERC721 then put together the metadata
1068
1035
  const contractInformation = await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftContractInformation).call(this, checksumHexAddress, nftMetadata, networkClientId);
1069
- const {
1070
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1071
- // eslint-disable-next-line @typescript-eslint/naming-convention
1072
- asset_contract_type,
1073
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1074
- // eslint-disable-next-line @typescript-eslint/naming-convention
1075
- created_date, symbol, description,
1076
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1077
- // eslint-disable-next-line @typescript-eslint/naming-convention
1078
- external_link,
1079
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1080
- // eslint-disable-next-line @typescript-eslint/naming-convention
1081
- schema_name,
1082
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1083
- // eslint-disable-next-line @typescript-eslint/naming-convention
1084
- collection: { name, image_url, tokenCount }, } = contractInformation;
1036
+ const { asset_contract_type, created_date, symbol, description, external_link, schema_name, collection: { name, image_url, tokenCount }, } = contractInformation;
1085
1037
  // If the nft is auto-detected we want some valid metadata to be present
1086
1038
  if (source === constants_1.Source.Detected &&
1087
1039
  'address' in contractInformation &&
@@ -1157,7 +1109,6 @@ async function _NftController_addNftContract(networkClientId, { tokenAddress, us
1157
1109
  }
1158
1110
  if (type !== controller_utils_1.ERC721 && type !== controller_utils_1.ERC1155) {
1159
1111
  throw rpc_errors_1.rpcErrors.invalidParams(
1160
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1161
1112
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1162
1113
  `Non NFT asset type ${type} not supported by watchNft`);
1163
1114
  }