Skip to content

chore(runway): cherry-pick refactor(predict): move deposit amount to PredictPayWithAnyTokenInfo cp-7.73.0#28416

Merged
chloeYue merged 1 commit into
release/7.73.0from
runway-cherry-pick-7.73.0-1775490300
Apr 7, 2026
Merged

chore(runway): cherry-pick refactor(predict): move deposit amount to PredictPayWithAnyTokenInfo cp-7.73.0#28416
chloeYue merged 1 commit into
release/7.73.0from
runway-cherry-pick-7.73.0-1775490300

Conversation

@runway-github

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

Copy link
Copy Markdown
Contributor

Description

This PR refactors the deposit amount flow in the Predict
buy-with-any-token feature to improve correctness, reduce redundant
re-computations, and align the token amount update pattern with Perps.

What changed:

  • Moved depositAmount computation from usePredictBuyInfo into
    PredictPayWithAnyTokenInfo, co-locating the calculation with the
    component that consumes it. This eliminates an unnecessary prop hop and
    keeps the headless component self-contained.
  • Gated deposit amount updates on input focus — deposit amount is
    only committed when the user finishes editing (input blur), preventing
    redundant effect runs and state churn while the user is actively typing.
  • Removed isQuotesStale logic from usePredictBuyConditions
    this workaround for TransactionPayController timing gaps is no longer
    needed, simplifying the pay fees loading derivation.
  • Added EngineService.flushState() after deposit amount, token
    amount, and pay token mutations to ensure immediate state consistency
    for the deposit-and-order batch flow.
  • Aligned token amount callback with amountHuman
    updateTokenAmountCallback now passes the fiat-converted amountHuman
    from useTransactionCustomAmount instead of the rounded deposit amount,
    matching the Perps pattern.

Files changed (8):

| File | Change |
| ------------------------------------- |

|
| PredictPayWithAnyTokenInfo.tsx | Major — owns deposit amount
computation, input focus gating, state flush |
| PredictPayWithAnyTokenInfo.test.tsx | Major — new test sections for
computation, gating, dedup behavior |
| PredictBuyWithAnyToken.tsx | Minor — passes currentValue,
preview, isInputFocused instead of depositAmount |
| PredictBuyWithAnyToken.test.tsx | Minor — updated mock interface |
| usePredictBuyInfo.ts | Minor — removed depositAmount return,
removed usePredictBalance and MINIMUM_BET imports |
| usePredictBuyInfo.test.ts | Minor — removed depositAmount tests
and related mocks |
| usePredictBuyConditions.ts | Moderate — removed isQuotesStale,
simplified isPayFeesLoading |
| usePredictBuyConditions.test.ts | Moderate — removed isQuotesStale
tests and getNativeTokenAddress mock |

Changelog

CHANGELOG entry: null

Related issues

Fixes: #28413

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

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

Medium Risk
Touches Predict buy payment/deposit amount propagation into the
confirmations flow, including new state-flush behavior; mistakes could
cause incorrect amounts or extra state churn during order placement.

Overview
Refactors the Predict buy-with-any-token flow so
PredictPayWithAnyTokenInfo owns deposit amount calculation and
propagation
(based on currentValue, preview fees, and
usePredictBalance) and only commits updates when the amount input is
not focused.

Removes depositAmount from usePredictBuyInfo and updates the
screen/component wiring accordingly;
updatePendingAmount/updateTokenAmount now de-dupe repeated
emissions, use amountHuman for token updates, and call
EngineService.flushState() after mutating confirmation/payment state.

Simplifies pay-fee loading in usePredictBuyConditions by dropping
the isQuotesStale workaround and associated native-token normalization
logic, with tests updated/expanded to cover the new deposit gating and
rounding behavior.

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

[11fc440](https://github.com/MetaMask/metamask-mobile/commit/11fc4409d49f4400c3eab53b1b3eedee29e555e9)

…PredictPayWithAnyTokenInfo cp-7.73.0 (#28396)

<!--
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 refactors the deposit amount flow in the Predict
buy-with-any-token feature to improve correctness, reduce redundant
re-computations, and align the token amount update pattern with Perps.

**What changed:**

- **Moved `depositAmount` computation** from `usePredictBuyInfo` into
`PredictPayWithAnyTokenInfo`, co-locating the calculation with the
component that consumes it. This eliminates an unnecessary prop hop and
keeps the headless component self-contained.
- **Gated deposit amount updates on input focus** — deposit amount is
only committed when the user finishes editing (input blur), preventing
redundant effect runs and state churn while the user is actively typing.
- **Removed `isQuotesStale` logic** from `usePredictBuyConditions` —
this workaround for `TransactionPayController` timing gaps is no longer
needed, simplifying the pay fees loading derivation.
- **Added `EngineService.flushState()`** after deposit amount, token
amount, and pay token mutations to ensure immediate state consistency
for the deposit-and-order batch flow.
- **Aligned token amount callback with `amountHuman`** —
`updateTokenAmountCallback` now passes the fiat-converted `amountHuman`
from `useTransactionCustomAmount` instead of the rounded deposit amount,
matching the Perps pattern.

**Files changed (8):**

| File | Change |
| ------------------------------------- |
---------------------------------------------------------------------------------------------
|
| `PredictPayWithAnyTokenInfo.tsx` | Major — owns deposit amount
computation, input focus gating, state flush |
| `PredictPayWithAnyTokenInfo.test.tsx` | Major — new test sections for
computation, gating, dedup behavior |
| `PredictBuyWithAnyToken.tsx` | Minor — passes `currentValue`,
`preview`, `isInputFocused` instead of `depositAmount` |
| `PredictBuyWithAnyToken.test.tsx` | Minor — updated mock interface |
| `usePredictBuyInfo.ts` | Minor — removed `depositAmount` return,
removed `usePredictBalance` and `MINIMUM_BET` imports |
| `usePredictBuyInfo.test.ts` | Minor — removed `depositAmount` tests
and related mocks |
| `usePredictBuyConditions.ts` | Moderate — removed `isQuotesStale`,
simplified `isPayFeesLoading` |
| `usePredictBuyConditions.test.ts` | Moderate — removed `isQuotesStale`
tests and `getNativeTokenAddress` mock |


<!--
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: null

## **Related issues**

Fixes: #28413

## **Manual testing steps**

```gherkin
Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]
```

## **Screenshots/Recordings**

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

### **Before**

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

### **After**

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

## **Pre-merge author checklist**

- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I've included tests if applicable
- [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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 Predict buy payment/deposit amount propagation into the
confirmations flow, including new state-flush behavior; mistakes could
cause incorrect amounts or extra state churn during order placement.
> 
> **Overview**
> Refactors the Predict buy-with-any-token flow so
`PredictPayWithAnyTokenInfo` owns **deposit amount calculation and
propagation** (based on `currentValue`, `preview` fees, and
`usePredictBalance`) and only commits updates when the amount input is
*not focused*.
> 
> Removes `depositAmount` from `usePredictBuyInfo` and updates the
screen/component wiring accordingly;
`updatePendingAmount`/`updateTokenAmount` now de-dupe repeated
emissions, use `amountHuman` for token updates, and call
`EngineService.flushState()` after mutating confirmation/payment state.
> 
> Simplifies pay-fee loading in `usePredictBuyConditions` by dropping
the `isQuotesStale` workaround and associated native-token normalization
logic, with tests updated/expanded to cover the new deposit gating and
rounding behavior.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
5526d80. 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 6, 2026 15:45
@github-actions

github-actions Bot commented Apr 6, 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 6, 2026
@github-actions github-actions Bot added size-XL risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 6, 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

@chloeYue chloeYue added the skip-smart-e2e-selection Skip Smart E2E selection, i.e. select all E2E tests to run label Apr 7, 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 7, 2026
@github-actions

github-actions Bot commented Apr 7, 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

@github-actions

github-actions Bot commented Apr 7, 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

@sonarqubecloud

sonarqubecloud Bot commented Apr 7, 2026

Copy link
Copy Markdown

@chloeYue

chloeYue commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

force merge this PR as the audit issue will be fixed by #28459

@chloeYue chloeYue merged commit 72fd0f3 into release/7.73.0 Apr 7, 2026
573 of 640 checks passed
@chloeYue chloeYue deleted the runway-cherry-pick-7.73.0-1775490300 branch April 7, 2026 14:31
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 7, 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 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