Skip to content

feat: Add NetworkVisibilityController #5939

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@

## Assets Team
/packages/assets-controllers @MetaMask/metamask-assets
/packages/network-visibility-controller @MetaMask/metamask-assets

## Confirmations Team
/packages/address-book-controller @MetaMask/confirmations
@@ -159,3 +160,5 @@
/packages/foundryup/CHANGELOG.md @MetaMask/mobile-platform @MetaMask/extension-platform @MetaMask/wallet-framework-engineers
/packages/seedless-onboarding-controller/package.json @MetaMask/web3auth @MetaMask/wallet-framework-engineers
/packages/seedless-onboarding-controller/CHANGELOG.md @MetaMask/web3auth @MetaMask/wallet-framework-engineers
/packages/network-visibility-controller/package.json @MetaMask/metamask-assets @MetaMask/wallet-framework-engineers
/packages/network-visibility-controller/CHANGELOG.md @MetaMask/metamask-assets @MetaMask/wallet-framework-engineers
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ Each package in this repository has its own README where you can find installati
- [`@metamask/multichain-transactions-controller`](packages/multichain-transactions-controller)
- [`@metamask/name-controller`](packages/name-controller)
- [`@metamask/network-controller`](packages/network-controller)
- [`@metamask/network-visibility-controller`](packages/network-visibility-controller)
- [`@metamask/notification-services-controller`](packages/notification-services-controller)
- [`@metamask/permission-controller`](packages/permission-controller)
- [`@metamask/permission-log-controller`](packages/permission-log-controller)
@@ -79,7 +80,7 @@ Each package in this repository has its own README where you can find installati
%%{ init: { 'flowchart': { 'curve': 'bumpX' } } }%%
graph LR;
linkStyle default opacity:0.5
account_wallet_controller(["@metamask/account-tree-controller"]);
account_tree_controller(["@metamask/account-tree-controller"]);
accounts_controller(["@metamask/accounts-controller"]);
address_book_controller(["@metamask/address-book-controller"]);
announcement_controller(["@metamask/announcement-controller"]);
@@ -112,6 +113,7 @@ linkStyle default opacity:0.5
multichain_transactions_controller(["@metamask/multichain-transactions-controller"]);
name_controller(["@metamask/name-controller"]);
network_controller(["@metamask/network-controller"]);
network_visibility_controller(["@metamask/network-visibility-controller"]);
notification_services_controller(["@metamask/notification-services-controller"]);
permission_controller(["@metamask/permission-controller"]);
permission_log_controller(["@metamask/permission-log-controller"]);
@@ -129,9 +131,9 @@ linkStyle default opacity:0.5
token_search_discovery_controller(["@metamask/token-search-discovery-controller"]);
transaction_controller(["@metamask/transaction-controller"]);
user_operation_controller(["@metamask/user-operation-controller"]);
account_wallet_controller --> base_controller;
account_wallet_controller --> accounts_controller;
account_wallet_controller --> keyring_controller;
account_tree_controller --> base_controller;
account_tree_controller --> accounts_controller;
account_tree_controller --> keyring_controller;
accounts_controller --> base_controller;
accounts_controller --> keyring_controller;
accounts_controller --> network_controller;
@@ -148,6 +150,7 @@ linkStyle default opacity:0.5
assets_controllers --> keyring_controller;
assets_controllers --> network_controller;
assets_controllers --> permission_controller;
assets_controllers --> phishing_controller;
assets_controllers --> preferences_controller;
assets_controllers --> transaction_controller;
base_controller --> json_rpc_engine;
@@ -192,6 +195,7 @@ linkStyle default opacity:0.5
ens_controller --> base_controller;
ens_controller --> controller_utils;
ens_controller --> network_controller;
error_reporting_service --> base_controller;
eth_json_rpc_provider --> json_rpc_engine;
gas_fee_controller --> base_controller;
gas_fee_controller --> controller_utils;
@@ -226,6 +230,7 @@ linkStyle default opacity:0.5
name_controller --> controller_utils;
network_controller --> base_controller;
network_controller --> controller_utils;
network_controller --> error_reporting_service;
network_controller --> eth_json_rpc_provider;
network_controller --> json_rpc_engine;
notification_services_controller --> base_controller;
@@ -261,6 +266,8 @@ linkStyle default opacity:0.5
sample_controllers --> base_controller;
sample_controllers --> controller_utils;
sample_controllers --> network_controller;
seedless_onboarding_controller --> base_controller;
seedless_onboarding_controller --> keyring_controller;
selected_network_controller --> base_controller;
selected_network_controller --> json_rpc_engine;
selected_network_controller --> network_controller;
10 changes: 10 additions & 0 deletions packages/network-visibility-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

[Unreleased]: https://github.com/MetaMask/core/
20 changes: 20 additions & 0 deletions packages/network-visibility-controller/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2025 MetaMask

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15 changes: 15 additions & 0 deletions packages/network-visibility-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# `@metamask/network-visibility-controller`

Handles user-facing network state for how networks are displayed and interacted with.

## Installation

`yarn add @metamask/network-visibility-controller`

or

`npm install @metamask/network-visibility-controller`

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
26 changes: 26 additions & 0 deletions packages/network-visibility-controller/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

const merge = require('deepmerge');
const path = require('path');

const baseConfig = require('../../jest.config.packages');

const displayName = path.basename(__dirname);

module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
});
87 changes: 87 additions & 0 deletions packages/network-visibility-controller/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"name": "@metamask/network-visibility-controller",
"version": "0.0.0",
"description": "Handles user-facing network state for how networks are displayed and interacted with",
"keywords": [
"MetaMask",
"Ethereum"
],
"homepage": "https://github.com/MetaMask/core/tree/main/packages/network-visibility-controller#readme",
"bugs": {
"url": "https://github.com/MetaMask/core/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/core.git"
},
"license": "MIT",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"files": [
"dist/"
],
"scripts": {
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
"build:docs": "typedoc",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/network-visibility-controller",
"since-latest-release": "../../scripts/since-latest-release.sh",
"changelog:update": "../../scripts/update-changelog.sh @metamask/network-visibility-controller",
"publish:preview": "yarn npm publish --tag preview",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^3.0.4",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/error-reporting-service": "^1.0.0",
"@metamask/network-controller": "^23.6.0",
"@metamask/providers": "^22.1.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typedoc": "^0.24.8",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.2.2"
},
"engines": {
"node": "^18.18 || >=20"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"@metamask/base-controller": "^8.0.1",
"@metamask/keyring-api": "^18.0.0",
"@metamask/keyring-snap-client": "^5.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we use this dep, I don't see it when I search for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are inheriting the BaseController in NetworkVisibilityController so that we can extend from it. I saw this pattern elsewhere in the app. Did I miss something here?

"@metamask/multichain-network-controller": "^0.8.0"
},
"peerDependencies": {
"@metamask/error-reporting-service": "^1.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, searching for this, I don't see if in out src.

"@metamask/network-controller": "^23.0.0",
"@metamask/providers": "^22.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, I think we can remove it since it is not used.

},
"lavamoat": {
"allowScripts": {
"@metamask/multichain-network-controller>@metamask/accounts-controller>@metamask/keyring-controller>ethereumjs-wallet>ethereum-cryptography>keccak": false,
"@metamask/multichain-network-controller>@metamask/accounts-controller>@metamask/keyring-controller>ethereumjs-wallet>ethereum-cryptography>secp256k1": false
}
}
}
Loading

Unchanged files with check annotations Beta

import { errorCodes, JsonRpcError } from '@metamask/rpc-errors';
import { nanoid } from 'nanoid';
import { flushPromises } from '../../../tests/helpers';

Check warning on line 7 in packages/approval-controller/src/ApprovalController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

`../../../tests/helpers` import should occur after import of `./errors`
import type {
AddApprovalOptions,
ApprovalControllerActions,
const id = Object.keys(
approvalController.state[PENDING_APPROVALS_STORE_KEY],
)[0];
expect(id && typeof id === 'string').toBe(true);

Check warning on line 356 in packages/approval-controller/src/ApprovalController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

Avoid having conditionals in tests
});
it('adds correctly specified entry with request data', () => {
).not.toThrow();
expect(
approvalController.has({ id: 'foo1' }) &&

Check warning on line 407 in packages/approval-controller/src/ApprovalController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

Avoid having conditionals in tests
approvalController.has({ id: 'foo2' }),
).toBe(true);
expect(
approvalController.has({ origin: ORIGIN }) &&

Check warning on line 412 in packages/approval-controller/src/ApprovalController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

Avoid having conditionals in tests

Check warning on line 412 in packages/approval-controller/src/ApprovalController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

Avoid having conditionals in tests
approvalController.has({ origin: ORIGIN, type: 'myType1' }) &&
approvalController.has({ origin: ORIGIN, type: 'myType2' }),
).toBe(true);
approvalController.accept('foo');
expect(
!approvalController.has({ id: 'foo' }) &&

Check warning on line 949 in packages/approval-controller/src/ApprovalController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

Avoid having conditionals in tests

Check warning on line 949 in packages/approval-controller/src/ApprovalController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

Avoid having conditionals in tests

Check warning on line 949 in packages/approval-controller/src/ApprovalController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

Avoid having conditionals in tests
!approvalController.has({ type: 'type' }) &&
!approvalController.has({ origin: 'bar.baz' }) &&
!approvalController.state[PENDING_APPROVALS_STORE_KEY].foo,
approvalController.accept('fizz');
expect(
!approvalController.has({ id: 'fizz' }) &&

Check warning on line 969 in packages/approval-controller/src/ApprovalController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

Avoid having conditionals in tests
!approvalController.has({ origin: 'bar.baz', type: 'type2' }),
).toBe(true);
import { SnapStatus } from '@metamask/snaps-utils';
import type { CaipChainId } from '@metamask/utils';
import type { V4Options } from 'uuid';
import * as uuid from 'uuid';

Check warning on line 21 in packages/accounts-controller/src/AccountsController.test.ts

GitHub Actions / Lint, build, and test / Lint (22.x)

No exported names found in module 'uuid'
import type {
AccountsControllerActions,