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
Conversation
…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 -->
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. |
Contributor
🔍 Smart E2E Test Selection⏭️ Smart E2E selection skipped - PR targets a release branch (release/*) All E2E tests pre-selected. |
Contributor
|
Close this cherry-pick PR as we will include it in 7.75 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thoughRPC / explorer lists are still mutable. Fire-and-forget
saveNetworkcalls from sheet actions could fail silently or race with sheet
dismissal.
Solution:
saveNetworkwith options that skip post-save navigation, bypassenableAction/ form-disabled guards where appropriate, and commit anew dirty baseline via
commitBaselineFromFormStateon success.validateNewRpcEndpointForSheetfirst,then persists using a committed form snapshot and
skipChainIdSubmitValidation: trueso the redundant submit-timechain-id check is not double-run. Other sheet persists pass an explicit
snapshot without that flag so submit validation still runs when needed.
delete build the next form state with shared pure helpers
(
appendRpcItemToFormState,applyRpcSelectionToFormState,removeRpcUrlFromFormState, block explorer equivalents),awaitpersist, then apply the form hook update only after success; failures
surface inline errors and loading states.
useNetworkFormuses the same helpers so snapshots match runtimesetFormbehavior. Tests were updated (act/waitForaround asyncsheet 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
Screenshots/Recordings
Before
After
network-urls.mov
Pre-merge author checklist
Docs and MetaMask Mobile
Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Performance checks (if applicable)
SRPs
to import wallets with many accounts and tokens
performance metrics
trace()for usage andaddTokenfor an example
For performance guidelines and tooling, see the Performance
Guide.
Pre-merge reviewer checklist
app, test code being changed).
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
UrlSheetMutationCommittedHandlerpath:NetworkDetailsViewschedulessaveNetworkafter sheet mutations (nonavigation, bypasses
enableAction/disabled guards, optionally skipschain-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
useNetworkFormto use them, hardensuseNetworkOperations.saveNetworkto returnbooleanand handlefailures, and introduces
validateNewRpcEndpointForSheetforRPC-sheet-specific validation (duplicates, URL rules, and
eth_chainIdmatch). 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.