Skip to content

chore(runway): cherry-pick refactor(networks): enhance NetworkDetailsView with improved RPC and block explorer handling cp-7.74.0#29283

Closed
runway-github[bot] wants to merge 1 commit into
release/7.74.00from
runway-cherry-pick-7.74.0-1776964982
Closed

chore(runway): cherry-pick refactor(networks): enhance NetworkDetailsView with improved RPC and block explorer handling cp-7.74.0#29283
runway-github[bot] wants to merge 1 commit into
release/7.74.00from
runway-cherry-pick-7.74.0-1776964982

Conversation

@runway-github
Copy link
Copy Markdown
Contributor

@runway-github runway-github Bot commented Apr 23, 2026

Description

Reason: Editing RPC endpoints or block explorers from the network
details bottom sheets could leave the in-app form out of sync with what
was actually saved. Saving from the main screen was also incorrectly
blocked when editable === false (e.g. built-in networks) even though
RPC / explorer lists are still mutable. Fire-and-forget saveNetwork
calls from sheet actions could fail silently or race with sheet
dismissal.

Solution:

  • After RPC / block explorer sheet mutations, the screen schedules
    saveNetwork with options that skip post-save navigation, bypass
    enableAction / form-disabled guards where appropriate, and commit a
    new dirty baseline via commitBaselineFromFormState on success.
  • RPC sheet add runs async validateNewRpcEndpointForSheet first,
    then persists using a committed form snapshot and
    skipChainIdSubmitValidation: true so the redundant submit-time
    chain-id check is not double-run. Other sheet persists pass an explicit
    snapshot without that flag so submit validation still runs when needed.
  • RPC select / delete and block explorer add / select /
    delete build the next form state with shared pure helpers
    (appendRpcItemToFormState, applyRpcSelectionToFormState,
    removeRpcUrlFromFormState, block explorer equivalents), await
    persist, then apply the form hook update only after success; failures
    surface inline errors and loading states.
  • useNetworkForm uses the same helpers so snapshots match runtime
    setForm behavior. Tests were updated (act / waitFor around async
    sheet actions) plus unit coverage for the new utils.

Changelog

CHANGELOG entry: Fixed custom network RPC and block explorer changes
from the network details bottom sheets so they persist reliably,
including for networks with locked name/chain/symbol fields, and added
clearer error feedback when a sheet save fails.

Related issues

Fixes: #28643

Manual testing steps

Feature: Network details — RPC and block explorer bottom sheets

  Scenario: Add RPC from sheet persists without main Save
    Given the user opens Settings > Networks and edits an existing custom network
    When they open the RPC bottom sheet, enter a valid new RPC URL and name, and confirm add
    Then the new RPC appears in the list, the sheet closes or returns to the list as before, and switching away and back shows the RPC still present

  Scenario: RPC sheet add shows error when validation fails
    Given the user is on the add-RPC form inside the RPC bottom sheet
    When they submit an RPC URL that fails sheet validation (e.g. wrong chain or duplicate per product rules)
    Then an inline error is shown and the RPC is not added until the issue is resolved

  Scenario: Select another RPC from the sheet persists
    Given a network has multiple RPC endpoints and the RPC sheet is open
    When the user selects a different endpoint in the list
    Then the sheet dismisses on success and the active RPC reflects the selection after reopening network details

  Scenario: Delete RPC from the sheet persists
    Given a network has more than one RPC and the RPC sheet is open
    When the user deletes a non-selected RPC (or deletes the selected one per product rules)
    Then the list updates and the change survives leaving and re-entering the screen

  Scenario: Add block explorer from sheet persists
    Given the user edits a network and opens the block explorer bottom sheet
    When they enter a valid new explorer URL and tap add
    Then the explorer is selected and the change persists without relying on the main Save button alone

  Scenario: Select or delete block explorer from sheet
    Given the network has multiple block explorer URLs in the sheet
    When the user selects another explorer or deletes one
    Then the UI updates and persisted state matches after revisiting the screen

  Scenario: Built-in network with locked fields can still persist RPC / explorer list edits
    Given a network where name/chain/symbol fields are not editable but RPC/explorer lists are
    When the user changes RPC or block explorer URLs from the sheets
    Then changes persist and the main Save button state matches whether other fields still have unsaved edits

Screenshots/Recordings

Before

After

network-urls.mov

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
  • Use these power-user
    SRPs

    to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production
    performance metrics
  • See trace() for usage and
    addToken
    for an example

For performance guidelines and tooling, see the Performance
Guide
.

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
Modifies network save/persist flow and validation around RPC
endpoints, including new bypass/skip flags and async sheet persistence,
which can affect whether network changes are correctly saved or
navigation occurs.

Overview
Fixes network edit bottom sheets so RPC and block explorer
add/select/delete now persist immediately and reliably
(instead of
being fire-and-forget), with loading + inline error messaging when
persistence fails.

Adds a stable UrlSheetMutationCommittedHandler path:
NetworkDetailsView schedules saveNetwork after sheet mutations (no
navigation, bypasses enableAction/disabled guards, optionally skips
chain-id submit validation) and commits a new dirty baseline on success
so the main Save button stays in sync.

Refactors form dirty detection and URL-list mutations into shared pure
utils (append*/apply*/remove* + networkFormBaselineSnapshot),
updates useNetworkForm to use them, hardens
useNetworkOperations.saveNetwork to return boolean and handle
failures, and introduces validateNewRpcEndpointForSheet for
RPC-sheet-specific validation (duplicates, URL rules, and eth_chainId
match). Tests are expanded/updated for the new async flows and helpers,
and new i18n strings are added for sheet save failures.

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

[2c04dcc](https://github.com/MetaMask/metamask-mobile/commit/2c04dccf8c3fa1872188acb02dca1dfc2a476861)

…View with improved RPC and block explorer handling cp-7.74.0 (#29189)

<!--
Please submit this PR as a draft initially.

Do not mark it as "Ready for review" until this PR meets the canonical
Definition of Ready For Review in `docs/readme/ready-for-review.md`.

In short: the template must be materially complete (not just section
titles
present), all status checks must be currently passing, and the only
expected
follow-up commits must be reviewer-driven.
-->

## **Description**

**Reason:** Editing RPC endpoints or block explorers from the network
details bottom sheets could leave the in-app form out of sync with what
was actually saved. Saving from the main screen was also incorrectly
blocked when `editable === false` (e.g. built-in networks) even though
RPC / explorer lists are still mutable. Fire-and-forget `saveNetwork`
calls from sheet actions could fail silently or race with sheet
dismissal.

**Solution:**

- After RPC / block explorer sheet mutations, the screen schedules
`saveNetwork` with options that skip post-save navigation, bypass
`enableAction` / form-disabled guards where appropriate, and commit a
new dirty baseline via `commitBaselineFromFormState` on success.
- RPC sheet **add** runs async `validateNewRpcEndpointForSheet` first,
then persists using a committed form snapshot and
`skipChainIdSubmitValidation: true` so the redundant submit-time
chain-id check is not double-run. Other sheet persists pass an explicit
snapshot without that flag so submit validation still runs when needed.
- RPC **select** / **delete** and block explorer **add** / **select** /
**delete** build the next form state with shared pure helpers
(`appendRpcItemToFormState`, `applyRpcSelectionToFormState`,
`removeRpcUrlFromFormState`, block explorer equivalents), `await`
persist, then apply the form hook update only after success; failures
surface inline errors and loading states.
- `useNetworkForm` uses the same helpers so snapshots match runtime
`setForm` behavior. Tests were updated (`act` / `waitFor` around async
sheet actions) plus unit coverage for the new utils.


## **Changelog**

<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`

If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`

(This helps the Release Engineer do their job more quickly and
accurately)
-->

CHANGELOG entry: Fixed custom network RPC and block explorer changes
from the network details bottom sheets so they persist reliably,
including for networks with locked name/chain/symbol fields, and added
clearer error feedback when a sheet save fails.

## **Related issues**

Fixes: #28643

## **Manual testing steps**

```gherkin
Feature: Network details — RPC and block explorer bottom sheets

  Scenario: Add RPC from sheet persists without main Save
    Given the user opens Settings > Networks and edits an existing custom network
    When they open the RPC bottom sheet, enter a valid new RPC URL and name, and confirm add
    Then the new RPC appears in the list, the sheet closes or returns to the list as before, and switching away and back shows the RPC still present

  Scenario: RPC sheet add shows error when validation fails
    Given the user is on the add-RPC form inside the RPC bottom sheet
    When they submit an RPC URL that fails sheet validation (e.g. wrong chain or duplicate per product rules)
    Then an inline error is shown and the RPC is not added until the issue is resolved

  Scenario: Select another RPC from the sheet persists
    Given a network has multiple RPC endpoints and the RPC sheet is open
    When the user selects a different endpoint in the list
    Then the sheet dismisses on success and the active RPC reflects the selection after reopening network details

  Scenario: Delete RPC from the sheet persists
    Given a network has more than one RPC and the RPC sheet is open
    When the user deletes a non-selected RPC (or deletes the selected one per product rules)
    Then the list updates and the change survives leaving and re-entering the screen

  Scenario: Add block explorer from sheet persists
    Given the user edits a network and opens the block explorer bottom sheet
    When they enter a valid new explorer URL and tap add
    Then the explorer is selected and the change persists without relying on the main Save button alone

  Scenario: Select or delete block explorer from sheet
    Given the network has multiple block explorer URLs in the sheet
    When the user selects another explorer or deletes one
    Then the UI updates and persisted state matches after revisiting the screen

  Scenario: Built-in network with locked fields can still persist RPC / explorer list edits
    Given a network where name/chain/symbol fields are not editable but RPC/explorer lists are
    When the user changes RPC or block explorer URLs from the sheets
    Then changes persist and the main Save button state matches whether other fields still have unsaved edits
```

## **Screenshots/Recordings**

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

### **Before**

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

### **After**


https://github.com/user-attachments/assets/5cfed7ea-e0a8-431e-b726-12580e1d3899


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

## **Pre-merge author checklist**

<!--
Every checklist item must be consciously assessed before marking this PR
as
"Ready for review". A checked box means you deliberately considered that
responsibility, not that you literally performed every action listed.

Unchecked boxes are ambiguous: they are not an implicit "N/A" and they
are not
a silent "skip". See `docs/readme/ready-for-review.md` for the full
checklist
semantics.
-->

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

#### Performance checks (if applicable)

- [ ] I've tested on Android
  - Ideally on a mid-range device; emulator is acceptable
- [ ] I've tested with a power user scenario
- Use these [power-user
SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [ ] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example

For performance guidelines and tooling, see the [Performance
Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers).

## **Pre-merge reviewer checklist**

<!--
Reviewer checklist items follow the same semantics as the author
checklist: an
unchecked box is ambiguous, a checked box means the reviewer consciously
assessed that responsibility. See `docs/readme/ready-for-review.md`.
-->

- [ ] 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.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Modifies network save/persist flow and validation around RPC
endpoints, including new bypass/skip flags and async sheet persistence,
which can affect whether network changes are correctly saved or
navigation occurs.
> 
> **Overview**
> Fixes network edit bottom sheets so **RPC and block explorer
add/select/delete now persist immediately and reliably** (instead of
being fire-and-forget), with loading + inline error messaging when
persistence fails.
> 
> Adds a stable `UrlSheetMutationCommittedHandler` path:
`NetworkDetailsView` schedules `saveNetwork` after sheet mutations (no
navigation, bypasses `enableAction`/disabled guards, optionally skips
chain-id submit validation) and commits a new dirty baseline on success
so the main Save button stays in sync.
> 
> Refactors form dirty detection and URL-list mutations into shared pure
utils (`append*/apply*/remove*` + `networkFormBaselineSnapshot`),
updates `useNetworkForm` to use them, hardens
`useNetworkOperations.saveNetwork` to return `boolean` and handle
failures, and introduces `validateNewRpcEndpointForSheet` for
RPC-sheet-specific validation (duplicates, URL rules, and `eth_chainId`
match). Tests are expanded/updated for the new async flows and helpers,
and new i18n strings are added for sheet save failures.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
4bd51e0. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbotv2 metamaskbotv2 Bot added the team-bots Bot team (for MetaMask Bot, Runway Bot, etc.) label Apr 23, 2026
@github-actions github-actions Bot added the risk-high Extensive testing required · High bug introduction risk label Apr 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - PR targets a release branch (release/*)

All E2E tests pre-selected.

View GitHub Actions results

@chloeYue
Copy link
Copy Markdown
Contributor

Close this cherry-pick PR as we will include it in 7.75

@chloeYue chloeYue closed this Apr 23, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

risk-high Extensive testing required · High bug introduction risk size-XL team-bots Bot team (for MetaMask Bot, Runway Bot, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants