Skip to content

feat: add @metamask/network-connection-banner-controller#9041

Draft
cryptodev-2s wants to merge 10 commits into
mainfrom
wpc-1014-network-connection-banner-controller
Draft

feat: add @metamask/network-connection-banner-controller#9041
cryptodev-2s wants to merge 10 commits into
mainfrom
wpc-1014-network-connection-banner-controller

Conversation

@cryptodev-2s

@cryptodev-2s cryptodev-2s commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Explanation

The RPC connection banner ("Still connecting" / "Unable to connect") is currently rendered by both metamask-extension and metamask-mobile based on duplicated logic in each repo:

  • The 5s / 30s timer state machine.
  • The show/hide rule (custom-RPC override, ≥2 distinct registrable domains failing, or all-enabled-failed escape hatch).
  • eTLD+1 grouping via psl so a single provider's wide outage doesn't pop the banner.
  • Infura URL detection.
  • The { chainId, networkName, rpcUrl, isInfuraEndpoint, infuraNetworkClientId } payload shape.

Every tweak — a rule refinement, an analytics property, an edge-case fix — has to land in both repos. The recent Cursor-bot exchange on the mobile PR around the all-down rule made the maintenance cost visible.

This PR introduces @metamask/network-connection-banner-controller so there's a single source of truth. The controller:

  • Subscribes to NetworkController:stateChanged, NetworkEnablementController:stateChanged, and ConnectivityController:stateChanged via the messenger.
  • Runs the 5s/30s escalation timers internally.
  • Exposes a flat state { status: 'available' | 'degraded' | 'unavailable', network: FailedNetwork | null } that clients subscribe to.
  • Exposes two messenger actions: dismissBanner() and switchToDefaultInfuraRpc({ chainId }) — the latter looks up the chain's first Infura endpoint and calls NetworkController:updateNetwork with replacementSelectedRpcEndpointIndex.
  • Stays analytics-free; clients diff state-change events into their own analytics translation.

Clients will subsequently migrate to consume this controller state and only own rendering + click handlers. Those migrations are out of scope here.

Layout mirrors @metamask/connectivity-controller exactly: same package.json shape, same tsconfig.json / tsconfig.build.json / jest.config.js patterns, same auto-generated *-method-action-types.ts, same withController + getRootMessenger test scaffold. The eTLD+1 logic and isLocalhostOrIPAddress are lifted verbatim from the extension's shared/lib/url-utils.ts (and the mobile equivalent in app/util/url-utils.ts), where they shipped reviewed and tested.

psl 1.15 ships its types field outside its exports map so TypeScript's node16 module resolution can't find it; a small ambient src/psl.d.ts shim mirrors the workaround already in use in extension and mobile. ip-regex is pinned to ^4.3.0 (last CJS release) because the monorepo's Jest config doesn't transform ESM-only deps.

100% test coverage across the new package, mirroring the rule cases that landed in the merged extension PR and the in-flight mobile PR: single-Infura suppression, Infura-wide outage suppression, multi-domain trigger, custom override, all-down escape hatch, offline short-circuit, switch-to-Infura dispatch.

References

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
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@socket-security

socket-security Bot commented Jun 8, 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
Addedip-regex@​4.3.01001009580100
Updatedpsl@​1.9.0 ⏵ 1.15.010010010080100

View full report

@cryptodev-2s cryptodev-2s force-pushed the wpc-1014-network-connection-banner-controller branch 2 times, most recently from 9111156 to d1fa945 Compare June 8, 2026 16:31
@cryptodev-2s

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.1-preview-7507a11
@metamask-previews/accounts-controller@39.0.0-preview-7507a11
@metamask-previews/address-book-controller@7.1.2-preview-7507a11
@metamask-previews/ai-controllers@0.7.0-preview-7507a11
@metamask-previews/analytics-controller@1.1.1-preview-7507a11
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-7507a11
@metamask-previews/announcement-controller@8.1.0-preview-7507a11
@metamask-previews/app-metadata-controller@2.0.1-preview-7507a11
@metamask-previews/approval-controller@9.0.1-preview-7507a11
@metamask-previews/assets-controller@8.3.2-preview-7507a11
@metamask-previews/assets-controllers@108.5.0-preview-7507a11
@metamask-previews/authenticated-user-storage@2.0.0-preview-7507a11
@metamask-previews/base-controller@9.1.0-preview-7507a11
@metamask-previews/base-data-service@0.1.3-preview-7507a11
@metamask-previews/bridge-controller@73.2.1-preview-7507a11
@metamask-previews/bridge-status-controller@72.0.2-preview-7507a11
@metamask-previews/build-utils@3.0.4-preview-7507a11
@metamask-previews/chain-agnostic-permission@1.6.1-preview-7507a11
@metamask-previews/chomp-api-service@3.1.0-preview-7507a11
@metamask-previews/claims-controller@0.5.2-preview-7507a11
@metamask-previews/client-controller@1.0.1-preview-7507a11
@metamask-previews/compliance-controller@2.1.0-preview-7507a11
@metamask-previews/composable-controller@12.0.1-preview-7507a11
@metamask-previews/config-registry-controller@0.4.0-preview-7507a11
@metamask-previews/connectivity-controller@0.2.0-preview-7507a11
@metamask-previews/controller-utils@12.1.0-preview-7507a11
@metamask-previews/core-backend@6.3.2-preview-7507a11
@metamask-previews/delegation-controller@3.0.1-preview-7507a11
@metamask-previews/earn-controller@12.2.0-preview-7507a11
@metamask-previews/eip-5792-middleware@3.0.4-preview-7507a11
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-7507a11
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-7507a11
@metamask-previews/ens-controller@19.1.3-preview-7507a11
@metamask-previews/eth-block-tracker@15.0.1-preview-7507a11
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-7507a11
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-7507a11
@metamask-previews/foundryup@1.0.1-preview-7507a11
@metamask-previews/gas-fee-controller@26.2.2-preview-7507a11
@metamask-previews/gator-permissions-controller@4.2.0-preview-7507a11
@metamask-previews/geolocation-controller@0.1.3-preview-7507a11
@metamask-previews/json-rpc-engine@10.5.0-preview-7507a11
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-7507a11
@metamask-previews/keyring-controller@26.0.0-preview-7507a11
@metamask-previews/logging-controller@8.0.2-preview-7507a11
@metamask-previews/message-manager@14.1.2-preview-7507a11
@metamask-previews/messenger@1.2.0-preview-7507a11
@metamask-previews/messenger-cli@0.2.0-preview-7507a11
@metamask-previews/money-account-balance-service@1.0.2-preview-7507a11
@metamask-previews/money-account-controller@0.3.2-preview-7507a11
@metamask-previews/money-account-upgrade-controller@2.0.3-preview-7507a11
@metamask-previews/multichain-account-service@10.0.2-preview-7507a11
@metamask-previews/multichain-api-middleware@3.1.3-preview-7507a11
@metamask-previews/multichain-network-controller@3.1.3-preview-7507a11
@metamask-previews/multichain-transactions-controller@7.1.1-preview-7507a11
@metamask-previews/name-controller@9.1.2-preview-7507a11
@metamask-previews/network-connection-banner-controller@0.1.0-preview-7507a11
@metamask-previews/network-controller@32.0.0-preview-7507a11
@metamask-previews/network-enablement-controller@5.3.0-preview-7507a11
@metamask-previews/notification-services-controller@24.1.2-preview-7507a11
@metamask-previews/passkey-controller@2.0.1-preview-7507a11
@metamask-previews/permission-controller@13.1.1-preview-7507a11
@metamask-previews/permission-log-controller@5.1.0-preview-7507a11
@metamask-previews/perps-controller@8.0.0-preview-7507a11
@metamask-previews/phishing-controller@17.2.0-preview-7507a11
@metamask-previews/polling-controller@16.0.6-preview-7507a11
@metamask-previews/preferences-controller@23.1.0-preview-7507a11
@metamask-previews/profile-metrics-controller@3.1.6-preview-7507a11
@metamask-previews/profile-sync-controller@28.1.1-preview-7507a11
@metamask-previews/ramps-controller@14.1.1-preview-7507a11
@metamask-previews/rate-limit-controller@7.0.1-preview-7507a11
@metamask-previews/react-data-query@0.2.1-preview-7507a11
@metamask-previews/remote-feature-flag-controller@4.2.2-preview-7507a11
@metamask-previews/sample-controllers@5.0.1-preview-7507a11
@metamask-previews/seedless-onboarding-controller@10.0.1-preview-7507a11
@metamask-previews/selected-network-controller@26.1.3-preview-7507a11
@metamask-previews/shield-controller@5.1.2-preview-7507a11
@metamask-previews/signature-controller@39.2.4-preview-7507a11
@metamask-previews/snap-account-service@0.3.0-preview-7507a11
@metamask-previews/social-controllers@2.2.1-preview-7507a11
@metamask-previews/storage-service@1.0.1-preview-7507a11
@metamask-previews/subscription-controller@6.1.3-preview-7507a11
@metamask-previews/transaction-controller@67.0.0-preview-7507a11
@metamask-previews/transaction-pay-controller@23.3.0-preview-7507a11
@metamask-previews/user-operation-controller@41.2.3-preview-7507a11
@metamask-previews/wallet@2.0.0-preview-7507a11

@cryptodev-2s cryptodev-2s force-pushed the wpc-1014-network-connection-banner-controller branch from 7507a11 to 612f8a3 Compare June 9, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant