Skip to content

chore: explicitly pass networkClientId for nftController #5622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 2, 2025

Conversation

sahar-fehri
Copy link
Contributor

@sahar-fehri sahar-fehri commented Apr 9, 2025

Explanation

This PR is part of a larger effort to remove the global network selector.

On this PR:

  • Removal of this.#chainId on the nftController
  • Removal of chainId from nftController constructor
  • Making the optional networkClientId in all functions a mandatory field

UI integration:

References

Changelog

@metamask/assets-controllers

  • UPDATE: Updated NftController and NftDetectionController to eliminate the dependency on the current chain. All functions that previously accepted networkClientId as an optional parameter now require it as a mandatory parameter

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, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

this.messagingSystem.subscribe(
'NetworkController:networkDidChange',
this.#onNetworkControllerNetworkDidChange.bind(this),
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This subscription is removed because the purpose of onNetworkControllerNetworkDidChange was to populate this.#chainId which has been removed

selectedNetworkClientId,
);
this.#chainId = chainId;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this because subscription was also removed

return chainId;
}
return this.#chainId;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been removed and we are making a call to NetworkController:getNetworkClientById when needed since we no longer fallback to this.#chainId

// TODO: revisit this with Solana support and instead of passing chainId, make sure chainId is read from nftMetadata
const chainIdToAddTo =
chainId || this.#getCorrectChainId({ networkClientId });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this in favor of the mandatory networkClientId;
This will be called from nftDetectionController to add NFTs in which case we will take the chainId from the NFT and find the networkClientId. Or directly from clients, in which case they need to provide the networkClientId.

@sahar-fehri
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "27.0.0-preview-3fadbce0",
  "@metamask-previews/address-book-controller": "6.0.3-preview-3fadbce0",
  "@metamask-previews/announcement-controller": "7.0.3-preview-3fadbce0",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-3fadbce0",
  "@metamask-previews/approval-controller": "7.1.3-preview-3fadbce0",
  "@metamask-previews/assets-controllers": "56.0.0-preview-3fadbce0",
  "@metamask-previews/base-controller": "8.0.0-preview-3fadbce0",
  "@metamask-previews/bridge-controller": "13.0.0-preview-3fadbce0",
  "@metamask-previews/bridge-status-controller": "12.0.1-preview-3fadbce0",
  "@metamask-previews/build-utils": "3.0.3-preview-3fadbce0",
  "@metamask-previews/chain-agnostic-permission": "0.3.0-preview-3fadbce0",
  "@metamask-previews/composable-controller": "11.0.0-preview-3fadbce0",
  "@metamask-previews/controller-utils": "11.7.0-preview-3fadbce0",
  "@metamask-previews/earn-controller": "0.11.0-preview-3fadbce0",
  "@metamask-previews/eip1193-permission-middleware": "0.1.0-preview-3fadbce0",
  "@metamask-previews/ens-controller": "16.0.0-preview-3fadbce0",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-3fadbce0",
  "@metamask-previews/gas-fee-controller": "23.0.0-preview-3fadbce0",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-3fadbce0",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-3fadbce0",
  "@metamask-previews/keyring-controller": "21.0.2-preview-3fadbce0",
  "@metamask-previews/logging-controller": "6.0.4-preview-3fadbce0",
  "@metamask-previews/message-manager": "12.0.1-preview-3fadbce0",
  "@metamask-previews/multichain": "4.0.0-preview-3fadbce0",
  "@metamask-previews/multichain-api-middleware": "0.1.1-preview-3fadbce0",
  "@metamask-previews/multichain-network-controller": "0.3.0-preview-3fadbce0",
  "@metamask-previews/multichain-transactions-controller": "0.9.0-preview-3fadbce0",
  "@metamask-previews/name-controller": "8.0.3-preview-3fadbce0",
  "@metamask-previews/network-controller": "23.2.0-preview-3fadbce0",
  "@metamask-previews/notification-services-controller": "5.0.1-preview-3fadbce0",
  "@metamask-previews/permission-controller": "11.0.6-preview-3fadbce0",
  "@metamask-previews/permission-log-controller": "3.0.3-preview-3fadbce0",
  "@metamask-previews/phishing-controller": "12.4.1-preview-3fadbce0",
  "@metamask-previews/polling-controller": "13.0.0-preview-3fadbce0",
  "@metamask-previews/preferences-controller": "17.0.0-preview-3fadbce0",
  "@metamask-previews/profile-sync-controller": "11.0.1-preview-3fadbce0",
  "@metamask-previews/queued-request-controller": "10.0.0-preview-3fadbce0",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-3fadbce0",
  "@metamask-previews/remote-feature-flag-controller": "1.6.0-preview-3fadbce0",
  "@metamask-previews/sample-controllers": "0.1.0-preview-3fadbce0",
  "@metamask-previews/selected-network-controller": "22.0.0-preview-3fadbce0",
  "@metamask-previews/signature-controller": "27.1.0-preview-3fadbce0",
  "@metamask-previews/token-search-discovery-controller": "2.1.0-preview-3fadbce0",
  "@metamask-previews/transaction-controller": "54.0.0-preview-3fadbce0",
  "@metamask-previews/user-operation-controller": "33.0.0-preview-3fadbce0"
}

@sahar-fehri sahar-fehri marked this pull request as ready for review April 11, 2025 14:40
@sahar-fehri sahar-fehri requested review from a team as code owners April 11, 2025 14:40
@sahar-fehri
Copy link
Contributor Author

TODO: Changelog

@salimtb salimtb force-pushed the feat/make-chainId-mandatory-in-nft-controller branch 2 times, most recently from 0d5cebc to 476edcf Compare April 27, 2025 22:17
@salimtb salimtb force-pushed the feat/make-chainId-mandatory-in-nft-controller branch from 476edcf to 42bb475 Compare April 27, 2025 22:28
@salimtb
Copy link
Contributor

salimtb commented Apr 27, 2025

@metamaskbot publish-preview

1 similar comment
@salimtb
Copy link
Contributor

salimtb commented Apr 28, 2025

@metamaskbot publish-preview

salimtb
salimtb previously approved these changes Apr 28, 2025
@sahar-fehri
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "29.0.0-preview-e5f15167",
  "@metamask-previews/address-book-controller": "6.0.3-preview-e5f15167",
  "@metamask-previews/announcement-controller": "7.0.3-preview-e5f15167",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-e5f15167",
  "@metamask-previews/approval-controller": "7.1.3-preview-e5f15167",
  "@metamask-previews/assets-controllers": "65.0.0-preview-e5f15167",
  "@metamask-previews/base-controller": "8.0.1-preview-e5f15167",
  "@metamask-previews/bridge-controller": "28.0.0-preview-e5f15167",
  "@metamask-previews/bridge-status-controller": "25.0.0-preview-e5f15167",
  "@metamask-previews/build-utils": "3.0.3-preview-e5f15167",
  "@metamask-previews/chain-agnostic-permission": "0.7.0-preview-e5f15167",
  "@metamask-previews/composable-controller": "11.0.0-preview-e5f15167",
  "@metamask-previews/controller-utils": "11.9.0-preview-e5f15167",
  "@metamask-previews/delegation-controller": "0.3.0-preview-e5f15167",
  "@metamask-previews/earn-controller": "0.14.0-preview-e5f15167",
  "@metamask-previews/eip1193-permission-middleware": "0.1.0-preview-e5f15167",
  "@metamask-previews/ens-controller": "16.0.0-preview-e5f15167",
  "@metamask-previews/error-reporting-service": "0.0.0-preview-e5f15167",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-e5f15167",
  "@metamask-previews/gas-fee-controller": "23.0.0-preview-e5f15167",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-e5f15167",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-e5f15167",
  "@metamask-previews/keyring-controller": "22.0.0-preview-e5f15167",
  "@metamask-previews/logging-controller": "6.0.4-preview-e5f15167",
  "@metamask-previews/message-manager": "12.0.1-preview-e5f15167",
  "@metamask-previews/multichain": "4.1.0-preview-e5f15167",
  "@metamask-previews/multichain-api-middleware": "0.4.0-preview-e5f15167",
  "@metamask-previews/multichain-network-controller": "0.7.0-preview-e5f15167",
  "@metamask-previews/multichain-transactions-controller": "1.0.0-preview-e5f15167",
  "@metamask-previews/name-controller": "8.0.3-preview-e5f15167",
  "@metamask-previews/network-controller": "23.5.0-preview-e5f15167",
  "@metamask-previews/notification-services-controller": "8.0.0-preview-e5f15167",
  "@metamask-previews/permission-controller": "11.0.6-preview-e5f15167",
  "@metamask-previews/permission-log-controller": "3.0.3-preview-e5f15167",
  "@metamask-previews/phishing-controller": "12.5.0-preview-e5f15167",
  "@metamask-previews/polling-controller": "13.0.0-preview-e5f15167",
  "@metamask-previews/preferences-controller": "18.0.0-preview-e5f15167",
  "@metamask-previews/profile-sync-controller": "15.0.0-preview-e5f15167",
  "@metamask-previews/queued-request-controller": "10.0.0-preview-e5f15167",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-e5f15167",
  "@metamask-previews/remote-feature-flag-controller": "1.6.0-preview-e5f15167",
  "@metamask-previews/sample-controllers": "0.1.0-preview-e5f15167",
  "@metamask-previews/selected-network-controller": "22.1.0-preview-e5f15167",
  "@metamask-previews/signature-controller": "29.0.0-preview-e5f15167",
  "@metamask-previews/token-search-discovery-controller": "3.2.0-preview-e5f15167",
  "@metamask-previews/transaction-controller": "56.2.0-preview-e5f15167",
  "@metamask-previews/user-operation-controller": "35.0.0-preview-e5f15167"
}

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

LGTM!

@sahar-fehri sahar-fehri merged commit f16ddbe into main Jun 2, 2025
210 checks passed
@sahar-fehri sahar-fehri deleted the feat/make-chainId-mandatory-in-nft-controller branch June 2, 2025 08:05
github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Jun 3, 2025
## **Description**

This PR integrates the changes from this core PR
MetaMask/core#5622
Making networkClientId no longer optional for `nftController` and
`nftDetectionController` functions.

Users should not experience any changes related to NFT flows.


[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31917?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

Test autodetection

1. Import a new account that you know has NFTs on linea or Ethereum
mainnet
2. Go to NFT tab.
3. You should see a loader then your NFTs will appear correctly
4. Switch between popular networks and current network and it should
filter your NFTs correctly

Test import/remove NFT

1. Go to NFT tab
2. Click on any NFT
3. Click on options and click remove NFT
4. NFT should be removed successfully
5. Re-import the NFT (whether on the NFT network or another network)
6. NFT should be imported successfully


## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

---------

Co-authored-by: salimtb <[email protected]>
Co-authored-by: MetaMask Bot <[email protected]>
github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Jun 3, 2025
## **Description**

This PR integrates the changes from this core PR
MetaMask/core#5622
Making networkClientId no longer optional for `nftController` and
`nftDetectionController` functions.

Users should not experience any changes related to NFT flows.


[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31917?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

Test autodetection

1. Import a new account that you know has NFTs on linea or Ethereum
mainnet
2. Go to NFT tab.
3. You should see a loader then your NFTs will appear correctly
4. Switch between popular networks and current network and it should
filter your NFTs correctly

Test import/remove NFT

1. Go to NFT tab
2. Click on any NFT
3. Click on options and click remove NFT
4. NFT should be removed successfully
5. Re-import the NFT (whether on the NFT network or another network)
6. NFT should be imported successfully


## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

---------

Co-authored-by: salimtb <[email protected]>
Co-authored-by: MetaMask Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GNS] Refactor NFTController: Remove Private Property #chainId and the fallback on current selected network
5 participants