Skip to content

fix: NFT ownership status not refreshing across all enabled networks when pulling to refresh#28655

Merged
juanmigdr merged 10 commits into
mainfrom
fix/nft-refresh-use-multicall
Apr 17, 2026
Merged

fix: NFT ownership status not refreshing across all enabled networks when pulling to refresh#28655
juanmigdr merged 10 commits into
mainfrom
fix/nft-refresh-use-multicall

Conversation

@juanmigdr

@juanmigdr juanmigdr commented Apr 10, 2026

Copy link
Copy Markdown
Member

Description

When the user selects "All popular networks" and pulls to refresh on the NFT grid, checkAndUpdateAllNftsOwnershipStatus was only being called for a subset of the enabled networks — or potentially only mainnet — because the hook derived its chain list from selectTokenNetworkFilter (a PreferencesController value) intersected with selectEvmNetworkConfigurationsByChainId (networks the user has manually added). Any popular network the user hadn't explicitly added would be silently dropped.

This fix replaces that incorrect source of truth with chainIdsToDetectNftsFor from the existing useNftDetection hook, which is already the canonical chain list used by detectNfts() itself (derived from NetworkEnablementController.enabledNetworkMap). Now both detectNfts() and checkAndUpdateAllNftsOwnershipStatus() operate on the exact same set of networks, regardless of which network filter the user has selected.

Additionally updates @metamask/assets-controllers and removes the now-unused AssetsContractController:getERC721OwnerOf and AssetsContractController:getERC1155BalanceOf messenger action allowances from the NftController messenger (these were removed upstream).

Changelog

CHANGELOG entry: fixed NFT ownership status not refreshing across all enabled networks when pulling to refresh

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/ASSETS-2959 & https://consensyssoftware.atlassian.net/browse/ASSETS-2976

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Touches NFT refresh behavior and upgrades @metamask/assets-controllers, which could subtly change which networks are queried and how the NFT controller interacts with upstream controller APIs.

Overview
Fixes pull-to-refresh on the NFT grid so ownership status updates run across the same enabled chain set used by NFT detection. useNftRefresh now derives network client IDs from useNftDetection().chainIdsToDetectNftsFor (instead of selectTokenNetworkFilter), ensuring all enabled/popular networks get checkAndUpdateAllNftsOwnershipStatus calls.

Updates unit tests to cover the "All popular networks" case, empty-enabled-chain behavior, and undefined client IDs. Also bumps @metamask/assets-controllers to ^104.0.0 and removes now-unused messenger action allowances (AssetsContractController:getERC721OwnerOf, AssetsContractController:getERC1155BalanceOf).

Reviewed by Cursor Bugbot for commit 4df107d. Bugbot is set up for automated code reviews on this repo. Configure here.

@juanmigdr juanmigdr requested a review from a team as a code owner April 10, 2026 11:22
@github-actions github-actions Bot added size-S risk-low Low testing needed · Low bug introduction risk labels Apr 10, 2026
github-merge-queue Bot pushed a commit to MetaMask/core that referenced this pull request Apr 10, 2026
## Explanation

- Replace individual `AssetsContractController` messenger calls
(`getERC721OwnerOf`, `getERC1155BalanceOf`) with a new
`getNftOwnershipForMultipleNfts` utility that batches ERC-721 `ownerOf`
and ERC-1155 `balanceOf` calls through Multicall3's `aggregate3`,
falling back to individual RPC calls on unsupported chains or when
multicall fails.
- Remove `checkAndUpdateSingleNftOwnershipStatus` in favor of
`checkAndUpdateAllNftsOwnershipStatus`, which now batches all NFTs in a
single pass.
- Add an optional `standard` parameter to `isNftOwner` so callers that
already know the token standard skip redundant subcalls.
- `checkAndUpdateAllNftsOwnershipStatus` now removes NFTs confirmed as
unowned from state rather than retaining them with `isCurrentlyOwned:
false`. The "Previously Owned" NFT feature this flag powered is no
longer supported.

**Breaking Changes**
- **`checkAndUpdateSingleNftOwnershipStatus` removed** — use
`checkAndUpdateAllNftsOwnershipStatus` instead.
- **`AllowedActions` narrowed** —
`AssetsContractController:getERC721OwnerOf` and
`AssetsContractController:getERC1155BalanceOf` are no longer required by
`NftController`'s messenger. Consumers constructing the messenger must
remove these from their allowed actions list.





<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

## References
Ticket: https://consensyssoftware.atlassian.net/browse/ASSETS-2959
PR on Mobile: MetaMask/metamask-mobile#28655
PR on Extension: 

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them




<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Medium risk due to breaking API surface (`AllowedActions` narrowed,
`checkAndUpdateSingleNftOwnershipStatus` removed) and changed state
semantics (unowned NFTs are deleted), plus new multicall batching logic
that could affect ownership determination across networks.
> 
> **Overview**
> **NFT ownership checks are refactored to batch on-chain calls via
Multicall3.** `NftController.isNftOwner` and
`checkAndUpdateAllNftsOwnershipStatus` now use the new
`getNftOwnershipForMultipleNfts` helper to aggregate ERC-721 `ownerOf` /
ERC-1155 `balanceOf` calls (with fallback to individual calls when
multicall/chain support is unavailable), and callers can pass an
optional `standard` to skip unnecessary subcalls.
> 
> **Breaking behavior changes:**
`AssetsContractController:getERC721OwnerOf` and
`AssetsContractController:getERC1155BalanceOf` are removed from
`NftController` `AllowedActions`,
`checkAndUpdateSingleNftOwnershipStatus` is removed, and ownership
refresh now **removes NFTs confirmed as unowned** from state instead of
setting `isCurrentlyOwned: false`. Tests and changelog are updated
accordingly, and `multicall` gains comprehensive coverage for the new
NFT ownership batching utility.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
f782f90. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@juanmigdr juanmigdr enabled auto-merge April 13, 2026 10:00
@juanmigdr juanmigdr disabled auto-merge April 13, 2026 10:00
@juanmigdr juanmigdr enabled auto-merge April 15, 2026 12:33
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 15, 2026
@socket-security

socket-security Bot commented Apr 15, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​metamask/​assets-controllers@​104.0.0721009198100

View full report

@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Apr 15, 2026
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Apr 15, 2026
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Apr 15, 2026
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Apr 16, 2026
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Apr 16, 2026
sahar-fehri
sahar-fehri previously approved these changes Apr 16, 2026
@juanmigdr juanmigdr dismissed stale reviews from sahar-fehri and Prithpal-Sooriya via 4df107d April 17, 2026 10:17
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Apr 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmations, SmokeIdentity, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeTrade, SmokeWalletPlatform, SmokeCard, SmokePerps, SmokeRamps, SmokeMultiChainAPI, SmokePredictions, SmokeSeedlessOnboarding, FlaskBuildTests
  • Selected Performance tags: @PerformanceAccountList, @PerformanceOnboarding, @PerformanceLogin, @PerformanceSwaps, @PerformanceLaunch, @PerformanceAssetLoading, @PerformancePredict, @PerformancePreps
  • Risk Level: high
  • AI Confidence: 100%
click to see 🤖 AI reasoning details

E2E Test Selection:
Hard rule (controller-version-update): @MetaMask controller package version updated in package.json: @metamask/assets-controllers. Running all tests.

Performance Test Selection:
Hard rule (controller-version-update): @MetaMask controller package version updated in package.json: @metamask/assets-controllers. Running all tests.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
12 value mismatches detected (expected — fixture represents an existing user).
View details

@Cal-L Cal-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@juanmigdr juanmigdr added this pull request to the merge queue Apr 17, 2026
Merged via the queue into main with commit 9d35858 Apr 17, 2026
115 checks passed
@juanmigdr juanmigdr deleted the fix/nft-refresh-use-multicall branch April 17, 2026 15:46
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 17, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.75.0 Issue or pull request that will be included in release 7.75.0 label Apr 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.75.0 Issue or pull request that will be included in release 7.75.0 risk-high Extensive testing required · High bug introduction risk size-S team-assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants