Skip to content

chore(runway): cherry-pick fix: multichain account network permissions switch cp-7.57.0#21208

Merged
Cal-L merged 1 commit into
release/7.57.0from
runway-cherry-pick-7.57.0-1760541800
Oct 16, 2025
Merged

chore(runway): cherry-pick fix: multichain account network permissions switch cp-7.57.0#21208
Cal-L merged 1 commit into
release/7.57.0from
runway-cherry-pick-7.57.0-1760541800

Conversation

@runway-github

@runway-github runway-github Bot commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

Description

This PR fixes following problem:

When a user changes network permissions for a connected dapp (by going
to Permissions tab → "Use your enabled networks" → selecting different
networks → Update), the dapp's provider doesn't get notified of the
network change. Transactions continue to execute on the initial network
instead of the newly permitted network.

Changelog

CHANGELOG entry: Fixed a bug preventing network switch when dapp network
permissions changes

Related issues

Fixes: #20722

Manual testing steps

Feature: Dapp network permissions change

  Scenario: user changes network permissions
    Given user connected to the dapp with network A

    When user click on Account Icon on top right corner → goes to Permissions tab → "Use your enabled networks" → selecting different networks → Update
    Then after clicking Connect, network of the dapp should change

Screenshots/Recordings

dapp-network-permissions.mov

Before

After

Pre-merge author checklist

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

Ensures per-dapp network switches (and provider notification) when updating permitted networks in Multichain Account Permissions, with supporting selectors/utilities and tests.

  • Multichain Account Permissions (MultichainAccountPermissions.tsx)
    • Implements per-dapp network switching on network-permission updates via SelectedNetworkController.setNetworkClientIdForDomain and SelectedNetworkController.update.
    • Determines current/new EVM chains using useNetworkInfo, selectEvmChainId, parseChainId, and KnownCaipNamespace to switch when the originally permitted network is removed.
    • Leverages networkConfigurations to resolve networkClientId; guards with hasProperty and NetworkConfiguration types.
    • Adds isPerDappSelectedNetworkEnabled and uses getNetworkImageSource for avatars.
  • Tests (MultichainAccountPermissions.test.tsx)
    • Mocks SelectedNetworkController.update, network state, isPerDappSelectedNetworkEnabled, and useNetworkInfo.
    • Adds flow test for selecting a new network and submitting updates; verifies screen transitions and elements.

Written by Cursor Bugbot for commit 8b3bfd6. This will update automatically on new commits. Configure here.

9f95100

…s switch cp-7.57.0 (#21043)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
This PR fixes following problem:

When a user changes network permissions for a connected dapp (by going
to Permissions tab → "Use your enabled networks" → selecting different
networks → Update), the dapp's provider doesn't get notified of the
network change. Transactions continue to execute on the initial network
instead of the newly permitted network.
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **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 a bug preventing network switch when dapp network
permissions changes

## **Related issues**

Fixes: #20722

## **Manual testing steps**

```gherkin
Feature: Dapp network permissions change

  Scenario: user changes network permissions
    Given user connected to the dapp with network A

    When user click on Account Icon on top right corner → goes to Permissions tab → "Use your enabled networks" → selecting different networks → Update
    Then after clicking Connect, network of the dapp should change
```

## **Screenshots/Recordings**

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

https://github.com/user-attachments/assets/b96c2502-777f-43e9-a029-f5d225650bd7
### **Before**

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

### **After**

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

## **Pre-merge author checklist**

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

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

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Switches the active EVM network for a dapp when network permissions
change and triggers a provider update notification.
> 
> - **MultichainAccountPermissions**
(`MultichainAccountPermissions.tsx`):
> - Implements async `handleNetworksSelected` to switch the dapp's
active EVM network when the current permitted network is removed and
another EVM chain is selected.
> - Uses `isPerDappSelectedNetworkEnabled`, `useNetworkInfo`, and
`selectEvmChainId` to resolve current chain and per-dapp context.
> - Finds target network via `networkConfigurations`, extracts
`networkClientId`, calls
`SelectedNetworkController.setNetworkClientIdForDomain`, and triggers
`SelectedNetworkController.update` to notify the dapp.
> - Adds CAIP helpers (`parseChainId`, `KnownCaipNamespace`,
`hasProperty`) and types (`NetworkConfiguration`).
> - **Tests** (`MultichainAccountPermissions.test.tsx`):
> - Extends Engine and selectors mocks
(Network/SelectedNetworkController, network configurations, per-dapp
flag, network info).
> - Adds test for selecting a new network (e.g., Sepolia) and confirming
update.
>   - Retains and adjusts navigation and selection flow tests.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ab6d187. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@runway-github runway-github Bot requested a review from a team as a code owner October 15, 2025 15:23
@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.

@metamaskbot metamaskbot added the team-runway-bot-deprecated DEPRECATED: please use "team-bots" instead label Oct 15, 2025
}
).update((state: { activeDappNetwork: string | null }) => {
state.activeDappNetwork = networkClientId;
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Unsafe Type Assertion Causes Runtime Crashes

An unsafe type assertion on Engine.context.SelectedNetworkController assumes an update method with a specific signature. This lacks runtime verification and can lead to a crash if the method doesn't exist or differs from the assumed type, as suggested by test mocks.

Fix in Cursor Fix in Web

const currentEvmCaipChainId: CaipChainId =
isPerDappSelectedNetworkEnabled()
? `eip155:${parseInt(networkInfo.chainId, 16)}`
: `eip155:${parseInt(currentEvmChainId, 16)}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Missing Null Checks in Network Chain ID Parsing

In handleNetworksSelected, parseInt is called on networkInfo.chainId and currentEvmChainId without null/undefined checks. This can cause runtime errors if values are missing, or produce malformed CAIP chain IDs like eip155:NaN, affecting network operations.

Fix in Cursor Fix in Web

) {
const { rpcEndpoints, defaultRpcEndpointIndex } =
config as NetworkConfiguration;
const { networkClientId } = rpcEndpoints[defaultRpcEndpointIndex];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Array Index Out of Bounds

Accessing rpcEndpoints[defaultRpcEndpointIndex] lacks bounds checking. Even with checks for property existence, defaultRpcEndpointIndex might not be a valid index in the rpcEndpoints array, which could cause a runtime error.

Fix in Cursor Fix in Web

@sonarqubecloud

Copy link
Copy Markdown

@Cal-L Cal-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Cal-L Cal-L merged commit 0313de7 into release/7.57.0 Oct 16, 2025
106 of 112 checks passed
@Cal-L Cal-L deleted the runway-cherry-pick-7.57.0-1760541800 branch October 16, 2025 19:03
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 16, 2025
@metamaskbot metamaskbot added the release-7.57.0 Issue or pull request that will be included in release 7.57.0 label Oct 16, 2025
@metamaskbot

Copy link
Copy Markdown
Collaborator

No release label on PR. Adding release label release-7.57.0 on PR, as PR was cherry-picked in branch 7.57.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.57.0 Issue or pull request that will be included in release 7.57.0 size-M team-runway-bot-deprecated DEPRECATED: please use "team-bots" instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants