Skip to content

chore(runway): cherry-pick fix(perps): extract payment token init into useInitPerpsPaymentToken hook and move it to the parent cp-7.73.0#28579

Merged
chloeYue merged 2 commits intorelease/7.73.0from
runway-cherry-pick-7.73.0-1775689127
Apr 9, 2026
Merged

chore(runway): cherry-pick fix(perps): extract payment token init into useInitPerpsPaymentToken hook and move it to the parent cp-7.73.0#28579
chloeYue merged 2 commits intorelease/7.73.0from
runway-cherry-pick-7.73.0-1775689127

Conversation

@runway-github
Copy link
Copy Markdown
Contributor

@runway-github runway-github bot commented Apr 8, 2026

Description

The PerpsPayRow component contained ~110 lines of payment token
initialization logic (pending config syncing, default token selection,
asset-change resets) mixed in with its rendering concerns. This made the
component harder to follow and impossible to unit-test the
initialization behavior in isolation.

This PR extracts that logic into a dedicated useInitPerpsPaymentToken
hook and calls it from PerpsOrderViewContentBase instead. The hook
encapsulates:

  • Syncing the pay token from pendingTradeConfiguration when resuming
    an order
  • Falling back to the highest-balance allowlist token when the user has
    no perps balance
  • Resetting state when the traded asset changes
  • Cleaning up the controller's selected payment token on unmount

A key prop keyed on payToken.symbol was also added to the
PerpsSlider so it recomputes width when the payment token changes,
keeping the slider range in sync, allowing the user to use the slider

Changelog

CHANGELOG entry: null

Related issues

Fixes: #28539

Manual testing steps

Feature: Perps payment token initialization

  Scenario: user opens a perps order with some perps balance and other tokens
    Given the user selects USDC on Arbitrum
    When user navigates changes the amount to a different amount
    Then the USDC on Arbitrum should be still selected
    And user should be able to use slider if they have enough balance to cover the trade

Screenshots/Recordings

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
Touches Perps payment-token selection/init logic and its interaction
with PerpsController/confirmation pay-token state, which could affect
default token selection and persisted pending configs if incorrect.

Overview
Moves Perps “pay with” token initialization/sync logic out of
PerpsPayRow into a new useInitPerpsPaymentToken hook, and runs it
from PerpsOrderView so pending trade config, default-token fallback,
asset-change resets, and unmount cleanup are handled at the screen
level.

Simplifies PerpsPayRow to be a pure display/navigation row (dropping
the initialAsset prop) and updates tests accordingly, while adding
focused unit tests for useInitPerpsPaymentToken.

Adds a key to PerpsSlider based on payToken.symbol to force a
re-mount when the payment token changes, keeping the slider’s
range/width in sync.

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

[ccf1e6c](https://github.com/MetaMask/metamask-mobile/commit/ccf1e6c6199b86245612b2495234fb3f15574750)

…o useInitPerpsPaymentToken hook and move it to the parent cp-7.73.0 (#28545)

## **Description**

The `PerpsPayRow` component contained ~110 lines of payment token
initialization logic (pending config syncing, default token selection,
asset-change resets) mixed in with its rendering concerns. This made the
component harder to follow and impossible to unit-test the
initialization behavior in isolation.

This PR extracts that logic into a dedicated `useInitPerpsPaymentToken`
hook and calls it from `PerpsOrderViewContentBase` instead. The hook
encapsulates:
- Syncing the pay token from `pendingTradeConfiguration` when resuming
an order
- Falling back to the highest-balance allowlist token when the user has
no perps balance
- Resetting state when the traded asset changes
- Cleaning up the controller's selected payment token on unmount

A `key` prop keyed on `payToken.symbol` was also added to the
`PerpsSlider` so it recomputes width when the payment token changes,
keeping the slider range in sync, allowing the user to use the slider

## **Changelog**

CHANGELOG entry: null

## **Related issues**

Fixes: #28539

## **Manual testing steps**

```gherkin
Feature: Perps payment token initialization

  Scenario: user opens a perps order with some perps balance and other tokens
    Given the user selects USDC on Arbitrum
    When user navigates changes the amount to a different amount
    Then the USDC on Arbitrum should be still selected
    And user should be able to use slider if they have enough balance to cover the trade
```

## **Screenshots/Recordings**

### **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**
> Touches Perps payment-token selection/init logic and its interaction
with `PerpsController`/confirmation pay-token state, which could affect
default token selection and persisted pending configs if incorrect.
> 
> **Overview**
> Moves Perps “pay with” token initialization/sync logic out of
`PerpsPayRow` into a new `useInitPerpsPaymentToken` hook, and runs it
from `PerpsOrderView` so pending trade config, default-token fallback,
asset-change resets, and unmount cleanup are handled at the screen
level.
> 
> Simplifies `PerpsPayRow` to be a pure display/navigation row (dropping
the `initialAsset` prop) and updates tests accordingly, while adding
focused unit tests for `useInitPerpsPaymentToken`.
> 
> Adds a `key` to `PerpsSlider` based on `payToken.symbol` to force a
re-mount when the payment token changes, keeping the slider’s
range/width in sync.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d3a7d10. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@runway-github runway-github bot requested a review from a team as a code owner April 8, 2026 22:58
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

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 8, 2026
@github-actions github-actions bot added size-L risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 8, 2026
Copy link
Copy Markdown
Contributor

@chloeYue chloeYue left a comment

Choose a reason for hiding this comment

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

LGTM

@chloeYue chloeYue added skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. skip-smart-e2e-selection Skip Smart E2E selection, i.e. select all E2E tests to run labels Apr 9, 2026
@github-actions github-actions bot added risk-high Extensive testing required · High bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 9, 2026
@github-actions github-actions bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

🔍 Smart E2E Test Selection

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

All E2E tests pre-selected.

View GitHub Actions results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

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

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 9, 2026

@chloeYue chloeYue merged commit d6c3b9a into release/7.73.0 Apr 9, 2026
185 of 190 checks passed
@chloeYue chloeYue deleted the runway-cherry-pick-7.73.0-1775689127 branch April 9, 2026 09:57
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 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-L skip-smart-e2e-selection Skip Smart E2E selection, i.e. select all E2E tests to run skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. 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