Repository navigation
feat: wire removeNft into NftDetectionController and pass explicit NFT source - #47436
Conversation
✨ Files requiring CODEOWNER review ✨🫰 @MetaMask/core-platform (1 files, +14 -3)
👨🔧 @MetaMask/extension-platform (1 files, +14 -3)
💎 @MetaMask/metamask-assets (2 files, +31 -0)
📜 @MetaMask/policy-reviewers (8 files, +80 -8)
Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. |
Builds ready [6e2ec0e]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 3 warn · 🔴 2 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Builds ready [105b7ef]
⚡ Performance Benchmarks (Total: 🟢 5 pass · 🟡 5 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
…and-source # Conflicts: # package.json # yarn.lock
Builds ready [2dd78f7]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 4 warn · 🔴 2 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [97ddfba]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 4 warn · 🔴 2 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [475d84c]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 2 warn · 🔴 4 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
|
There was a problem hiding this comment.
Would love to see them removed!



Description
Adapts the extension to two changes in
@metamask/assets-controllers:NftDetectionControllerrequires aremoveNftoption. During detection, an NFT already in state that the API now returns as spam is removed (only if its stored source isdetectedor unset;customanddappare never auto-removed). It is not added toignoredNfts, so it can come back if un-spammed.source(custom,dapp,detected).addNft,addNftsandaddNftVerifyOwnershipdefault toSource.Customwhen it is omitted, so any caller that is not a manual import must pass a source explicitly.Changes:
nft-detection-controller-init.ts: passremoveNft(same lazyNftControllergetter asaddNfts).metamask-controller.jsgetApi:addNftandaddNftVerifyOwnershipare only called from the UI import flow, so they now passSource.Customexplicitly (same as the default, now explicit).metamask-controller.js_updateNFTOwnership: after a confirmed contract interaction, NFTs transferred to the selected account are added from the receipt logs. This is an automatic add (not a manual import), so it now passesSource.Detected. Without it, the defaultCustomwould exempt these NFTs from spam removal.Behavior notes for reviewers:
_updateNFTOwnershipchange is extension-specific (mobile has no equivalent). NFTs added there are now spam-removable, and theNftAddedevent reportssource: 'detected'instead of'custom'for them.addNftcaller in the extension (mobile had two); ownership refreshes usecheckAndUpdate*OwnershipStatus, which keeps the stored source.Reference: metamask-mobile#38283.
Changelog
CHANGELOG entry: Spam NFTs already in your wallet are now removed automatically when detected
Related issues
Fixes: ASSETS-4116
Related: core#8237, core#11106, metamask-mobile#38283
Manual testing steps
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes NFT add/remove behavior and spam handling in wallet state; wrong source tagging could remove user-imported NFTs or leave spam in place.
Overview
Bumps
@metamask/assets-controllersto 113.0.0 (with LavaMoat policy updates) and adapts the extension to NFT spam auto-removal and per-NFTsourcetracking.NftDetectionControllerinit now passesremoveNftintoNftController, matching the new required option so detection can drop spam NFTs that were added as detected (not manual imports).metamask-controllersetsSource.Customon UIaddNft/addNftVerifyOwnershipAPI paths, andSource.Detectedwhen NFTs are added from transaction receipt logs in_updateNFTOwnership, so auto-added NFTs stay eligible for spam removal instead of inheriting the default custom exemption.Tests cover init delegation and the three source call sites.
Reviewed by Cursor Bugbot for commit 475d84c. Bugbot is set up for automated code reviews on this repo. Configure here.