@metamask-previews/assets-controllers 103.1.1-preview-97aa3f6 → 103.1.1-preview-d9d1316f5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -11,16 +11,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
 
12
12
  - **BREAKING:** `NftController` no longer uses the `AssetsContractController:getERC721OwnerOf` and `AssetsContractController:getERC1155BalanceOf` messenger actions for ownership checks; these have been removed from `AllowedActions` ([#8281](https://github.com/MetaMask/core/pull/8281))
13
13
  - Consumers that construct the `NftController` messenger and register handlers for these two actions must remove them from their allowed actions list.
14
- - **BREAKING:** Removed the `checkAndUpdateSingleNftOwnershipStatus` method from `NftController` ([#8281](https://github.com/MetaMask/core/pull/8281))
15
- - Use `checkAndUpdateAllNftsOwnershipStatus` instead, which now batches all ownership checks via Multicall3 in a single RPC request.
16
- - `checkAndUpdateAllNftsOwnershipStatus` now removes NFTs confirmed as unowned from state instead of setting `isCurrentlyOwned: false` ([#8281](https://github.com/MetaMask/core/pull/8281))
14
+ - **BREAKING:** `checkAndUpdateSingleNftOwnershipStatus` no longer accepts a `batch` boolean as its second argument; the signature is now `(nft, networkClientId, { userAddress }?)` ([#8281](https://github.com/MetaMask/core/pull/8281), [#8435](https://github.com/MetaMask/core/pull/8435))
15
+ - The method now always writes the updated NFT to state and returns it. Remove the `batch` argument from all call sites.
16
+ - **BREAKING:** `checkAndUpdateAllNftsOwnershipStatus` now removes NFTs confirmed as unowned from state instead of setting `isCurrentlyOwned: false` on them ([#8281](https://github.com/MetaMask/core/pull/8281))
17
17
  - The `isCurrentlyOwned: false` flag was originally used to power a "Previously Owned" NFTs section in MetaMask, which is no longer supported. NFTs that are confirmed as no longer owned are now removed from state immediately rather than being retained with a stale flag.
18
- - `NftController` NFT ownership checks (`isNftOwner`, `checkAndUpdateAllNftsOwnershipStatus`) now use Multicall3 to batch ERC-721 `ownerOf` and ERC-1155 `balanceOf` calls into fewer RPC requests, falling back to individual calls on unsupported chains ([#8281](https://github.com/MetaMask/core/pull/8281))
18
+ - `NftController` NFT ownership checks (`isNftOwner`, `checkAndUpdateSingleNftOwnershipStatus`, `checkAndUpdateAllNftsOwnershipStatus`) now use Multicall3 to batch ERC-721 `ownerOf` and ERC-1155 `balanceOf` calls into fewer RPC requests, falling back to individual calls on unsupported chains ([#8281](https://github.com/MetaMask/core/pull/8281))
19
19
  - Bump `@metamask/accounts-controller` from `^37.1.1` to `^37.2.0` ([#8363](https://github.com/MetaMask/core/pull/8363))
20
20
  - Bump `@metamask/keyring-controller` from `^25.1.1` to `^25.2.0` ([#8363](https://github.com/MetaMask/core/pull/8363))
21
21
  - Bump `@metamask/messenger` from `^1.0.0` to `^1.1.1` ([#8364](https://github.com/MetaMask/core/pull/8364), [#8373](https://github.com/MetaMask/core/pull/8373))
22
22
  - Bump `@metamask/transaction-controller` from `^64.0.0` to `^64.1.0` ([#8432](https://github.com/MetaMask/core/pull/8432))
23
23
 
24
+ ### Fixed
25
+
26
+ - Restore `checkAndUpdateSingleNftOwnershipStatus` to `NftController` to fix a regression where consumers (e.g. the MetaMask extension) that call this method individually were broken by its removal in [#8281](https://github.com/MetaMask/core/pull/8281) ([#8435](https://github.com/MetaMask/core/pull/8435))
27
+
24
28
  ## [103.1.1]
25
29
 
26
30
  ### Changed
@@ -462,6 +462,46 @@ class NftController extends base_controller_1.BaseController {
462
462
  state.ignoredNfts = [];
463
463
  });
464
464
  }
465
+ /**
466
+ * Checks whether input NFT is still owned by the user
467
+ * and updates the isCurrentlyOwned value on the NFT object accordingly.
468
+ *
469
+ * @param nft - The NFT object to check and update.
470
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
471
+ * @param accountParams - The userAddress to check ownership against.
472
+ * @param accountParams.userAddress - the address passed through the confirmed transaction flow to ensure assets are stored to the correct account
473
+ * @returns the NFT with the updated isCurrentlyOwned value
474
+ */
475
+ async checkAndUpdateSingleNftOwnershipStatus(nft, networkClientId, { userAddress } = {}) {
476
+ const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
477
+ const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
478
+ const { address, tokenId } = nft;
479
+ let isOwned = nft.isCurrentlyOwned;
480
+ try {
481
+ isOwned = await this.isNftOwner(addressToSearch, address, tokenId, networkClientId, { standard: nft.standard });
482
+ }
483
+ catch {
484
+ // ignore error
485
+ // this will only throw an error 'Unable to verify ownership' in which case
486
+ // we want to keep the current value of isCurrentlyOwned for this flow.
487
+ }
488
+ const updatedNft = {
489
+ ...nft,
490
+ isCurrentlyOwned: isOwned,
491
+ };
492
+ const { allNfts } = this.state;
493
+ const nfts = [...(allNfts[addressToSearch]?.[chainId] ?? [])];
494
+ const indexToUpdate = nfts.findIndex((item) => item.tokenId === tokenId &&
495
+ item.address.toLowerCase() === address.toLowerCase());
496
+ if (indexToUpdate !== -1) {
497
+ nfts[indexToUpdate] = updatedNft;
498
+ __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNestedNftState).call(this, nfts, ALL_NFTS_STATE_KEY, {
499
+ userAddress: addressToSearch,
500
+ chainId,
501
+ });
502
+ }
503
+ return updatedNft;
504
+ }
465
505
  /**
466
506
  * Checks whether NFTs associated with current selectedAddress/chainId combination are still owned by the user
467
507
  * And updates the isCurrentlyOwned value on each accordingly.