From 9b9798050dd19a5a52215ddf6c30046bb94ba110 Mon Sep 17 00:00:00 2001 From: sahar-fehri Date: Tue, 15 Oct 2024 18:10:30 +0200 Subject: [PATCH 1/5] chore: update assets-controllers v33.0.0 --- app/core/Engine.ts | 142 +-- package.json | 2 +- .../@metamask+assets-controllers+32.0.0.patch | 1022 ----------------- .../@metamask+assets-controllers+33.0.0.patch | 414 +++++++ yarn.lock | 16 +- 5 files changed, 501 insertions(+), 1095 deletions(-) delete mode 100644 patches/@metamask+assets-controllers+32.0.0.patch create mode 100644 patches/@metamask+assets-controllers+33.0.0.patch diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 95199c1b9eb..ae96b867e80 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -19,7 +19,7 @@ import { TokenListState, TokenListStateChange, TokenRatesController, - TokenRatesState, + TokenRatesControllerState, TokensController, TokensControllerState, CodefiTokenPricesServiceV2, @@ -345,7 +345,7 @@ export interface EngineState { PreferencesController: PreferencesState; PhishingController: PhishingControllerState; TokenBalancesController: TokenBalancesControllerState; - TokenRatesController: TokenRatesState; + TokenRatesController: TokenRatesControllerState; TransactionController: TransactionControllerState; SmartTransactionsController: SmartTransactionsControllerState; SwapsController: SwapsState; @@ -569,6 +569,33 @@ class Engine { getNetworkClientById: networkController.getNetworkClientById.bind(networkController), }); + const accountsControllerMessenger: AccountsControllerMessenger = + this.controllerMessenger.getRestricted({ + name: 'AccountsController', + allowedEvents: [ + 'SnapController:stateChange', + 'KeyringController:accountRemoved', + 'KeyringController:stateChange', + ], + allowedActions: [ + 'KeyringController:getAccounts', + 'KeyringController:getKeyringsByType', + 'KeyringController:getKeyringForAccount', + ], + }); + + const defaultAccountsControllerState: AccountsControllerState = { + internalAccounts: { + accounts: {}, + selectedAccount: '', + }, + }; + + const accountsController = new AccountsController({ + messenger: accountsControllerMessenger, + state: initialState.AccountsController ?? defaultAccountsControllerState, + }); + const nftController = new NftController({ chainId: networkController.getNetworkClientById( networkController?.state.selectedNetworkClientId, @@ -580,10 +607,13 @@ class Engine { allowedActions: [ `${approvalController.name}:addRequest`, `${networkController.name}:getNetworkClientById`, + 'AccountsController:getAccount', + 'AccountsController:getSelectedAccount', ], allowedEvents: [ 'PreferencesController:stateChange', 'NetworkController:networkDidChange', + 'AccountsController:selectedEvmAccountChange', ], }), @@ -619,32 +649,6 @@ class Engine { }), state: initialState.LoggingController, }); - const accountsControllerMessenger: AccountsControllerMessenger = - this.controllerMessenger.getRestricted({ - name: 'AccountsController', - allowedEvents: [ - 'SnapController:stateChange', - 'KeyringController:accountRemoved', - 'KeyringController:stateChange', - ], - allowedActions: [ - 'KeyringController:getAccounts', - 'KeyringController:getKeyringsByType', - 'KeyringController:getKeyringForAccount', - ], - }); - - const defaultAccountsControllerState: AccountsControllerState = { - internalAccounts: { - accounts: {}, - selectedAccount: '', - }, - }; - - const accountsController = new AccountsController({ - messenger: accountsControllerMessenger, - state: initialState.AccountsController ?? defaultAccountsControllerState, - }); const tokensController = new TokensController({ chainId: networkController.getNetworkClientById( networkController?.state.selectedNetworkClientId, @@ -936,21 +940,34 @@ class Engine { ), }); - const accountTrackerController = new AccountTrackerController({ - onPreferencesStateChange, - getIdentities: () => preferencesController.state.identities, - getSelectedAddress: () => accountsController.getSelectedAccount().address, - getMultiAccountBalancesEnabled: () => - preferencesController.state.isMultiAccountBalancesEnabled, - getCurrentChainId: () => - toHexadecimal( - networkController.getNetworkClientById( - networkController?.state.selectedNetworkClientId, - ).configuration.chainId, - ), - getNetworkClientById: - networkController.getNetworkClientById.bind(networkController), - }); + const accountTrackerController = new AccountTrackerController( + { + // @ts-expect-error TODO: Resolve mismatch between base-controller versions fix < ======. + messenger: this.controllerMessenger.getRestricted({ + name: 'AccountTrackerController', + allowedActions: [ + `AccountsController:getSelectedAccount`, + `AccountsController:listAccounts`, + ], + allowedEvents: [ + 'AccountsController:selectedEvmAccountChange', + 'AccountsController:selectedAccountChange', + ], + }), + getMultiAccountBalancesEnabled: () => + preferencesController.state.isMultiAccountBalancesEnabled, + getCurrentChainId: () => + toHexadecimal( + networkController.getNetworkClientById( + networkController?.state.selectedNetworkClientId, + ).configuration.chainId, + ), + getNetworkClientById: + networkController.getNetworkClientById.bind(networkController), + }, + undefined, + { accounts: {} }, + ); const permissionController = new PermissionController({ // @ts-expect-error TODO: Resolve mismatch between base-controller versions. messenger: this.controllerMessenger.getRestricted({ @@ -1480,6 +1497,7 @@ class Engine { 'NetworkController:getState', 'NetworkController:getNetworkClientById', 'PreferencesController:getState', + 'AccountsController:getSelectedAccount', ], }), disabled: false, @@ -1503,28 +1521,24 @@ class Engine { interval: 180000, }), new TokenRatesController({ - onTokensStateChange: (listener) => - this.controllerMessenger.subscribe( - `${tokensController.name}:stateChange`, - listener, - ), - onNetworkStateChange: (listener) => - this.controllerMessenger.subscribe( - AppConstants.NETWORK_STATE_CHANGE_EVENT, - listener, - ), - onPreferencesStateChange, - chainId: networkController.getNetworkClientById( - networkController?.state.selectedNetworkClientId, - ).configuration.chainId, - ticker: networkController.getNetworkClientById( - networkController?.state.selectedNetworkClientId, - ).configuration.ticker, - selectedAddress: preferencesController.state.selectedAddress, + // @ts-expect-error TODO: Resolve mismatch between base-controller versions. + messenger: this.controllerMessenger.getRestricted({ + name: 'TokenRatesController', + allowedActions: [ + 'TokensController:getState', + 'NetworkController:getNetworkClientById', + 'NetworkController:getState', + 'PreferencesController:getState', + ], + allowedEvents: [ + 'PreferencesController:stateChange', + 'TokensController:stateChange', + 'NetworkController:stateChange', + ], + }), tokenPricesService: codefiTokenApiV2, interval: 30 * 60 * 1000, - getNetworkClientById: - networkController.getNetworkClientById.bind(networkController), + state: initialState.TokenRatesController || { marketData: {} }, }), this.transactionController, this.smartTransactionsController, @@ -1990,7 +2004,7 @@ class Engine { NftController.reset(); TokenBalancesController.reset(); - TokenRatesController.update({ marketData: {} }); + TokenRatesController.reset(); // eslint-disable-next-line @typescript-eslint/no-explicit-any (TransactionController as any).update(() => ({ diff --git a/package.json b/package.json index 1b811292afe..9bf13d585d9 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ "@metamask/accounts-controller": "^18.2.1", "@metamask/address-book-controller": "^6.0.1", "@metamask/approval-controller": "^7.0.1", - "@metamask/assets-controllers": "^32.0.0", + "@metamask/assets-controllers": "^33.0.0", "@metamask/base-controller": "^7.0.1", "@metamask/composable-controller": "^3.0.0", "@metamask/contract-metadata": "^2.1.0", diff --git a/patches/@metamask+assets-controllers+32.0.0.patch b/patches/@metamask+assets-controllers+32.0.0.patch deleted file mode 100644 index 875d616b53e..00000000000 --- a/patches/@metamask+assets-controllers+32.0.0.patch +++ /dev/null @@ -1,1022 +0,0 @@ -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-4AC3X2U5.js b/node_modules/@metamask/assets-controllers/dist/chunk-4AC3X2U5.js -index bb55790..c7e7f99 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-4AC3X2U5.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-4AC3X2U5.js -@@ -187,6 +187,18 @@ var TokensController = class extends _basecontroller.BaseController { - } - ); - } -+ /** -+ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO -+ * Resets to the default state -+ */ -+ reset() { -+ this.update((state) => { -+ state.allTokens = {}; -+ state.allIgnoredTokens = {}; -+ state.ignoredTokens = []; -+ state.tokens = []; -+ }); -+ } - /** - * Adds a token to the stored token list. - * -@@ -605,9 +617,13 @@ _selectedAddress = new WeakMap(); - _provider = new WeakMap(); - _abortController = new WeakMap(); - _onNetworkDidChange = new WeakSet(); --onNetworkDidChange_fn = function({ providerConfig }) { -+onNetworkDidChange_fn = function({ selectedNetworkClientId }) { - const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state; -- const { chainId } = providerConfig; -+ const selectedNetworkClient = this.messagingSystem.call( -+ 'NetworkController:getNetworkClientById', -+ selectedNetworkClientId, -+ ); -+ const { chainId } = selectedNetworkClient.configuration; - _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _abortController).abort(); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _abortController, new AbortController()); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _chainId, chainId); -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-CGLUTXI7.js b/node_modules/@metamask/assets-controllers/dist/chunk-CGLUTXI7.js -index 7cc44fa..7a1de65 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-CGLUTXI7.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-CGLUTXI7.js -@@ -44,7 +44,7 @@ var getDefaultNftControllerState = () => ({ - allNfts: {}, - ignoredNfts: [] - }); --var _mutex, _selectedAddress, _chainId, _ipfsGateway, _openSeaEnabled, _useIpfsSubdomains, _isIpfsGatewayEnabled, _getERC721AssetName, _getERC721AssetSymbol, _getERC721TokenURI, _getERC721OwnerOf, _getERC1155BalanceOf, _getERC1155TokenURI, _onNftAdded, _onNetworkControllerNetworkDidChange, onNetworkControllerNetworkDidChange_fn, _onPreferencesControllerStateChange, onPreferencesControllerStateChange_fn, _updateNestedNftState, updateNestedNftState_fn, _getNftInformationFromApi, getNftInformationFromApi_fn, _getNftInformationFromTokenURI, getNftInformationFromTokenURI_fn, _getNftURIAndStandard, getNftURIAndStandard_fn, _getNftInformation, getNftInformation_fn, _getNftContractInformationFromContract, getNftContractInformationFromContract_fn, _getNftContractInformation, getNftContractInformation_fn, _addIndividualNft, addIndividualNft_fn, _addNftContract, addNftContract_fn, _removeAndIgnoreIndividualNft, removeAndIgnoreIndividualNft_fn, _removeIndividualNft, removeIndividualNft_fn, _removeNftContract, removeNftContract_fn, _validateWatchNft, validateWatchNft_fn, _getCorrectChainId, getCorrectChainId_fn; -+var _mutex, _selectedAddress, _chainId, _ipfsGateway, _displayNftMedia, _useIpfsSubdomains, _isIpfsGatewayEnabled, _getERC721AssetName, _getERC721AssetSymbol, _getERC721TokenURI, _getERC721OwnerOf, _getERC1155BalanceOf, _getERC1155TokenURI, _onNftAdded, _onNetworkControllerNetworkDidChange, onNetworkControllerNetworkDidChange_fn, _onPreferencesControllerStateChange, onPreferencesControllerStateChange_fn, _updateNestedNftState, updateNestedNftState_fn, _getNftInformationFromApi, getNftInformationFromApi_fn, _getNftInformationFromTokenURI, getNftInformationFromTokenURI_fn, _getNftURIAndStandard, getNftURIAndStandard_fn, _getNftInformation, getNftInformation_fn, _getNftContractInformationFromContract, getNftContractInformationFromContract_fn, _getNftContractInformation, getNftContractInformation_fn, _addIndividualNft, addIndividualNft_fn, _addNftContract, addNftContract_fn, _removeAndIgnoreIndividualNft, removeAndIgnoreIndividualNft_fn, _removeIndividualNft, removeIndividualNft_fn, _removeNftContract, removeNftContract_fn, _validateWatchNft, validateWatchNft_fn, _getCorrectChainId, getCorrectChainId_fn; - var NftController = class extends _basecontroller.BaseController { - /** - * Creates an NftController instance. -@@ -53,7 +53,7 @@ var NftController = class extends _basecontroller.BaseController { - * @param options.chainId - The chain ID of the current network. - * @param options.selectedAddress - The currently selected address. - * @param options.ipfsGateway - The configured IPFS gateway. -- * @param options.openSeaEnabled - Controls whether the OpenSea API is used. -+ * @param options.displayNftMedia - Controls whether the OpenSea API is used. - * @param options.useIpfsSubdomains - Controls whether IPFS subdomains are used. - * @param options.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not. - * @param options.getERC721AssetName - Gets the name of the asset at the given address. -@@ -71,7 +71,7 @@ var NftController = class extends _basecontroller.BaseController { - chainId: initialChainId, - selectedAddress = "", - ipfsGateway = _controllerutils.IPFS_DEFAULT_GATEWAY_URL, -- openSeaEnabled = false, -+ displayNftMedia = false, - useIpfsSubdomains = true, - isIpfsGatewayEnabled = true, - getERC721AssetName, -@@ -104,7 +104,7 @@ var NftController = class extends _basecontroller.BaseController { - * @param preferencesState - The new state of the preference controller. - * @param preferencesState.selectedAddress - The current selected address. - * @param preferencesState.ipfsGateway - The configured IPFS gateway. -- * @param preferencesState.openSeaEnabled - Controls whether the OpenSea API is used. -+ * @param preferencesState.displayNftMedia - Controls whether the OpenSea API is used. - * @param preferencesState.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not. - */ - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _onPreferencesControllerStateChange); -@@ -233,7 +233,7 @@ var NftController = class extends _basecontroller.BaseController { - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _selectedAddress, void 0); - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _chainId, void 0); - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _ipfsGateway, void 0); -- _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _openSeaEnabled, void 0); -+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _displayNftMedia, void 0); - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _useIpfsSubdomains, void 0); - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _isIpfsGatewayEnabled, void 0); - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getERC721AssetName, void 0); -@@ -246,7 +246,7 @@ var NftController = class extends _basecontroller.BaseController { - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _selectedAddress, selectedAddress); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _chainId, initialChainId); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _ipfsGateway, ipfsGateway); -- _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _openSeaEnabled, openSeaEnabled); -+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _displayNftMedia, displayNftMedia); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _useIpfsSubdomains, useIpfsSubdomains); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isIpfsGatewayEnabled, isIpfsGatewayEnabled); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getERC721AssetName, getERC721AssetName); -@@ -268,6 +268,17 @@ var NftController = class extends _basecontroller.BaseController { - getNftApi() { - return `${_controllerutils.NFT_API_BASE_URL}/tokens`; - } -+ /** -+ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO -+ * Resets to the default state -+ */ -+ reset() { -+ this.update((state) => { -+ state.allNftContracts = {}; -+ state.allNfts = {}; -+ state.ignoredNfts = []; -+ }); -+ } - /** - * Adds a new suggestedAsset to state. Parameters will be validated according to - * asset type being watched. A `:pending` hub event will be emitted once added. -@@ -771,7 +782,7 @@ _mutex = new WeakMap(); - _selectedAddress = new WeakMap(); - _chainId = new WeakMap(); - _ipfsGateway = new WeakMap(); --_openSeaEnabled = new WeakMap(); -+_displayNftMedia = new WeakMap(); - _useIpfsSubdomains = new WeakMap(); - _isIpfsGatewayEnabled = new WeakMap(); - _getERC721AssetName = new WeakMap(); -@@ -797,14 +808,14 @@ _onPreferencesControllerStateChange = new WeakSet(); - onPreferencesControllerStateChange_fn = async function({ - selectedAddress, - ipfsGateway, -- openSeaEnabled, -+ displayNftMedia, - isIpfsGatewayEnabled - }) { - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _selectedAddress, selectedAddress); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _ipfsGateway, ipfsGateway); -- _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _openSeaEnabled, openSeaEnabled); -+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _displayNftMedia, displayNftMedia); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isIpfsGatewayEnabled, isIpfsGatewayEnabled); -- const needsUpdateNftMetadata = isIpfsGatewayEnabled && ipfsGateway !== "" || openSeaEnabled; -+ const needsUpdateNftMetadata = isIpfsGatewayEnabled && ipfsGateway !== "" || displayNftMedia; - if (needsUpdateNftMetadata) { - const nfts = this.state.allNfts[selectedAddress]?.[_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _chainId)] ?? []; - const nftsToUpdate = nfts.filter( -@@ -818,6 +829,7 @@ onPreferencesControllerStateChange_fn = async function({ - } - } - }; -+ - _updateNestedNftState = new WeakSet(); - updateNestedNftState_fn = function(newCollection, baseStateKey, { userAddress, chainId }) { - this.update((state) => { -@@ -850,12 +862,25 @@ getNftInformationFromApi_fn = async function(contractAddress, tokenId) { - } - } - }); -+ const getCollectionParams = new URLSearchParams({ -+ chainId: "1", -+ id: `${nftInformation?.tokens[0]?.token?.collection?.id}` -+ }).toString(); -+ const collectionInformation = await _controllerutils.fetchWithErrorHandling.call(void 0, { -+ url: `${_controllerutils.NFT_API_BASE_URL}/collections?${getCollectionParams}`, -+ options: { -+ headers: { -+ Version: '1' -+ } -+ } -+ }); - if (!nftInformation?.tokens?.[0]?.token) { - return { - name: null, - description: null, - image: null, -- standard: null -+ standard: null, -+ error: 'Opensea import error', - }; - } - const { -@@ -887,7 +912,16 @@ getNftInformationFromApi_fn = async function(contractAddress, tokenId) { - }, - rarityRank && { rarityRank }, - rarity && { rarity }, -- collection && { collection } -+ (collection || collectionInformation) && { -+ collection: { -+ ...collection || {}, -+ creator: collection?.creator || collectionInformation?.collections[0].creator, -+ openseaVerificationStatus: collectionInformation?.collections[0].openseaVerificationStatus, -+ contractDeployedAt: collectionInformation?.collections[0].contractDeployedAt, -+ ownerCount: collectionInformation?.collections[0].ownerCount, -+ topBid: collectionInformation?.collections[0].topBid -+ } -+ } - ); - return nftMetadata; - }; -@@ -904,10 +938,11 @@ getNftInformationFromTokenURI_fn = async function(contractAddress, tokenId, netw - description: null, - standard: standard || null, - favorite: false, -- tokenURI: tokenURI ?? null -+ tokenURI: tokenURI ?? null, -+ error: 'URI import error', - }; - } -- const isDisplayNFTMediaToggleEnabled = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _openSeaEnabled); -+ const isDisplayNFTMediaToggleEnabled = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _displayNftMedia); - if (!hasIpfsTokenURI && !isDisplayNFTMediaToggleEnabled) { - return { - image: null, -@@ -925,6 +960,16 @@ getNftInformationFromTokenURI_fn = async function(contractAddress, tokenId, netw - _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _useIpfsSubdomains) - ); - } -+ if (tokenURI.startsWith("data:image/")) { -+ return { -+ image: tokenURI, -+ name: null, -+ description: null, -+ standard: standard || null, -+ favorite: false, -+ tokenURI: tokenURI ?? null -+ }; -+ } - try { - const object = await _controllerutils.handleFetch.call(void 0, tokenURI); - const image = Object.prototype.hasOwnProperty.call(object, "image") ? "image" : ( -@@ -946,7 +991,8 @@ getNftInformationFromTokenURI_fn = async function(contractAddress, tokenId, netw - description: null, - standard: standard || null, - favorite: false, -- tokenURI: tokenURI ?? null -+ tokenURI: tokenURI ?? null, -+ error: 'URI import error', - }; - } - }; -@@ -977,15 +1023,27 @@ getNftInformation_fn = async function(contractAddress, tokenId, networkClientId) - _controllerutils.safelyExecute.call(void 0, - () => _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getNftInformationFromTokenURI, getNftInformationFromTokenURI_fn).call(this, contractAddress, tokenId, networkClientId) - ), -- _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _openSeaEnabled) && chainId === "0x1" ? _controllerutils.safelyExecute.call(void 0, -+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _displayNftMedia) && chainId === "0x1" ? _controllerutils.safelyExecute.call(void 0, - () => _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getNftInformationFromApi, getNftInformationFromApi_fn).call(this, contractAddress, tokenId) - ) : void 0 - ]); -+ -+ if (blockchainMetadata?.error && nftApiMetadata?.error) { -+ return { -+ image: null, -+ name: null, -+ description: null, -+ standard: blockchainMetadata.standard ?? null, -+ favorite: false, -+ tokenURI: blockchainMetadata.tokenURI ?? null, -+ error: 'Both import failed', -+ }; -+ } - return { - ...nftApiMetadata, - name: blockchainMetadata?.name ?? nftApiMetadata?.name ?? null, - description: blockchainMetadata?.description ?? nftApiMetadata?.description ?? null, -- image: blockchainMetadata?.image ?? nftApiMetadata?.image ?? null, -+ image: nftApiMetadata?.image ?? blockchainMetadata?.image ?? null, - standard: blockchainMetadata?.standard ?? nftApiMetadata?.standard ?? null, - tokenURI: blockchainMetadata?.tokenURI ?? null - }; -@@ -1048,7 +1106,8 @@ addIndividualNft_fn = async function(tokenAddress, tokenId, nftMetadata, nftCont - nftMetadata, - existingEntry - ); -- if (!differentMetadata && existingEntry.isCurrentlyOwned) { -+ const hasNewFields = _chunkNEXY7SE2js.hasNewCollectionFields(nftMetadata, existingEntry); -+ if (!differentMetadata && existingEntry.isCurrentlyOwned && !hasNewFields) { - return; - } - const indexToUpdate = nfts.findIndex( -@@ -1080,7 +1139,8 @@ addIndividualNft_fn = async function(tokenAddress, tokenId, nftMetadata, nftCont - symbol: nftContract.symbol, - tokenId: tokenId.toString(), - standard: nftMetadata.standard, -- source -+ source, -+ tokenURI: nftMetadata.tokenURI, - }); - } - } finally { -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-ELSMS5S7.js b/node_modules/@metamask/assets-controllers/dist/chunk-ELSMS5S7.js -index 45254ad..f3c6204 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-ELSMS5S7.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-ELSMS5S7.js -@@ -87,6 +87,7 @@ var CurrencyRateController = class extends _pollingcontroller.StaticIntervalPoll - const nativeCurrencyForExchangeRate = Object.values( - _controllerutils.TESTNET_TICKER_SYMBOLS - ).includes(nativeCurrency) ? _controllerutils.FALL_BACK_VS_CURRENCY : nativeCurrency; -+ let shouldUpdateState = true; - try { - if (currentCurrency && nativeCurrency && // if either currency is an empty string we can skip the comparison - // because it will result in an error from the api and ultimately -@@ -103,23 +104,27 @@ var CurrencyRateController = class extends _pollingcontroller.StaticIntervalPoll - } - } catch (error) { - if (!(error instanceof Error && error.message.includes("market does not exist for this coin pair"))) { -+ // Don't update state on transient / unexpected errors -+ shouldUpdateState = false; - throw error; - } - } finally { - try { -- this.update(() => { -- return { -- currencyRates: { -- ...currencyRates, -- [nativeCurrency]: { -- conversionDate, -- conversionRate, -- usdConversionRate -- } -- }, -- currentCurrency -- }; -- }); -+ if(shouldUpdateState) { -+ this.update(() => { -+ return { -+ currencyRates: { -+ ...currencyRates, -+ [nativeCurrency]: { -+ conversionDate, -+ conversionRate, -+ usdConversionRate -+ } -+ }, -+ currentCurrency -+ }; -+ }); -+ } - } finally { - releaseLock(); - } -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-GU53EI7A.js b/node_modules/@metamask/assets-controllers/dist/chunk-GU53EI7A.js -index 33b048f..5867375 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-GU53EI7A.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-GU53EI7A.js -@@ -61,7 +61,7 @@ var AccountTrackerController = class extends _pollingcontroller.StaticIntervalPo - this.syncAccounts(chainId); - const { accounts, accountsByChainId } = this.state; - const isMultiAccountBalancesEnabled = this.getMultiAccountBalancesEnabled(); -- const accountsToUpdate = isMultiAccountBalancesEnabled ? Object.keys(accounts) : [this.getSelectedAddress()]; -+ const accountsToUpdate = isMultiAccountBalancesEnabled ? Object.keys(accounts) : [_controllerutils.toChecksumHexAddress.call(void 0, this.getSelectedAddress())]; - const accountsForChain = { ...accountsByChainId[chainId] }; - for (const address of accountsToUpdate) { - const balance = await this.getBalanceFromChain(address, ethQuery); -@@ -80,9 +80,8 @@ var AccountTrackerController = class extends _pollingcontroller.StaticIntervalPo - [chainId]: accountsForChain - } - }); -- } catch (err) { -+ } finally { - releaseLock(); -- throw err; - } - }; - this.defaultConfig = { -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-HDI4L2DD.js b/node_modules/@metamask/assets-controllers/dist/chunk-HDI4L2DD.js -index 76e3362..e11991d 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-HDI4L2DD.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-HDI4L2DD.js -@@ -165,7 +165,10 @@ var TokenDetectionController = class extends _pollingcontroller.StaticIntervalPo - if (!this.isActive) { - return; - } -- const addressAgainstWhichToDetect = selectedAddress ?? _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAddress); -+ //const addressAgainstWhichToDetect = selectedAddress ?? _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAddress); -+ const currentAddress = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAddress); -+ const currentAddressChecksum = _controllerutils.toChecksumHexAddress.call(void 0, currentAddress) -+ const addressAgainstWhichToDetect = _controllerutils.toChecksumHexAddress.call(void 0, selectedAddress) ?? currentAddressChecksum; - const { chainId, networkClientId: selectedNetworkClientId } = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getCorrectChainIdAndNetworkClientId, getCorrectChainIdAndNetworkClientId_fn).call(this, networkClientId); - const chainIdAgainstWhichToDetect = chainId; - const networkClientIdAgainstWhichToDetect = selectedNetworkClientId; -@@ -224,12 +227,10 @@ registerEventListeners_fn = function() { - ); - this.messagingSystem.subscribe( - "PreferencesController:stateChange", -- async ({ selectedAddress: newSelectedAddress, useTokenDetection }) => { -- const isSelectedAddressChanged = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAddress) !== newSelectedAddress; -+ async ({ useTokenDetection }) => { - const isDetectionChangedFromPreferences = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isDetectionEnabledFromPreferences) !== useTokenDetection; -- _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _selectedAddress, newSelectedAddress); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isDetectionEnabledFromPreferences, useTokenDetection); -- if (isSelectedAddressChanged || isDetectionChangedFromPreferences) { -+ if (isDetectionChangedFromPreferences) { - await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _restartTokenDetection, restartTokenDetection_fn).call(this, { - selectedAddress: _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAddress) - }); -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-IBK6AXPP.js b/node_modules/@metamask/assets-controllers/dist/chunk-IBK6AXPP.js -index f7509a1..4573718 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-IBK6AXPP.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-IBK6AXPP.js -@@ -19,7 +19,7 @@ function getDefaultTokenBalancesState() { - contractBalances: {} - }; - } --var _handle, _getERC20BalanceOf, _interval, _tokens, _disabled; -+var _handle, _getERC20BalanceOf, _interval, _tokens, _disabled, _updateInProgress; - var TokenBalancesController = class extends _basecontroller.BaseController { - /** - * Construct a Token Balances Controller. -@@ -54,9 +54,11 @@ var TokenBalancesController = class extends _basecontroller.BaseController { - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _interval, void 0); - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _tokens, void 0); - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _disabled, void 0); -+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _updateInProgress, void 0); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _disabled, disabled); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _interval, interval); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _tokens, tokens); -+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _updateInProgress, false); - this.messagingSystem.subscribe( - "TokensController:stateChange", - ({ tokens: newTokens, detectedTokens }) => { -@@ -79,6 +81,15 @@ var TokenBalancesController = class extends _basecontroller.BaseController { - disable() { - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _disabled, true); - } -+ /** -+ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO -+ * Resets to the default state -+ */ -+ reset() { -+ this.update((state) => { -+ state.contractBalances = {}; -+ }); -+ } - /** - * Starts a new polling interval. - * -@@ -100,27 +111,34 @@ var TokenBalancesController = class extends _basecontroller.BaseController { - * Updates balances for all tokens. - */ - async updateBalances() { -- if (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _disabled)) { -+ if (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _disabled) || _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _updateInProgress)) { - return; - } - const { selectedAddress } = this.messagingSystem.call( - "PreferencesController:getState" - ); - const newContractBalances = {}; -- for (const token of _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _tokens)) { -- const { address } = token; -- try { -- const balance = await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getERC20BalanceOf).call(this, address, selectedAddress); -- newContractBalances[address] = _controllerutils.toHex.call(void 0, balance); -- token.hasBalanceError = false; -- } catch (error) { -- newContractBalances[address] = _controllerutils.toHex.call(void 0, 0); -- token.hasBalanceError = true; -- } -- } -+ const balancePromises = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _tokens).map((token) => { -+ const { address } = token; -+ return _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getERC20BalanceOf).call(this, address, selectedAddress).then((balance) => { -+ newContractBalances[address] = _controllerutils.toHex.call(void 0, balance); -+ token = { -+ ...token, -+ hasBalanceError: false -+ }; -+ }).catch((error) => { -+ newContractBalances[address] = _controllerutils.toHex.call(void 0, 0); -+ token = { -+ ...token, -+ hasBalanceError: true -+ }; -+ }); -+ }); -+ await Promise.all(balancePromises); - this.update((state) => { - state.contractBalances = newContractBalances; - }); -+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _updateInProgress, false); - } - }; - _handle = new WeakMap(); -@@ -128,6 +146,7 @@ _getERC20BalanceOf = new WeakMap(); - _interval = new WeakMap(); - _tokens = new WeakMap(); - _disabled = new WeakMap(); -+_updateInProgress = new WeakMap(); - var TokenBalancesController_default = TokenBalancesController; - - -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-JUI3XNEF.js b/node_modules/@metamask/assets-controllers/dist/chunk-JUI3XNEF.js -index 44804c8..911a6e6 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-JUI3XNEF.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-JUI3XNEF.js -@@ -247,10 +247,15 @@ var TokenListController = class extends _pollingcontroller.StaticIntervalPolling - }; - _onNetworkControllerStateChange = new WeakSet(); - onNetworkControllerStateChange_fn = async function(networkControllerState) { -- if (this.chainId !== networkControllerState.providerConfig.chainId) { -+ const selectedNetworkClient = this.messagingSystem.call( -+ "NetworkController:getNetworkClientById", -+ networkControllerState.selectedNetworkClientId -+ ); -+ const { chainId } = selectedNetworkClient.configuration; -+ if (this.chainId !== chainId) { - this.abortController.abort(); - this.abortController = new AbortController(); -- this.chainId = networkControllerState.providerConfig.chainId; -+ this.chainId = chainId; - if (this.state.preventPollingOnNetworkRestart) { - this.clearingTokenListData(); - } else { -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-QFDTOEYR.js b/node_modules/@metamask/assets-controllers/dist/chunk-QFDTOEYR.js -index 5335fa5..0854306 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-QFDTOEYR.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-QFDTOEYR.js -@@ -8,12 +8,14 @@ var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js'); - // src/NftDetectionController.ts - - -- -+var utils_1 = require('@metamask/utils'); -+var _chunkR4HATJKUjs = require('./chunk-NEXY7SE2.js'); - - - - - var _controllerutils = require('@metamask/controller-utils'); -+var supportedNftDetectionNetworks = [_controllerutils.ChainId.mainnet]; - var _pollingcontroller = require('@metamask/polling-controller'); - var DEFAULT_INTERVAL = 18e4; - var controllerName = "NftDetectionController"; -@@ -24,7 +26,8 @@ var BlockaidResultType = /* @__PURE__ */ ((BlockaidResultType2) => { - BlockaidResultType2["Malicious"] = "Malicious"; - return BlockaidResultType2; - })(BlockaidResultType || {}); --var _intervalId, _interval, _disabled, _addNft, _getNftState, _stopPolling, stopPolling_fn, _startPolling, startPolling_fn, _onPreferencesControllerStateChange, onPreferencesControllerStateChange_fn, _getOwnerNftApi, getOwnerNftApi_fn, _getOwnerNfts, getOwnerNfts_fn; -+var MAX_GET_COLLECTION_BATCH_SIZE = 20; -+var _intervalId, _interval, _disabled, _addNft, _getNftState, _stopPolling, stopPolling_fn, _startPolling, startPolling_fn, _onPreferencesControllerStateChange, onPreferencesControllerStateChange_fn, _getOwnerNftApi, getOwnerNftApi_fn, _getOwnerNfts, getOwnerNfts_fn, _inProcessNftFetchingUpdates; - var NftDetectionController = class extends _pollingcontroller.StaticIntervalPollingController { - /** - * The controller options -@@ -68,8 +71,10 @@ var NftDetectionController = class extends _pollingcontroller.StaticIntervalPoll - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _disabled, void 0); - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _addNft, void 0); - _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getNftState, void 0); -+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _inProcessNftFetchingUpdates, void 0); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _interval, interval); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _disabled, disabled); -+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _inProcessNftFetchingUpdates, {}); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getNftState, getNftState); - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _addNft, addNft); - this.messagingSystem.subscribe( -@@ -126,62 +131,152 @@ var NftDetectionController = class extends _pollingcontroller.StaticIntervalPoll - */ - async detectNfts(options) { - const userAddress = options?.userAddress ?? this.messagingSystem.call("PreferencesController:getState").selectedAddress; -- if (!this.isMainnet() || _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _disabled)) { -+ -+ const { selectedNetworkClientId } = this.messagingSystem.call("NetworkController:getState"); -+ const { configuration: { chainId }} = this.messagingSystem.call( -+ "NetworkController:getNetworkClientById", -+ selectedNetworkClientId -+ ); -+ if (!supportedNftDetectionNetworks.includes(chainId) || _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _disabled)) { - return; - } - if (!userAddress) { - return; - } -- const apiNfts = await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getOwnerNfts, getOwnerNfts_fn).call(this, userAddress); -- const addNftPromises = apiNfts.map(async (nft) => { -- const { -- tokenId: token_id, -- contract, -- kind, -- image: image_url, -- imageSmall: image_thumbnail_url, -- metadata: { imageOriginal: image_original_url } = {}, -- name, -- description, -- attributes, -- topBid, -- lastSale, -- rarityRank, -- rarityScore, -- collection -- } = nft.token; -- let ignored; -- const { ignoredNfts } = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getNftState).call(this); -- if (ignoredNfts.length > 0) { -- ignored = ignoredNfts.find((c) => { -- return c.address === _controllerutils.toChecksumHexAddress.call(void 0, contract) && c.tokenId === token_id; -- }); -- } -- if (!ignored) { -- const nftMetadata = Object.assign( -- {}, -- { name }, -- description && { description }, -- image_url && { image: image_url }, -- image_thumbnail_url && { imageThumbnail: image_thumbnail_url }, -- image_original_url && { imageOriginal: image_original_url }, -- kind && { standard: kind.toUpperCase() }, -- lastSale && { lastSale }, -- attributes && { attributes }, -- topBid && { topBid }, -- rarityRank && { rarityRank }, -- rarityScore && { rarityScore }, -- collection && { collection } -+ -+ const updateKey = `${chainId}:${userAddress}`; -+ if (updateKey in _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _inProcessNftFetchingUpdates)) { -+ await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _inProcessNftFetchingUpdates)[updateKey]; -+ return; -+ } -+ const { -+ promise: inProgressUpdate, -+ resolve: updateSucceeded, -+ reject: updateFailed -+ } = utils_1.createDeferredPromise.call(void 0, { suppressUnhandledRejection: true }); -+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _inProcessNftFetchingUpdates)[updateKey] = inProgressUpdate; -+ let next; -+ let apiNfts = []; -+ let resultNftApi; -+ try{ -+ do { -+ resultNftApi = await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getOwnerNfts, getOwnerNfts_fn).call(this, userAddress, chainId, next); -+ apiNfts = resultNftApi.tokens.filter( -+ (elm) => elm.token.isSpam === false && (elm.blockaidResult?.result_type ? elm.blockaidResult?.result_type === "Benign" /* Benign */ : true) - ); -- await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _addNft).call(this, contract, token_id, { -- nftMetadata, -- userAddress, -- source: "detected" /* Detected */, -- networkClientId: options?.networkClientId -+ const collections = apiNfts.reduce((acc, currValue) => { -+ if (!acc.includes(currValue.token.contract) && currValue.token.contract === currValue?.token?.collection?.id) { -+ acc.push(currValue.token.contract); -+ } -+ return acc; -+ }, []); -+ if (collections.length !== 0) { -+ const collectionResponse = await _chunkR4HATJKUjs.reduceInBatchesSerially.call(void 0, { -+ values: collections, -+ batchSize: MAX_GET_COLLECTION_BATCH_SIZE, -+ eachBatch: async (allResponses, batch) => { -+ const params = new URLSearchParams( -+ batch.map((s) => ["contract", s]) -+ ); -+ params.append("chainId", "1"); -+ const collectionResponseForBatch = await _controllerutils.fetchWithErrorHandling.call(void 0, -+ { -+ url: `${_controllerutils.NFT_API_BASE_URL}/collections?${params.toString()}`, -+ options: { -+ headers: { -+ Version: '1' -+ } -+ }, -+ timeout: 15000 -+ } -+ ); -+ return { -+ ...allResponses, -+ ...collectionResponseForBatch -+ }; -+ }, -+ initialResult: {} -+ }); -+ -+ if (collectionResponse.collections?.length) { -+ apiNfts.forEach((singleNFT) => { -+ const found = collectionResponse.collections.find( -+ (elm) => elm.id?.toLowerCase() === singleNFT.token.contract.toLowerCase() -+ ); -+ if (found) { -+ singleNFT.token = { -+ ...singleNFT.token, -+ collection: { -+ ...singleNFT.token.collection ?? {}, -+ creator: found?.creator, -+ openseaVerificationStatus: found?.openseaVerificationStatus, -+ contractDeployedAt: found.contractDeployedAt, -+ ownerCount: found.ownerCount, -+ topBid: found.topBid -+ } -+ }; -+ } -+ }); -+ } -+ } -+ -+ const addNftPromises = apiNfts.map(async (nft) => { -+ const { -+ tokenId, -+ contract, -+ kind, -+ image: imageUrl, -+ imageSmall: imageThumbnailUrl, -+ metadata: { imageOriginal: imageOriginalUrl } = {}, -+ name, -+ description, -+ attributes, -+ topBid, -+ lastSale, -+ rarityRank, -+ rarityScore, -+ collection -+ } = nft.token; -+ let ignored; -+ const { ignoredNfts } = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getNftState).call(this); -+ if (ignoredNfts.length) { -+ ignored = ignoredNfts.find((c) => { -+ return c.address === _controllerutils.toChecksumHexAddress.call(void 0, contract) && c.tokenId === tokenId; -+ }); -+ } -+ if (!ignored) { -+ const nftMetadata = Object.assign( -+ {}, -+ { name }, -+ description && { description }, -+ imageUrl && { image: imageUrl }, -+ imageThumbnailUrl && { imageThumbnail: imageThumbnailUrl }, -+ imageOriginalUrl && { imageOriginal: imageOriginalUrl }, -+ kind && { standard: kind.toUpperCase() }, -+ lastSale && { lastSale }, -+ attributes && { attributes }, -+ topBid && { topBid }, -+ rarityRank && { rarityRank }, -+ rarityScore && { rarityScore }, -+ collection && { collection } -+ ); -+ await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _addNft).call(this, contract, tokenId, { -+ nftMetadata, -+ userAddress, -+ source: "detected" /* Detected */, -+ networkClientId: options?.networkClientId -+ }); -+ } - }); -- } -- }); -- await Promise.all(addNftPromises); -+ await Promise.all(addNftPromises); -+ } while(next = resultNftApi.continuation) -+ updateSucceeded(); -+ }catch(error){ -+ updateFailed(error); -+ throw error; -+ }finally{ -+ delete _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _inProcessNftFetchingUpdates)[updateKey]; -+ } - } - }; - _intervalId = new WeakMap(); -@@ -190,6 +285,7 @@ _disabled = new WeakMap(); - _addNft = new WeakMap(); - _getNftState = new WeakMap(); - _stopPolling = new WeakSet(); -+_inProcessNftFetchingUpdates = new WeakMap(); - stopPolling_fn = function() { - if (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _intervalId)) { - clearInterval(_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _intervalId)); -@@ -207,41 +303,26 @@ _onPreferencesControllerStateChange = new WeakSet(); - onPreferencesControllerStateChange_fn = function({ useNftDetection }) { - if (!useNftDetection !== _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _disabled)) { - _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _disabled, !useNftDetection); -- if (useNftDetection) { -- this.start(); -- } else { -- this.stop(); -- } - } - }; - _getOwnerNftApi = new WeakSet(); --getOwnerNftApi_fn = function({ address, next }) { -- return `${_controllerutils.NFT_API_BASE_URL}/users/${address}/tokens?chainIds=1&limit=50&includeTopBid=true&continuation=${next ?? ""}`; -+getOwnerNftApi_fn = function({ chainId, address, next }) { -+ return `${_controllerutils.NFT_API_BASE_URL}/users/${address}/tokens?chainIds=${chainId}&limit=50&includeTopBid=true&continuation=${next ?? ""}`; - }; - _getOwnerNfts = new WeakSet(); --getOwnerNfts_fn = async function(address) { -- let nftApiResponse; -- let nfts = []; -- let next; -- do { -- nftApiResponse = await _controllerutils.fetchWithErrorHandling.call(void 0, { -- url: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getOwnerNftApi, getOwnerNftApi_fn).call(this, { address, next }), -- options: { -- headers: { -- Version: _controllerutils.NFT_API_VERSION -- } -- }, -- timeout: _controllerutils.NFT_API_TIMEOUT -- }); -- if (!nftApiResponse) { -- return nfts; -- } -- const newNfts = nftApiResponse.tokens?.filter( -- (elm) => elm.token.isSpam === false && (elm.blockaidResult?.result_type ? elm.blockaidResult?.result_type === "Benign" /* Benign */ : true) -- ) ?? []; -- nfts = [...nfts, ...newNfts]; -- } while (next = nftApiResponse.continuation); -- return nfts; -+getOwnerNfts_fn = async function(address, chainId, cursor) { -+ const convertedChainId = _controllerutils.convertHexToDecimal.call(void 0, chainId).toString(); -+ const url = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getOwnerNftApi, getOwnerNftApi_fn).call(this, { -+ chainId: convertedChainId, -+ address, -+ next: cursor -+ }); -+ const nftApiResponse = await _controllerutils.handleFetch.call(void 0, url, { -+ headers: { -+ Version: '1' -+ } -+ }); -+ return nftApiResponse; - }; - var NftDetectionController_default = NftDetectionController; - -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-QHWKLZUC.js b/node_modules/@metamask/assets-controllers/dist/chunk-QHWKLZUC.js -index 6f461a4..a3573af 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-QHWKLZUC.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-QHWKLZUC.js -@@ -69,9 +69,10 @@ var AssetsContractController = class extends _basecontroller.BaseControllerV1 { - this.configure({ ipfsGateway }); - }); - onNetworkDidChange((networkState) => { -- if (this.config.chainId !== networkState.providerConfig.chainId) { -+ const {configuration: { chainId}} = this.getNetworkClientById(networkState.selectedNetworkClientId); -+ if (this.config.chainId !== chainId) { - this.configure({ -- chainId: networkState.providerConfig.chainId -+ chainId, - }); - } - }); -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-UEDNQBJN.js b/node_modules/@metamask/assets-controllers/dist/chunk-UEDNQBJN.js -index 80cecfb..e19a2e9 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-UEDNQBJN.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-UEDNQBJN.js -@@ -380,7 +380,7 @@ fetchAndMapExchangeRatesForSupportedNativeCurrency_fn = async function({ - (obj, [tokenAddress, token]) => { - obj = { - ...obj, -- [tokenAddress.toLowerCase()]: { ...token } -+ [tokenAddress]: { ...token } - }; - return obj; - }, -@@ -416,7 +416,7 @@ fetchAndMapExchangeRatesForUnsupportedNativeCurrency_fn = async function({ - ...acc, - [tokenAddress]: { - ...token, -- value: token.value ? token.value * fallbackCurrencyToNativeCurrencyConversionRate : void 0 -+ price: token.price ? token.price * fallbackCurrencyToNativeCurrencyConversionRate : void 0 - } - }; - return acc; -diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-Z6TBQQE5.js b/node_modules/@metamask/assets-controllers/dist/chunk-Z6TBQQE5.js -index 2f1b66f..f4acd79 100644 ---- a/node_modules/@metamask/assets-controllers/dist/chunk-Z6TBQQE5.js -+++ b/node_modules/@metamask/assets-controllers/dist/chunk-Z6TBQQE5.js -@@ -295,13 +295,12 @@ var CodefiTokenPricesServiceV2 = class { - (obj, tokenAddress) => { - const lowercasedTokenAddress = tokenAddress.toLowerCase(); - const marketData = addressCryptoDataMap[lowercasedTokenAddress]; -- if (marketData === void 0) { -+ if (!marketData) { - return obj; - } -- const { price } = marketData; -+ - const token = { - tokenAddress, -- value: price, - currency, - ...marketData - }; -diff --git a/node_modules/@metamask/assets-controllers/dist/types/NftController.d.ts b/node_modules/@metamask/assets-controllers/dist/types/NftController.d.ts -index bbf4f12..38b1276 100644 ---- a/node_modules/@metamask/assets-controllers/dist/types/NftController.d.ts -+++ b/node_modules/@metamask/assets-controllers/dist/types/NftController.d.ts -@@ -6,7 +6,7 @@ import type { PreferencesControllerStateChangeEvent } from '@metamask/preference - import type { Hex } from '@metamask/utils'; - import type { AssetsContractController } from './AssetsContractController'; - import { Source } from './constants'; --import type { Collection, Attributes, LastSale } from './NftDetectionController'; -+import type { Collection, Attributes, LastSale, TopBid } from './NftDetectionController'; - type NFTStandardType = 'ERC721' | 'ERC1155'; - type SuggestedNftMeta = { - asset: { -@@ -107,11 +107,13 @@ export type NftMetadata = { - creator?: string; - transactionId?: string; - tokenURI?: string | null; -+ error?: string; - collection?: Collection; - address?: string; -- attributes?: Attributes; -+ attributes?: Attributes[]; - lastSale?: LastSale; - rarityRank?: string; -+ topBid?: TopBid; - }; - /** - * @type NftControllerState -@@ -420,6 +422,11 @@ export declare class NftController extends BaseController; -+ /** -+ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO -+ * Resets to the default state -+ */ -+ reset(): void; - } - export default NftController; - //# sourceMappingURL=NftController.d.ts.map -\ No newline at end of file -diff --git a/node_modules/@metamask/assets-controllers/dist/types/NftDetectionController.d.ts b/node_modules/@metamask/assets-controllers/dist/types/NftDetectionController.d.ts -index 758a85e..a4a4b72 100644 ---- a/node_modules/@metamask/assets-controllers/dist/types/NftDetectionController.d.ts -+++ b/node_modules/@metamask/assets-controllers/dist/types/NftDetectionController.d.ts -@@ -225,7 +225,39 @@ export type Attributes = { - topBidValue?: number | null; - createdAt?: string; - }; --export type Collection = { -+export type GetCollectionsResponse = { -+ collections: CollectionResponse[]; -+}; -+export type CollectionResponse = { -+ id?: string; -+ openseaVerificationStatus?: string; -+ contractDeployedAt?: string; -+ creator?: string; -+ ownerCount?: string; -+ topBid?: TopBid & { -+ sourceDomain?: string; -+ }; -+}; -+export type FloorAskCollection = { -+ id?: string; -+ price?: Price; -+ maker?: string; -+ kind?: string; -+ validFrom?: number; -+ validUntil?: number; -+ source?: SourceCollection; -+ rawData?: Metadata; -+ isNativeOffChainCancellable?: boolean; -+}; -+ -+export type SourceCollection = { -+ id: string; -+ domain: string; -+ name: string; -+ icon: string; -+ url: string; -+}; -+export type TokenCollection = { - id?: string; - name?: string; - slug?: string; -@@ -241,7 +273,9 @@ export type Collection = { - floorAskPrice?: Price; - royaltiesBps?: number; - royalties?: Royalties[]; -+ floorAsk?: FloorAskCollection; - }; -+export type Collection = TokenCollection & CollectionResponse; - export type Royalties = { - bps?: number; - recipient?: string; -diff --git a/node_modules/@metamask/assets-controllers/dist/types/TokenBalancesController.d.ts b/node_modules/@metamask/assets-controllers/dist/types/TokenBalancesController.d.ts -index 52bb3ac..d4d5c0a 100644 ---- a/node_modules/@metamask/assets-controllers/dist/types/TokenBalancesController.d.ts -+++ b/node_modules/@metamask/assets-controllers/dist/types/TokenBalancesController.d.ts -@@ -79,6 +79,11 @@ export declare class TokenBalancesController extends BaseController; -+ /** -+ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO -+ * Resets to the default state -+ */ -+ reset(): void; - } - export default TokenBalancesController; - //# sourceMappingURL=TokenBalancesController.d.ts.map -\ No newline at end of file -diff --git a/node_modules/@metamask/assets-controllers/dist/types/TokensController.d.ts b/node_modules/@metamask/assets-controllers/dist/types/TokensController.d.ts -index bc4126d..ce8016a 100644 ---- a/node_modules/@metamask/assets-controllers/dist/types/TokensController.d.ts -+++ b/node_modules/@metamask/assets-controllers/dist/types/TokensController.d.ts -@@ -162,6 +162,11 @@ export declare class TokensController extends BaseController { + BlockaidResultType2["Malicious"] = "Malicious"; + return BlockaidResultType2; + })(BlockaidResultType || {}); ++var MAX_GET_COLLECTION_BATCH_SIZE = 20; + var _disabled, _addNft, _getNftState, _inProcessNftFetchingUpdates, _onPreferencesControllerStateChange, onPreferencesControllerStateChange_fn, _getOwnerNftApi, getOwnerNftApi_fn, _getOwnerNfts, getOwnerNfts_fn; + var NftDetectionController = class extends _basecontroller.BaseController { + /** +@@ -134,6 +135,61 @@ var NftDetectionController = class extends _basecontroller.BaseController { + apiNfts = resultNftApi.tokens.filter( + (elm) => elm.token.isSpam === false && (elm.blockaidResult?.result_type ? elm.blockaidResult?.result_type === "Benign" /* Benign */ : true) + ); ++ ++ const collections = apiNfts.reduce((acc, currValue) => { ++ if (!acc.includes(currValue.token.contract) && currValue.token.contract === currValue?.token?.collection?.id) { ++ acc.push(currValue.token.contract); ++ } ++ return acc; ++ }, []); ++ if (collections.length !== 0) { ++ const collectionResponse = await _chunkNYVA7ZTQjs.reduceInBatchesSerially.call(void 0, { ++ values: collections, ++ batchSize: MAX_GET_COLLECTION_BATCH_SIZE, ++ eachBatch: async (allResponses, batch) => { ++ const params = new URLSearchParams( ++ batch.map((s) => ["contract", s]) ++ ); ++ params.append("chainId", "1"); ++ const collectionResponseForBatch = await _controllerutils.fetchWithErrorHandling.call(void 0, ++ { ++ url: `${_controllerutils.NFT_API_BASE_URL}/collections?${params.toString()}`, ++ options: { ++ headers: { ++ Version: '1' ++ } ++ }, ++ timeout: 15000 ++ } ++ ); ++ return { ++ ...allResponses, ++ ...collectionResponseForBatch ++ }; ++ }, ++ initialResult: {} ++ }); ++ if (collectionResponse.collections?.length) { ++ apiNfts.forEach((singleNFT) => { ++ const found = collectionResponse.collections.find( ++ (elm) => elm.id?.toLowerCase() === singleNFT.token.contract.toLowerCase() ++ ); ++ if (found) { ++ singleNFT.token = { ++ ...singleNFT.token, ++ collection: { ++ ...singleNFT.token.collection ?? {}, ++ creator: found?.creator, ++ openseaVerificationStatus: found?.openseaVerificationStatus, ++ contractDeployedAt: found.contractDeployedAt, ++ ownerCount: found.ownerCount, ++ topBid: found.topBid ++ } ++ }; ++ } ++ }); ++ } ++ } + const addNftPromises = apiNfts.map(async (nft) => { + const { + tokenId, +diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-7JWDWDXT.js b/node_modules/@metamask/assets-controllers/dist/chunk-7JWDWDXT.js +index af5d784..99e4a32 100644 +--- a/node_modules/@metamask/assets-controllers/dist/chunk-7JWDWDXT.js ++++ b/node_modules/@metamask/assets-controllers/dist/chunk-7JWDWDXT.js +@@ -44,7 +44,7 @@ var getDefaultNftControllerState = () => ({ + allNfts: {}, + ignoredNfts: [] + }); +-var _mutex, _selectedAccountId, _chainId, _ipfsGateway, _openSeaEnabled, _useIpfsSubdomains, _isIpfsGatewayEnabled, _getERC721AssetName, _getERC721AssetSymbol, _getERC721TokenURI, _getERC721OwnerOf, _getERC1155BalanceOf, _getERC1155TokenURI, _onNftAdded, _onNetworkControllerNetworkDidChange, onNetworkControllerNetworkDidChange_fn, _onPreferencesControllerStateChange, onPreferencesControllerStateChange_fn, _onSelectedAccountChange, onSelectedAccountChange_fn, _updateNestedNftState, updateNestedNftState_fn, _getNftInformationFromApi, getNftInformationFromApi_fn, _getNftInformationFromTokenURI, getNftInformationFromTokenURI_fn, _getNftURIAndStandard, getNftURIAndStandard_fn, _getNftInformation, getNftInformation_fn, _getNftContractInformationFromContract, getNftContractInformationFromContract_fn, _getNftContractInformation, getNftContractInformation_fn, _addIndividualNft, addIndividualNft_fn, _addNftContract, addNftContract_fn, _removeAndIgnoreIndividualNft, removeAndIgnoreIndividualNft_fn, _removeIndividualNft, removeIndividualNft_fn, _removeNftContract, removeNftContract_fn, _validateWatchNft, validateWatchNft_fn, _getCorrectChainId, getCorrectChainId_fn, _getAddressOrSelectedAddress, getAddressOrSelectedAddress_fn, _updateNftUpdateForAccount, updateNftUpdateForAccount_fn; ++var _mutex, _selectedAccountId, _chainId, _ipfsGateway, _displayNftMedia, _useIpfsSubdomains, _isIpfsGatewayEnabled, _getERC721AssetName, _getERC721AssetSymbol, _getERC721TokenURI, _getERC721OwnerOf, _getERC1155BalanceOf, _getERC1155TokenURI, _onNftAdded, _onNetworkControllerNetworkDidChange, onNetworkControllerNetworkDidChange_fn, _onPreferencesControllerStateChange, onPreferencesControllerStateChange_fn, _onSelectedAccountChange, onSelectedAccountChange_fn, _updateNestedNftState, updateNestedNftState_fn, _getNftInformationFromApi, getNftInformationFromApi_fn, _getNftInformationFromTokenURI, getNftInformationFromTokenURI_fn, _getNftURIAndStandard, getNftURIAndStandard_fn, _getNftInformation, getNftInformation_fn, _getNftContractInformationFromContract, getNftContractInformationFromContract_fn, _getNftContractInformation, getNftContractInformation_fn, _addIndividualNft, addIndividualNft_fn, _addNftContract, addNftContract_fn, _removeAndIgnoreIndividualNft, removeAndIgnoreIndividualNft_fn, _removeIndividualNft, removeIndividualNft_fn, _removeNftContract, removeNftContract_fn, _validateWatchNft, validateWatchNft_fn, _getCorrectChainId, getCorrectChainId_fn, _getAddressOrSelectedAddress, getAddressOrSelectedAddress_fn, _updateNftUpdateForAccount, updateNftUpdateForAccount_fn; + var NftController = class extends _basecontroller.BaseController { + /** + * Creates an NftController instance. +@@ -52,7 +52,7 @@ var NftController = class extends _basecontroller.BaseController { + * @param options - The controller options. + * @param options.chainId - The chain ID of the current network. + * @param options.ipfsGateway - The configured IPFS gateway. +- * @param options.openSeaEnabled - Controls whether the OpenSea API is used. ++ * @param options.displayNftMedia - Controls whether the NFT API is used. + * @param options.useIpfsSubdomains - Controls whether IPFS subdomains are used. + * @param options.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not. + * @param options.getERC721AssetName - Gets the name of the asset at the given address. +@@ -69,7 +69,7 @@ var NftController = class extends _basecontroller.BaseController { + constructor({ + chainId: initialChainId, + ipfsGateway = _controllerutils.IPFS_DEFAULT_GATEWAY_URL, +- openSeaEnabled = false, ++ displayNftMedia = false, + useIpfsSubdomains = true, + isIpfsGatewayEnabled = true, + getERC721AssetName, +@@ -101,7 +101,7 @@ var NftController = class extends _basecontroller.BaseController { + * Handles the state change of the preference controller. + * @param preferencesState - The new state of the preference controller. + * @param preferencesState.ipfsGateway - The configured IPFS gateway. +- * @param preferencesState.openSeaEnabled - Controls whether the OpenSea API is used. ++ * @param preferencesState.displayNftMedia - Controls whether the NFT API is used. + * @param preferencesState.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not. + */ + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _onPreferencesControllerStateChange); +@@ -237,7 +237,7 @@ var NftController = class extends _basecontroller.BaseController { + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _selectedAccountId, void 0); + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _chainId, void 0); + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _ipfsGateway, void 0); +- _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _openSeaEnabled, void 0); ++ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _displayNftMedia, void 0); + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _useIpfsSubdomains, void 0); + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _isIpfsGatewayEnabled, void 0); + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getERC721AssetName, void 0); +@@ -252,7 +252,7 @@ var NftController = class extends _basecontroller.BaseController { + ).id); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _chainId, initialChainId); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _ipfsGateway, ipfsGateway); +- _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _openSeaEnabled, openSeaEnabled); ++ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _displayNftMedia, displayNftMedia); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _useIpfsSubdomains, useIpfsSubdomains); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isIpfsGatewayEnabled, isIpfsGatewayEnabled); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getERC721AssetName, getERC721AssetName); +@@ -279,6 +279,18 @@ var NftController = class extends _basecontroller.BaseController { + _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _onSelectedAccountChange, onSelectedAccountChange_fn).bind(this) + ); + } ++ ++ /** ++ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO ++ * Resets to the default state ++ */ ++ reset() { ++ this.update((state) => { ++ state.allNftContracts = {}; ++ state.allNfts = {}; ++ state.ignoredNfts = []; ++ }); ++ } + getNftApi() { + return `${_controllerutils.NFT_API_BASE_URL}/tokens`; + } +@@ -797,7 +809,7 @@ _mutex = new WeakMap(); + _selectedAccountId = new WeakMap(); + _chainId = new WeakMap(); + _ipfsGateway = new WeakMap(); +-_openSeaEnabled = new WeakMap(); ++_displayNftMedia = new WeakMap(); + _useIpfsSubdomains = new WeakMap(); + _isIpfsGatewayEnabled = new WeakMap(); + _getERC721AssetName = new WeakMap(); +@@ -822,7 +834,7 @@ onNetworkControllerNetworkDidChange_fn = function({ + _onPreferencesControllerStateChange = new WeakSet(); + onPreferencesControllerStateChange_fn = async function({ + ipfsGateway, +- openSeaEnabled, ++ displayNftMedia, + isIpfsGatewayEnabled + }) { + const selectedAccount = this.messagingSystem.call( +@@ -830,9 +842,9 @@ onPreferencesControllerStateChange_fn = async function({ + ); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _selectedAccountId, selectedAccount.id); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _ipfsGateway, ipfsGateway); +- _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _openSeaEnabled, openSeaEnabled); ++ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _displayNftMedia, displayNftMedia); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isIpfsGatewayEnabled, isIpfsGatewayEnabled); +- const needsUpdateNftMetadata = isIpfsGatewayEnabled && ipfsGateway !== "" || openSeaEnabled; ++ const needsUpdateNftMetadata = isIpfsGatewayEnabled && ipfsGateway !== "" || displayNftMedia; + if (needsUpdateNftMetadata && selectedAccount) { + await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateNftUpdateForAccount, updateNftUpdateForAccount_fn).call(this, selectedAccount); + } +@@ -841,7 +853,7 @@ _onSelectedAccountChange = new WeakSet(); + onSelectedAccountChange_fn = async function(internalAccount) { + const oldSelectedAccountId = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAccountId); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _selectedAccountId, internalAccount.id); +- const needsUpdateNftMetadata = (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isIpfsGatewayEnabled) && _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _ipfsGateway) !== "" || _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _openSeaEnabled)) && oldSelectedAccountId !== internalAccount.id; ++ const needsUpdateNftMetadata = (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isIpfsGatewayEnabled) && _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _ipfsGateway) !== "" || _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _displayNftMedia)) && oldSelectedAccountId !== internalAccount.id; + if (needsUpdateNftMetadata) { + await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateNftUpdateForAccount, updateNftUpdateForAccount_fn).call(this, internalAccount); + } +@@ -865,9 +877,14 @@ updateNestedNftState_fn = function(newCollection, baseStateKey, { userAddress, c + }); + }; + _getNftInformationFromApi = new WeakSet(); +-getNftInformationFromApi_fn = async function(contractAddress, tokenId) { ++getNftInformationFromApi_fn = async function(contractAddress, tokenId, networkClientId) { ++ const chainId = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getCorrectChainId, getCorrectChainId_fn).call(this, { ++ networkClientId ++ }); ++ // Convert hex chainId to number ++ const convertedChainId = (0, _controllerutils.convertHexToDecimal)(chainId).toString(); + const urlParams = new URLSearchParams({ +- chainIds: "1", ++ chainIds: convertedChainId, + tokens: `${contractAddress}:${tokenId}`, + includeTopBid: "true", + includeAttributes: "true", +@@ -881,12 +898,26 @@ getNftInformationFromApi_fn = async function(contractAddress, tokenId) { + } + } + }); ++ const getCollectionParams = new URLSearchParams({ ++ chainId: convertedChainId, ++ id: `${nftInformation?.tokens[0]?.token?.collection?.id}` ++ }).toString(); ++ ++ const collectionInformation = await _controllerutils.fetchWithErrorHandling.call(void 0, { ++ url: `${_controllerutils.NFT_API_BASE_URL}/collections?${getCollectionParams}`, ++ options: { ++ headers: { ++ Version: '1' ++ } ++ } ++ }); + if (!nftInformation?.tokens?.[0]?.token) { + return { + name: null, + description: null, + image: null, +- standard: null ++ standard: null, ++ error: 'Opensea import error', + }; + } + const { +@@ -918,7 +949,16 @@ getNftInformationFromApi_fn = async function(contractAddress, tokenId) { + }, + rarityRank && { rarityRank }, + rarity && { rarity }, +- collection && { collection } ++ (collection || collectionInformation) && { ++ collection: { ++ ...collection || {}, ++ creator: collection?.creator || collectionInformation?.collections[0].creator, ++ openseaVerificationStatus: collectionInformation?.collections[0].openseaVerificationStatus, ++ contractDeployedAt: collectionInformation?.collections[0].contractDeployedAt, ++ ownerCount: collectionInformation?.collections[0].ownerCount, ++ topBid: collectionInformation?.collections[0].topBid ++ } ++ } + ); + return nftMetadata; + }; +@@ -938,7 +978,7 @@ getNftInformationFromTokenURI_fn = async function(contractAddress, tokenId, netw + tokenURI: tokenURI ?? null + }; + } +- const isDisplayNFTMediaToggleEnabled = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _openSeaEnabled); ++ const isDisplayNFTMediaToggleEnabled = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _displayNftMedia); + if (!hasIpfsTokenURI && !isDisplayNFTMediaToggleEnabled) { + return { + image: null, +@@ -946,7 +986,8 @@ getNftInformationFromTokenURI_fn = async function(contractAddress, tokenId, netw + description: null, + standard: standard || null, + favorite: false, +- tokenURI: tokenURI ?? null ++ tokenURI: tokenURI ?? null, ++ error: 'URI import error', + }; + } + if (hasIpfsTokenURI) { +@@ -956,6 +997,16 @@ getNftInformationFromTokenURI_fn = async function(contractAddress, tokenId, netw + _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _useIpfsSubdomains) + ); + } ++ if (tokenURI.startsWith("data:image/")) { ++ return { ++ image: tokenURI, ++ name: null, ++ description: null, ++ standard: standard || null, ++ favorite: false, ++ tokenURI: tokenURI ?? null ++ }; ++ } + try { + const object = await _controllerutils.handleFetch.call(void 0, tokenURI); + const image = Object.prototype.hasOwnProperty.call(object, "image") ? "image" : ( +@@ -977,7 +1028,8 @@ getNftInformationFromTokenURI_fn = async function(contractAddress, tokenId, netw + description: null, + standard: standard || null, + favorite: false, +- tokenURI: tokenURI ?? null ++ tokenURI: tokenURI ?? null, ++ error: 'URI import error', + }; + } + }; +@@ -1008,10 +1060,22 @@ getNftInformation_fn = async function(contractAddress, tokenId, networkClientId) + _controllerutils.safelyExecute.call(void 0, + () => _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getNftInformationFromTokenURI, getNftInformationFromTokenURI_fn).call(this, contractAddress, tokenId, networkClientId) + ), +- _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _openSeaEnabled) && chainId === "0x1" ? _controllerutils.safelyExecute.call(void 0, +- () => _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getNftInformationFromApi, getNftInformationFromApi_fn).call(this, contractAddress, tokenId) ++ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _displayNftMedia) && chainId === "0x1" ? _controllerutils.safelyExecute.call(void 0, ++ () => _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getNftInformationFromApi, getNftInformationFromApi_fn).call(this, contractAddress, tokenId, networkClientId) + ) : void 0 + ]); ++ ++ if (blockchainMetadata?.error && nftApiMetadata?.error) { ++ return { ++ image: null, ++ name: null, ++ description: null, ++ standard: blockchainMetadata.standard ?? null, ++ favorite: false, ++ tokenURI: blockchainMetadata.tokenURI ?? null, ++ error: 'Both import failed', ++ }; ++ } + return { + ...nftApiMetadata, + name: blockchainMetadata?.name ?? nftApiMetadata?.name ?? null, +@@ -1095,7 +1159,8 @@ addIndividualNft_fn = async function(tokenAddress, tokenId, nftMetadata, nftCont + nftMetadata, + existingEntry + ); +- if (!differentMetadata && existingEntry.isCurrentlyOwned) { ++ const hasNewFields = _chunkNEXY7SE2js.hasNewCollectionFields(nftMetadata, existingEntry); ++ if (!differentMetadata && existingEntry.isCurrentlyOwned && !hasNewFields) { + return; + } + const indexToUpdate = nfts.findIndex( +@@ -1127,7 +1192,8 @@ addIndividualNft_fn = async function(tokenAddress, tokenId, nftMetadata, nftCont + symbol: nftContract.symbol, + tokenId: tokenId.toString(), + standard: nftMetadata.standard, +- source ++ source, ++ tokenURI: nftMetadata.tokenURI, + }); + } + } finally { +diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-FGAZXVKS.js b/node_modules/@metamask/assets-controllers/dist/chunk-FGAZXVKS.js +index 4a6aa79..da5f9c1 100644 +--- a/node_modules/@metamask/assets-controllers/dist/chunk-FGAZXVKS.js ++++ b/node_modules/@metamask/assets-controllers/dist/chunk-FGAZXVKS.js +@@ -179,6 +179,15 @@ var TokenRatesController = class extends _pollingcontroller.StaticIntervalPollin + enable() { + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _disabled, false); + } ++ /** ++ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO ++ * Resets to the default state ++ */ ++ reset() { ++ this.update((state) => { ++ state.marketData = {}; ++ }); ++ } + /** + * Blocks controller from making network calls + */ +diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-NWVMFCSC.js b/node_modules/@metamask/assets-controllers/dist/chunk-NWVMFCSC.js +index cdb2710..9a0f961 100644 +--- a/node_modules/@metamask/assets-controllers/dist/chunk-NWVMFCSC.js ++++ b/node_modules/@metamask/assets-controllers/dist/chunk-NWVMFCSC.js +@@ -19,7 +19,7 @@ function getDefaultTokenBalancesState() { + contractBalances: {} + }; + } +-var _handle, _getERC20BalanceOf, _interval, _tokens, _disabled; ++var _handle, _getERC20BalanceOf, _interval, _tokens, _disabled, _updateInProgress; + var TokenBalancesController = class extends _basecontroller.BaseController { + /** + * Construct a Token Balances Controller. +@@ -54,9 +54,11 @@ var TokenBalancesController = class extends _basecontroller.BaseController { + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _interval, void 0); + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _tokens, void 0); + _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _disabled, void 0); ++ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _updateInProgress, void 0); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _disabled, disabled); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _interval, interval); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _tokens, tokens); ++ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _updateInProgress, false); + this.messagingSystem.subscribe( + "TokensController:stateChange", + ({ tokens: newTokens, detectedTokens }) => { +@@ -78,6 +80,15 @@ var TokenBalancesController = class extends _basecontroller.BaseController { + */ + disable() { + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _disabled, true); ++ } ++ /** ++ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO ++ * Resets to the default state ++ */ ++ reset() { ++ this.update((state) => { ++ state.contractBalances = {}; ++ }); + } + /** + * Starts a new polling interval. diff --git a/yarn.lock b/yarn.lock index 4d2b39ab497..b067805b486 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4294,7 +4294,7 @@ "@metamask/superstruct" "^3.1.0" "@metamask/utils" "^9.0.0" -"@metamask/accounts-controller@^16.0.0", "@metamask/accounts-controller@^17.2.0", "@metamask/accounts-controller@^18.1.0", "@metamask/accounts-controller@^18.2.1": +"@metamask/accounts-controller@^17.0.0", "@metamask/accounts-controller@^17.2.0", "@metamask/accounts-controller@^18.1.0", "@metamask/accounts-controller@^18.2.1": version "18.2.1" resolved "https://registry.yarnpkg.com/@metamask/accounts-controller/-/accounts-controller-18.2.1.tgz#8e4a842316e9b7bbd0409b36129f7123ba4a4c79" integrity sha512-BEvux+ZFpTOQa6HbRl7i7Tq24ztqrZIsX+H0ePh47lU+N8RWq1q0JCItV+zbsgdcYnwhtcMZTsp4jJPQwPe2og== @@ -4330,10 +4330,10 @@ "@metamask/utils" "^9.1.0" nanoid "^3.1.31" -"@metamask/assets-controllers@^32.0.0": - version "32.0.0" - resolved "https://registry.yarnpkg.com/@metamask/assets-controllers/-/assets-controllers-32.0.0.tgz#75175a848f0788036e2feff17e4bb245c2f7d223" - integrity sha512-d1+ASPADu+b3Jw77AxHX382F0VRxksGxDlJ/f0hzZDHkoNUqPVxX1wL3ZIyBQYh4je4Nq7MOslg5kwUPXF13rw== +"@metamask/assets-controllers@^33.0.0": + version "33.0.0" + resolved "https://registry.yarnpkg.com/@metamask/assets-controllers/-/assets-controllers-33.0.0.tgz#e00082a1f68a72ca10d4cffe1dc7a0a7b1c52957" + integrity sha512-9/W8E13cVVpfHtzaF4UABo1IKnfeg+gfhJdN7MJfNMrDclw2nK101OXLPIFwtGL4rddpRMuEBk0EWJAglNjWQQ== dependencies: "@ethereumjs/util" "^8.1.0" "@ethersproject/address" "^5.7.0" @@ -4341,13 +4341,13 @@ "@ethersproject/contracts" "^5.7.0" "@ethersproject/providers" "^5.7.0" "@metamask/abi-utils" "^2.0.2" - "@metamask/accounts-controller" "^16.0.0" + "@metamask/accounts-controller" "^17.0.0" "@metamask/approval-controller" "^7.0.0" "@metamask/base-controller" "^6.0.0" "@metamask/contract-metadata" "^2.4.0" "@metamask/controller-utils" "^11.0.0" "@metamask/eth-query" "^4.0.0" - "@metamask/keyring-controller" "^17.0.0" + "@metamask/keyring-controller" "^17.1.0" "@metamask/metamask-eth-abis" "^3.1.1" "@metamask/network-controller" "^19.0.0" "@metamask/polling-controller" "^8.0.0" @@ -4846,7 +4846,7 @@ bech32 "^2.0.0" uuid "^9.0.1" -"@metamask/keyring-controller@^17.0.0", "@metamask/keyring-controller@^17.2.1", "@metamask/keyring-controller@^17.2.2": +"@metamask/keyring-controller@^17.1.0", "@metamask/keyring-controller@^17.2.1", "@metamask/keyring-controller@^17.2.2": version "17.2.2" resolved "https://registry.yarnpkg.com/@metamask/keyring-controller/-/keyring-controller-17.2.2.tgz#944bc693305b4a6e4f1e73739a82c4bc6573dd9a" integrity sha512-Shqk0ybcTPrHQLlBJ1V+InuYC7nD3/a6Ws0XCcBCOfkLTXvtSooKIWBioK83XlHMHkfsM6+bySxSqXJVgJvBZw== From 9200e0352ffcc64993828d8b84cbc345de6d2c3d Mon Sep 17 00:00:00 2001 From: sahar-fehri Date: Tue, 15 Oct 2024 19:05:55 +0200 Subject: [PATCH 2/5] chore: update assets-controllers v33.0.0 --- app/core/EngineService/EngineService.ts | 2 +- app/reducers/collectibles/index.js | 11 +- app/selectors/accountsController.ts | 11 + app/selectors/tokenRatesController.ts | 4 +- app/selectors/types.ts | 4 +- app/store/migrations/029.ts | 4 +- app/store/migrations/031.ts | 4 +- .../@metamask+assets-controllers+33.0.0.patch | 318 +++++++++++++++++- 8 files changed, 344 insertions(+), 14 deletions(-) diff --git a/app/core/EngineService/EngineService.ts b/app/core/EngineService/EngineService.ts index c46e5118ff5..d20ef64d807 100644 --- a/app/core/EngineService/EngineService.ts +++ b/app/core/EngineService/EngineService.ts @@ -92,7 +92,7 @@ class EngineService { name: 'TokenBalancesController', key: `${engine.context.TokenBalancesController.name}:stateChange`, }, - { name: 'TokenRatesController' }, + { name: 'TokenRatesController', key: 'TokenRatesController:stateChange' }, { name: 'TransactionController', key: `${engine.context.TransactionController.name}:stateChange`, diff --git a/app/reducers/collectibles/index.js b/app/reducers/collectibles/index.js index 1a3b0989307..769f2cfbcf6 100644 --- a/app/reducers/collectibles/index.js +++ b/app/reducers/collectibles/index.js @@ -4,7 +4,10 @@ import { selectAllNftContracts, selectAllNfts, } from '../../selectors/nftController'; -import { selectSelectedInternalAccountChecksummedAddress } from '../../selectors/accountsController'; +import { + selectSelectedInternalAccountAddress, + selectSelectedInternalAccountChecksummedAddress, +} from '../../selectors/accountsController'; import { compareTokenIds } from '../../util/tokens'; import { createDeepEqualSelector } from '../../selectors/util'; @@ -14,7 +17,7 @@ export const isNftFetchingProgressSelector = (state) => state.collectibles.isNftFetchingProgress; export const collectibleContractsSelector = createSelector( - selectSelectedInternalAccountChecksummedAddress, + selectSelectedInternalAccountAddress, selectChainId, selectAllNftContracts, (address, chainId, allNftContracts) => @@ -22,14 +25,14 @@ export const collectibleContractsSelector = createSelector( ); export const collectiblesSelector = createDeepEqualSelector( - selectSelectedInternalAccountChecksummedAddress, + selectSelectedInternalAccountAddress, selectChainId, selectAllNfts, (address, chainId, allNfts) => allNfts[address]?.[chainId] || [], ); export const favoritesCollectiblesSelector = createSelector( - selectSelectedInternalAccountChecksummedAddress, + selectSelectedInternalAccountAddress, selectChainId, favoritesSelector, (address, chainId, favorites) => favorites[address]?.[chainId] || [], diff --git a/app/selectors/accountsController.ts b/app/selectors/accountsController.ts index 99ba3d82b2c..0977a3c0346 100644 --- a/app/selectors/accountsController.ts +++ b/app/selectors/accountsController.ts @@ -69,3 +69,14 @@ export const selectSelectedInternalAccountChecksummedAddress = createSelector( return selectedAddress ? toChecksumHexAddress(selectedAddress) : undefined; }, ); + +/** + * A memoized selector that returns the selected internal account address + */ +export const selectSelectedInternalAccountAddress = createSelector( + selectSelectedInternalAccount, + (account) => { + const selectedAddress = account?.address; + return selectedAddress || undefined; + }, +); diff --git a/app/selectors/tokenRatesController.ts b/app/selectors/tokenRatesController.ts index aad37a30ebb..e41d78a0dd3 100644 --- a/app/selectors/tokenRatesController.ts +++ b/app/selectors/tokenRatesController.ts @@ -1,6 +1,6 @@ /* eslint-disable import/prefer-default-export */ import { createSelector } from 'reselect'; -import { TokenRatesState } from '@metamask/assets-controllers'; +import { TokenRatesControllerState } from '@metamask/assets-controllers'; import { RootState } from '../reducers'; import { selectChainId } from './networkController'; import { Hex } from '@metamask/utils'; @@ -11,6 +11,6 @@ const selectTokenRatesControllerState = (state: RootState) => export const selectContractExchangeRates = createSelector( selectChainId, selectTokenRatesControllerState, - (chainId: Hex, tokenRatesControllerState: TokenRatesState) => + (chainId: Hex, tokenRatesControllerState: TokenRatesControllerState) => tokenRatesControllerState.marketData[chainId], ); diff --git a/app/selectors/types.ts b/app/selectors/types.ts index 75624d44a13..061cec63b82 100644 --- a/app/selectors/types.ts +++ b/app/selectors/types.ts @@ -5,7 +5,7 @@ import { NftControllerState, TokenDetectionController, TokenListState, - TokenRatesState, + TokenRatesControllerState, TokensControllerState, TokenBalancesControllerState, } from '@metamask/assets-controllers'; @@ -39,7 +39,7 @@ export interface EngineState { PhishingController: PhishingControllerState; PPOMController: PPOMState; TokenBalancesController: TokenBalancesControllerState; - TokenRatesController: TokenRatesState; + TokenRatesController: TokenRatesControllerState; TransactionController: TransactionControllerState; SwapsController: SwapsController; ///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps) diff --git a/app/store/migrations/029.ts b/app/store/migrations/029.ts index 9b3d9199a9e..af4f1ebf1ba 100644 --- a/app/store/migrations/029.ts +++ b/app/store/migrations/029.ts @@ -15,7 +15,7 @@ import { NftContract, NftControllerState, TokenListState, - TokenRatesState, + TokenRatesControllerState, TokensControllerState, } from '@metamask/assets-controllers'; @@ -530,7 +530,7 @@ export default async function migrate(stateAsync: unknown) { const tokenRatesControllerState = state?.engine?.backgroundState?.TokenRatesController; const newTokenRatesControllerState = state?.engine?.backgroundState - ?.TokenRatesController as TokenRatesState; + ?.TokenRatesController as TokenRatesControllerState; if (!isObject(tokenRatesControllerState)) { captureException( diff --git a/app/store/migrations/031.ts b/app/store/migrations/031.ts index a0fca395d12..ba4b06ca119 100644 --- a/app/store/migrations/031.ts +++ b/app/store/migrations/031.ts @@ -2,7 +2,7 @@ import { hasProperty, isObject } from '@metamask/utils'; import { captureException } from '@sentry/react-native'; import { TokenListState, - TokenRatesState, + TokenRatesControllerState, TokensControllerState, } from '@metamask/assets-controllers'; import { toHex } from '@metamask/controller-utils'; @@ -105,7 +105,7 @@ export default async function migrate(stateAsync: unknown) { const tokenRatesControllerState = state?.engine?.backgroundState?.TokenRatesController; const newTokenRatesControllerState = state?.engine?.backgroundState - ?.TokenRatesController as TokenRatesState; + ?.TokenRatesController as TokenRatesControllerState; if (!isObject(tokenRatesControllerState)) { captureException( diff --git a/patches/@metamask+assets-controllers+33.0.0.patch b/patches/@metamask+assets-controllers+33.0.0.patch index fb5e848d328..18d12fd948f 100644 --- a/patches/@metamask+assets-controllers+33.0.0.patch +++ b/patches/@metamask+assets-controllers+33.0.0.patch @@ -372,7 +372,7 @@ index 4a6aa79..da5f9c1 100644 * Blocks controller from making network calls */ diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-NWVMFCSC.js b/node_modules/@metamask/assets-controllers/dist/chunk-NWVMFCSC.js -index cdb2710..9a0f961 100644 +index cdb2710..5a7529d 100644 --- a/node_modules/@metamask/assets-controllers/dist/chunk-NWVMFCSC.js +++ b/node_modules/@metamask/assets-controllers/dist/chunk-NWVMFCSC.js @@ -19,7 +19,7 @@ function getDefaultTokenBalancesState() { @@ -412,3 +412,319 @@ index cdb2710..9a0f961 100644 } /** * Starts a new polling interval. +@@ -107,20 +118,28 @@ var TokenBalancesController = class extends _basecontroller.BaseController { + "PreferencesController:getState" + ); + const newContractBalances = {}; +- for (const token of _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _tokens)) { ++ ++ const balancePromises = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _tokens).map((token) => { + const { address } = token; +- try { +- const balance = await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getERC20BalanceOf).call(this, address, selectedAddress); +- newContractBalances[address] = _controllerutils.toHex.call(void 0, balance); +- token.hasBalanceError = false; +- } catch (error) { +- newContractBalances[address] = _controllerutils.toHex.call(void 0, 0); +- token.hasBalanceError = true; +- } +- } ++ return _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getERC20BalanceOf).call(this, address, selectedAddress).then((balance) => { ++ newContractBalances[address] = _controllerutils.toHex.call(void 0, balance); ++ token = { ++ ...token, ++ hasBalanceError: false ++ }; ++ }).catch((error) => { ++ newContractBalances[address] = _controllerutils.toHex.call(void 0, 0); ++ token = { ++ ...token, ++ hasBalanceError: true ++ }; ++ }); ++ }); ++ await Promise.all(balancePromises); + this.update((state) => { + state.contractBalances = newContractBalances; + }); ++ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _updateInProgress, false); + } + }; + _handle = new WeakMap(); +@@ -128,6 +147,7 @@ _getERC20BalanceOf = new WeakMap(); + _interval = new WeakMap(); + _tokens = new WeakMap(); + _disabled = new WeakMap(); ++_updateInProgress = new WeakMap(); + var TokenBalancesController_default = TokenBalancesController; + + +diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-RJBYLTY5.js b/node_modules/@metamask/assets-controllers/dist/chunk-RJBYLTY5.js +index 294447b..5e522de 100644 +--- a/node_modules/@metamask/assets-controllers/dist/chunk-RJBYLTY5.js ++++ b/node_modules/@metamask/assets-controllers/dist/chunk-RJBYLTY5.js +@@ -293,6 +293,19 @@ var TokensController = class extends _basecontroller.BaseController { + releaseLock(); + } + } ++ ++ /** ++ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO ++ * Resets to the default state ++ */ ++ reset() { ++ this.update((state) => { ++ state.allTokens = {}; ++ state.allIgnoredTokens = {}; ++ state.ignoredTokens = []; ++ state.tokens = []; ++ }); ++ } + /** + * Add a batch of tokens. + * +diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-T5ZX5BV7.js b/node_modules/@metamask/assets-controllers/dist/chunk-T5ZX5BV7.js +index 9c89a65..2ac17ba 100644 +--- a/node_modules/@metamask/assets-controllers/dist/chunk-T5ZX5BV7.js ++++ b/node_modules/@metamask/assets-controllers/dist/chunk-T5ZX5BV7.js +@@ -87,6 +87,7 @@ var CurrencyRateController = class extends _pollingcontroller.StaticIntervalPoll + const nativeCurrencyForExchangeRate = Object.values( + _controllerutils.TESTNET_TICKER_SYMBOLS + ).includes(nativeCurrency) ? _controllerutils.FALL_BACK_VS_CURRENCY : nativeCurrency; ++ let shouldUpdateState = true; + try { + if (currentCurrency && nativeCurrency && // if either currency is an empty string we can skip the comparison + // because it will result in an error from the api and ultimately +@@ -103,23 +104,27 @@ var CurrencyRateController = class extends _pollingcontroller.StaticIntervalPoll + } + } catch (error) { + if (!(error instanceof Error && error.message.includes("market does not exist for this coin pair"))) { ++ // Don't update state on transient / unexpected errors ++ shouldUpdateState = false; + throw error; + } + } finally { + try { +- this.update(() => { +- return { +- currencyRates: { +- ...currencyRates, +- [nativeCurrency]: { +- conversionDate, +- conversionRate, +- usdConversionRate +- } +- }, +- currentCurrency +- }; +- }); ++ if(shouldUpdateState) { ++ this.update(() => { ++ return { ++ currencyRates: { ++ ...currencyRates, ++ [nativeCurrency]: { ++ conversionDate, ++ conversionRate, ++ usdConversionRate ++ } ++ }, ++ currentCurrency ++ }; ++ }); ++ } + } finally { + releaseLock(); + } +diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-VZF43NDM.js b/node_modules/@metamask/assets-controllers/dist/chunk-VZF43NDM.js +index 871ba96..02f5036 100644 +--- a/node_modules/@metamask/assets-controllers/dist/chunk-VZF43NDM.js ++++ b/node_modules/@metamask/assets-controllers/dist/chunk-VZF43NDM.js +@@ -165,7 +165,9 @@ var TokenDetectionController = class extends _pollingcontroller.StaticIntervalPo + if (!this.isActive) { + return; + } +- const addressAgainstWhichToDetect = selectedAddress ?? _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAddress); ++ const currentAddress = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAddress); ++ const currentAddressChecksum = _controllerutils.toChecksumHexAddress.call(void 0, currentAddress) ++ const addressAgainstWhichToDetect = _controllerutils.toChecksumHexAddress.call(void 0, selectedAddress) ?? currentAddressChecksum; + const { chainId, networkClientId: selectedNetworkClientId } = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getCorrectChainIdAndNetworkClientId, getCorrectChainIdAndNetworkClientId_fn).call(this, networkClientId); + const chainIdAgainstWhichToDetect = chainId; + const networkClientIdAgainstWhichToDetect = selectedNetworkClientId; +@@ -228,12 +230,10 @@ registerEventListeners_fn = function() { + "PreferencesController:stateChange", + // TODO: Either fix this lint violation or explain why it's necessary to ignore. + // eslint-disable-next-line @typescript-eslint/no-misused-promises +- async ({ selectedAddress: newSelectedAddress, useTokenDetection }) => { +- const isSelectedAddressChanged = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAddress) !== newSelectedAddress; ++ async ({ useTokenDetection }) => { + const isDetectionChangedFromPreferences = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isDetectionEnabledFromPreferences) !== useTokenDetection; +- _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _selectedAddress, newSelectedAddress); + _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isDetectionEnabledFromPreferences, useTokenDetection); +- if (isSelectedAddressChanged || isDetectionChangedFromPreferences) { ++ if ( isDetectionChangedFromPreferences) { + await _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _restartTokenDetection, restartTokenDetection_fn).call(this, { + selectedAddress: _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _selectedAddress) + }); +diff --git a/node_modules/@metamask/assets-controllers/dist/types/NftController.d.ts b/node_modules/@metamask/assets-controllers/dist/types/NftController.d.ts +index b663e26..09f72c6 100644 +--- a/node_modules/@metamask/assets-controllers/dist/types/NftController.d.ts ++++ b/node_modules/@metamask/assets-controllers/dist/types/NftController.d.ts +@@ -7,7 +7,7 @@ import type { PreferencesControllerStateChangeEvent } from '@metamask/preference + import type { Hex } from '@metamask/utils'; + import type { AssetsContractController } from './AssetsContractController'; + import { Source } from './constants'; +-import type { Collection, Attributes, LastSale } from './NftDetectionController'; ++import type { Collection, Attributes, LastSale, TopBid } from './NftDetectionController'; + type NFTStandardType = 'ERC721' | 'ERC1155'; + type SuggestedNftMeta = { + asset: { +@@ -108,11 +108,13 @@ export type NftMetadata = { + creator?: string; + transactionId?: string; + tokenURI?: string | null; ++ error?: string; + collection?: Collection; + address?: string; +- attributes?: Attributes; ++ attributes?: Attributes[]; + lastSale?: LastSale; + rarityRank?: string; ++ topBid?: TopBid; + }; + /** + * @type NftControllerState +@@ -419,6 +421,11 @@ export declare class NftController extends BaseController; ++ /** ++ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO ++ * Resets to the default state ++ */ ++ reset(): void; + } + export default NftController; + //# sourceMappingURL=NftController.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@metamask/assets-controllers/dist/types/NftDetectionController.d.ts b/node_modules/@metamask/assets-controllers/dist/types/NftDetectionController.d.ts +index c645b3a..2f1c945 100644 +--- a/node_modules/@metamask/assets-controllers/dist/types/NftDetectionController.d.ts ++++ b/node_modules/@metamask/assets-controllers/dist/types/NftDetectionController.d.ts +@@ -227,7 +227,41 @@ export type Attributes = { + topBidValue?: number | null; + createdAt?: string; + }; +-export type Collection = { ++ ++export type GetCollectionsResponse = { ++ collections: CollectionResponse[]; ++}; ++export type CollectionResponse = { ++ id?: string; ++ openseaVerificationStatus?: string; ++ contractDeployedAt?: string; ++ creator?: string; ++ ownerCount?: string; ++ topBid?: TopBid & { ++ sourceDomain?: string; ++ }; ++}; ++export type FloorAskCollection = { ++ id?: string; ++ price?: Price; ++ maker?: string; ++ kind?: string; ++ validFrom?: number; ++ validUntil?: number; ++ source?: SourceCollection; ++ rawData?: Metadata; ++ isNativeOffChainCancellable?: boolean; ++}; ++ ++export type SourceCollection = { ++ id: string; ++ domain: string; ++ name: string; ++ icon: string; ++ url: string; ++}; ++ ++export type TokenCollection = { + id?: string; + name?: string; + slug?: string; +@@ -243,7 +277,9 @@ export type Collection = { + floorAskPrice?: Price; + royaltiesBps?: number; + royalties?: Royalties[]; ++ floorAsk?: FloorAskCollection; + }; ++export type Collection = TokenCollection & CollectionResponse; + export type Royalties = { + bps?: number; + recipient?: string; +diff --git a/node_modules/@metamask/assets-controllers/dist/types/TokenBalancesController.d.ts b/node_modules/@metamask/assets-controllers/dist/types/TokenBalancesController.d.ts +index 52bb3ac..d4d5c0a 100644 +--- a/node_modules/@metamask/assets-controllers/dist/types/TokenBalancesController.d.ts ++++ b/node_modules/@metamask/assets-controllers/dist/types/TokenBalancesController.d.ts +@@ -79,6 +79,11 @@ export declare class TokenBalancesController extends BaseController; ++ /** ++ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO ++ * Resets to the default state ++ */ ++ reset(): void; + } + export default TokenBalancesController; + //# sourceMappingURL=TokenBalancesController.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@metamask/assets-controllers/dist/types/TokenRatesController.d.ts b/node_modules/@metamask/assets-controllers/dist/types/TokenRatesController.d.ts +index f29e877..24ce7d7 100644 +--- a/node_modules/@metamask/assets-controllers/dist/types/TokenRatesController.d.ts ++++ b/node_modules/@metamask/assets-controllers/dist/types/TokenRatesController.d.ts +@@ -165,6 +165,11 @@ export declare class TokenRatesController extends StaticIntervalPollingControlle + * @returns The controller state. + */ + _executePoll(networkClientId: NetworkClientId): Promise; ++ /** ++ * THIS FUNCTIONS IS CURRENTLY PATCHED AND STILL NEEDS TO BE IMPLEMENTED ON THE CORE REPO ++ * Resets to the default state ++ */ ++ reset(): void; + } + export default TokenRatesController; + //# sourceMappingURL=TokenRatesController.d.ts.map +\ No newline at end of file +diff --git a/node_modules/@metamask/assets-controllers/dist/types/TokensController.d.ts b/node_modules/@metamask/assets-controllers/dist/types/TokensController.d.ts +index bc4126d..ce8016a 100644 +--- a/node_modules/@metamask/assets-controllers/dist/types/TokensController.d.ts ++++ b/node_modules/@metamask/assets-controllers/dist/types/TokensController.d.ts +@@ -162,6 +162,11 @@ export declare class TokensController extends BaseController Date: Tue, 15 Oct 2024 19:15:43 +0200 Subject: [PATCH 3/5] fix: fix unit test --- app/components/UI/CollectibleContracts/index.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/UI/CollectibleContracts/index.test.tsx b/app/components/UI/CollectibleContracts/index.test.tsx index 33b8adfd836..8ed9f29a830 100644 --- a/app/components/UI/CollectibleContracts/index.test.tsx +++ b/app/components/UI/CollectibleContracts/index.test.tsx @@ -99,7 +99,7 @@ describe('CollectibleContracts', () => { AccountsController: MOCK_ACCOUNTS_CONTROLLER_STATE, NftController: { allNfts: { - [MOCK_ADDRESS]: { + [MOCK_ADDRESS.toLowerCase()]: { '0x1': [ { address: '0x72b1FDb6443338A158DeC2FbF411B71aeB157A42', @@ -131,7 +131,7 @@ describe('CollectibleContracts', () => { }, }, allNftContracts: { - [MOCK_ADDRESS]: { + [MOCK_ADDRESS.toLowerCase()]: { '0x1': [ { address: '0x72b1FDb6443338A158DeC2FbF411B71aeB157A42', From 035280e6d66b45a8a025d27b891c406ee1fa7099 Mon Sep 17 00:00:00 2001 From: sahar-fehri Date: Tue, 15 Oct 2024 19:28:17 +0200 Subject: [PATCH 4/5] fix: rm unused import --- app/reducers/collectibles/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/reducers/collectibles/index.js b/app/reducers/collectibles/index.js index 769f2cfbcf6..6643ee6a060 100644 --- a/app/reducers/collectibles/index.js +++ b/app/reducers/collectibles/index.js @@ -4,10 +4,7 @@ import { selectAllNftContracts, selectAllNfts, } from '../../selectors/nftController'; -import { - selectSelectedInternalAccountAddress, - selectSelectedInternalAccountChecksummedAddress, -} from '../../selectors/accountsController'; +import { selectSelectedInternalAccountAddress } from '../../selectors/accountsController'; import { compareTokenIds } from '../../util/tokens'; import { createDeepEqualSelector } from '../../selectors/util'; From 36f889b75588e2b3c8d18f1cb31a15dbaef89e54 Mon Sep 17 00:00:00 2001 From: sahar-fehri Date: Tue, 15 Oct 2024 19:29:12 +0200 Subject: [PATCH 5/5] fix: fix --- app/core/Engine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index ae96b867e80..a93a46e8d21 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -942,7 +942,7 @@ class Engine { const accountTrackerController = new AccountTrackerController( { - // @ts-expect-error TODO: Resolve mismatch between base-controller versions fix < ======. + // @ts-expect-error TODO: Resolve mismatch between base-controller versions messenger: this.controllerMessenger.getRestricted({ name: 'AccountTrackerController', allowedActions: [