Skip to content

refactor(predict): move deposit amount to PredictPayWithAnyTokenInfo cp-7.73.0 #28396

Merged
caieu merged 5 commits into
mainfrom
predict/mm-pay-deposit-amount
Apr 6, 2026
Merged

refactor(predict): move deposit amount to PredictPayWithAnyTokenInfo cp-7.73.0 #28396
caieu merged 5 commits into
mainfrom
predict/mm-pay-deposit-amount

Conversation

@caieu

@caieu caieu commented Apr 4, 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 amountHumanupdateTokenAmountCallback 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.

caieu added 5 commits April 3, 2026 14:32
depositAmount was only consumed by PredictPayWithAnyTokenInfo, so the
component should own its computation. This reduces the shared hook's
surface area and makes the data flow more explicit.
Remove normalizeQuoteComparableAddress, isPaymentTokenRequired, and
isQuotesStale logic from usePredictBuyConditions, simplifying
isPayFeesLoading to only check controller loading states. Move
useTransactionCustomAmount call earlier in PredictPayWithAnyTokenInfo
for consistent hook ordering.
@github-actions

github-actions Bot commented Apr 4, 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-predict Predict team label Apr 4, 2026
@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - draft PR

All E2E tests pre-selected.

View GitHub Actions results

@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

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

@sonarqubecloud

sonarqubecloud Bot commented Apr 4, 2026

Copy link
Copy Markdown

@caieu caieu marked this pull request as ready for review April 6, 2026 11:04
@caieu caieu requested a review from a team as a code owner April 6, 2026 11:04

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5526d80. Configure here.

@caieu caieu changed the title refactor(predict): move deposit amount computation to PredictPayWithAnyTokenInfo and gate on input focus refactor(predict): move deposit amount to PredictPayWithAnyTokenInfo Apr 6, 2026
@caieu caieu changed the title refactor(predict): move deposit amount to PredictPayWithAnyTokenInfo refactor(predict): move deposit amount to PredictPayWithAnyTokenInfo cp-7.73.0 Apr 6, 2026
@caieu caieu added this pull request to the merge queue Apr 6, 2026
Merged via the queue into main with commit 11fc440 Apr 6, 2026
141 of 142 checks passed
@caieu caieu deleted the predict/mm-pay-deposit-amount branch April 6, 2026 15:41
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 6, 2026
@metamaskbot metamaskbot added the release-7.74.0 Issue or pull request that will be included in release 7.74.0 label Apr 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.74.0 Issue or pull request that will be included in release 7.74.0 size-XL team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Predict with any token uses incorrect quote when placing bet

3 participants