Skip to content

chore(runway): cherry-pick fix(perps): centralize Arbitrum network check in deposit hooks to prevent missing network errors cp-7.72.0#28233

Merged
chloeYue merged 1 commit into
release/7.72.0from
runway-cherry-pick-7.72.0-1775031228
Apr 1, 2026
Merged

chore(runway): cherry-pick fix(perps): centralize Arbitrum network check in deposit hooks to prevent missing network errors cp-7.72.0#28233
chloeYue merged 1 commit into
release/7.72.0from
runway-cherry-pick-7.72.0-1775031228

Conversation

@runway-github

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

Copy link
Copy Markdown
Contributor

Description

Ensures the Arbitrum network exists before every perps deposit
transaction, preventing No network client found for chain errors when
users haven't added Arbitrum to their wallet.

Problem: ensureArbitrumNetworkExists() was previously called at
individual call sites (button handlers, redirect screens), making it
easy to miss entry points. Notably, PerpsOrderRedirect — reachable
from Token Details without mounting PerpsHomeView — had the check
removed, causing deposits to fail when Arbitrum wasn't present.
Additionally, the useFocusEffect call in PerpsHomeView had no
.catch() handler, creating unhandled promise rejections when the
network addition failed.

Solution:

  1. Centralized the network check in usePerpsTrading — both
    depositWithConfirmation() and depositWithOrder() now call await ensureArbitrumNetworkExists() before invoking the controller. Every
    caller is automatically covered.
  2. Kept a preemptive warm-up in PerpsHomeView's useFocusEffect
    with a .catch() handler so the network is added before the user taps
    deposit, avoiding latency.
  3. Removed redundant checks from PerpsOrderRedirect,
    usePerpsHomeActions (deposit and withdraw handlers), and
    usePerpsBalanceTokenFilter.
  4. Updated tests to mock usePerpsNetworkManagement where needed
    due to the new transitive dependency.

Changelog

CHANGELOG entry: Fixed a bug where depositing into Perps from Token
Details could fail if the Arbitrum network had not been added to the
wallet

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2716
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2715

Manual testing steps

Feature: Perps deposit with Arbitrum network guarantee

  Scenario: User deposits from Token Details without Arbitrum in wallet
    Given the user has NOT added the Arbitrum network to their wallet
    And the user is viewing a perps-eligible token on Token Details

    When the user taps the deposit/trade button
    Then the Arbitrum network is automatically added
    And the deposit transaction is created successfully
    And the user is navigated to the confirmation screen

  Scenario: User deposits from Perps Home with Arbitrum already added
    Given the user has the Arbitrum network in their wallet
    And the user is on the Perps Home screen

    When the user taps "Add Funds"
    Then the deposit proceeds without delay
    And no duplicate network addition occurs

  Scenario: User lands on Perps Home without Arbitrum
    Given the user has NOT added the Arbitrum network
    
    When the user navigates to the Perps Home screen
    Then the Arbitrum network is silently added in the background
    And no error is shown if the addition fails

Screenshots/Recordings

N/A — no UI changes, logic-only fix.

Before

N/A

After

N/A

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

Medium Risk
Moves the Arbitrum network precondition into core perps deposit
entrypoints, affecting all deposit flows; failures or timing changes
could impact transaction creation and navigation to confirmations.

Overview
Centralizes Arbitrum network setup for deposits. usePerpsTrading
now calls ensureArbitrumNetworkExists() inside both
depositWithConfirmation and depositWithOrder, so every perps deposit
path enforces the network prerequisite.

Removes redundant pre-checks at call sites and hardens navigation
timing.
Callers like PerpsOrderRedirect, usePerpsHomeActions, and
usePerpsBalanceTokenFilter no longer manually gate on the network
check; PerpsHomeView keeps a best-effort warm-up on focus with an
added .catch() to avoid unhandled rejections, and
PerpsMarketDetailsView triggers navigateToConfirmation inside the
deposit try/catch.

Tests/presets updated for new transitive dependency. Multiple
perps view/hook tests add or adjust mocks for
usePerpsNetworkManagement, add waitFor where async ordering changed,
and the perps state preset now includes an Arbitrum network
configuration to keep view tests stable.

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

[dcf5011](https://github.com/MetaMask/metamask-mobile/commit/dcf50111e2b33a26030f447e483d7564c5ca03fc)

…eck in deposit hooks to prevent missing network errors (#27484)

## **Description**

Ensures the Arbitrum network exists before every perps deposit
transaction, preventing `No network client found for chain` errors when
users haven't added Arbitrum to their wallet.

**Problem:** `ensureArbitrumNetworkExists()` was previously called at
individual call sites (button handlers, redirect screens), making it
easy to miss entry points. Notably, `PerpsOrderRedirect` — reachable
from Token Details without mounting `PerpsHomeView` — had the check
removed, causing deposits to fail when Arbitrum wasn't present.
Additionally, the `useFocusEffect` call in `PerpsHomeView` had no
`.catch()` handler, creating unhandled promise rejections when the
network addition failed.

**Solution:**
1. **Centralized the network check** in `usePerpsTrading` — both
`depositWithConfirmation()` and `depositWithOrder()` now call `await
ensureArbitrumNetworkExists()` before invoking the controller. Every
caller is automatically covered.
2. **Kept a preemptive warm-up** in `PerpsHomeView`'s `useFocusEffect`
with a `.catch()` handler so the network is added before the user taps
deposit, avoiding latency.
3. **Removed redundant checks** from `PerpsOrderRedirect`,
`usePerpsHomeActions` (deposit and withdraw handlers), and
`usePerpsBalanceTokenFilter`.
4. **Updated tests** to mock `usePerpsNetworkManagement` where needed
due to the new transitive dependency.

## **Changelog**

CHANGELOG entry: Fixed a bug where depositing into Perps from Token
Details could fail if the Arbitrum network had not been added to the
wallet

## **Related issues**

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2716
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2715
 
## **Manual testing steps**

```gherkin
Feature: Perps deposit with Arbitrum network guarantee

  Scenario: User deposits from Token Details without Arbitrum in wallet
    Given the user has NOT added the Arbitrum network to their wallet
    And the user is viewing a perps-eligible token on Token Details

    When the user taps the deposit/trade button
    Then the Arbitrum network is automatically added
    And the deposit transaction is created successfully
    And the user is navigated to the confirmation screen

  Scenario: User deposits from Perps Home with Arbitrum already added
    Given the user has the Arbitrum network in their wallet
    And the user is on the Perps Home screen

    When the user taps "Add Funds"
    Then the deposit proceeds without delay
    And no duplicate network addition occurs

  Scenario: User lands on Perps Home without Arbitrum
    Given the user has NOT added the Arbitrum network
    
    When the user navigates to the Perps Home screen
    Then the Arbitrum network is silently added in the background
    And no error is shown if the addition fails
```

## **Screenshots/Recordings**

N/A — no UI changes, logic-only fix.

### **Before**

N/A

### **After**

N/A

## **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]
> **Medium Risk**
> Moves the Arbitrum network precondition into core perps deposit
entrypoints, affecting all deposit flows; failures or timing changes
could impact transaction creation and navigation to confirmations.
> 
> **Overview**
> **Centralizes Arbitrum network setup for deposits.** `usePerpsTrading`
now calls `ensureArbitrumNetworkExists()` inside both
`depositWithConfirmation` and `depositWithOrder`, so every perps deposit
path enforces the network prerequisite.
> 
> **Removes redundant pre-checks at call sites and hardens navigation
timing.** Callers like `PerpsOrderRedirect`, `usePerpsHomeActions`, and
`usePerpsBalanceTokenFilter` no longer manually gate on the network
check; `PerpsHomeView` keeps a *best-effort warm-up* on focus with an
added `.catch()` to avoid unhandled rejections, and
`PerpsMarketDetailsView` triggers `navigateToConfirmation` inside the
deposit try/catch.
> 
> **Tests/presets updated for new transitive dependency.** Multiple
perps view/hook tests add or adjust mocks for
`usePerpsNetworkManagement`, add `waitFor` where async ordering changed,
and the perps state preset now includes an Arbitrum network
configuration to keep view tests stable.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
18ee027. 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 April 1, 2026 08:14
@github-actions

github-actions Bot commented Apr 1, 2026

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-bots Bot team (for MetaMask Bot, Runway Bot, etc.) label Apr 1, 2026
@github-actions github-actions Bot added the size-M label Apr 1, 2026
@chloeYue chloeYue added skip-smart-e2e-selection Skip Smart E2E selection, i.e. select all E2E tests to run and removed size-M labels Apr 1, 2026

@chloeYue chloeYue 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

@github-actions github-actions Bot added the risk-high Extensive testing required · High bug introduction risk label Apr 1, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - skip-smart-e2e-selection label found

All E2E tests pre-selected.

View GitHub Actions results

@sonarqubecloud

sonarqubecloud Bot commented Apr 1, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@chloeYue

chloeYue commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Bypass rules to force merge this cherry-pick as the audit issue will be fixed by: #28237

@chloeYue chloeYue merged commit d396076 into release/7.72.0 Apr 1, 2026
195 of 244 checks passed
@chloeYue chloeYue deleted the runway-cherry-pick-7.72.0-1775031228 branch April 1, 2026 09:24
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 1, 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 skip-smart-e2e-selection Skip Smart E2E selection, i.e. select all E2E tests to run team-bots Bot team (for MetaMask Bot, Runway Bot, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants