Skip to content

fix(predict): improve Predict buy-with-any-token UX from UAT issues cp-7.73.0#28302

Merged
caieu merged 16 commits into
mainfrom
predict/uat-fixes
Apr 3, 2026
Merged

fix(predict): improve Predict buy-with-any-token UX from UAT issues cp-7.73.0#28302
caieu merged 16 commits into
mainfrom
predict/uat-fixes

Conversation

@caieu

@caieu caieu commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Description

Addresses several UAT issues in the Predict buy-with-any-token flow:

  • Auto-select best payment token: New usePredictDefaultPaymentToken hook auto-selects the token with the highest fiat balance when Predict balance is below MINIMUM_BET ($1), instead of requiring manual selection. Resets to Predict balance when sufficient.
  • Optimistic positions on deposit: Creates optimistic positions from the order preview at deposit time so the position appears immediately in the portfolio while the deposit confirms. Clears optimistic positions on failure (both direct order failures and failed deposit-and-order transactions).
  • Navigate back on deposit: Navigate back when the deposit-and-order flow begins, so the user isn't stuck on the buy form.
  • Keep token selection always enabled: Removes the canSelectToken gate — the pay-with-token row is now always interactive (disabled only while placing an order).
  • "Predict balance first" hint: Shows "Your Predict balance will be used first" below the pay-with row when an external token is selected, so users understand the payment order.
  • Deposit amount guards: depositAmount now returns 0 when the preview is unavailable or the bet is below minimum, preventing premature deposit calculations and stale values from triggering the deposit flow.
  • Updated insufficient funds messaging: Error messages now suggest trying a different token when funds are insufficient.
  • Fix text overflow on Polymarket terms: Nests the "learn more" link inside the disclaimer text and adds horizontal padding to prevent overflow.
  • Fix premature payment token reset: Adds a totalPayForPredictBalance > 0 guard so the auto-reset effect only fires when there is an actual bet amount, preventing the selected token from being cleared immediately after selection.
  • Depositing toast notification: Shows a "Prediction in progress" toast with spinner when the deposit phase begins and invalidates position queries to reflect the optimistic position.

Changelog

CHANGELOG entry: null

Related issues

Fixes:

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

https://www.loom.com/share/c25681fd77a444e496f999a23a55b0e6

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
Updates buy-with-any-token order state transitions, optimistic position caching, and navigation/toast behavior; mistakes could cause incorrect UI state or stale/phantom positions during deposit/order failures.

Overview
Improves the buy-with-any-token flow by introducing a new order event status depositing and publishing it when the flow transitions into the deposit phase, with a matching “Prediction in progress” toast and positions query invalidation.

Adds preview-based optimistic positions during deposit via PolymarketProvider.createOptimisticPositionFromPreview, and ensures cleanup via clearOptimisticPosition when placeOrder fails or when a depositAndOrder transaction fails.

Refines buy screen UX: auto-selects a default payment token when Predict balance is below MINIMUM_BET (new usePredictDefaultPaymentToken), removes the canSelectToken gate (row only disabled while placing), navigates back when entering DEPOSITING, adds a “Predict balance will be used first” hint, guards deposit amount calculation until fees/minimum bet are available, and updates insufficient-funds copy to suggest trying another token; also adjusts the Polymarket TOS disclaimer layout to prevent overflow.

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

caieu added 7 commits April 1, 2026 11:30
The auto-reset effect in usePredictBuyConditions was resetting the
selected external payment token immediately after selection because
the condition `predictBalance >= totalPayForPredictBalance` is trivially
true when totalPayForPredictBalance is 0 (no bet entered). This caused
the available balance to flash the combined amount then revert to the
Predict-only balance.
Add a `totalPayForPredictBalance > 0` guard so the sufficiency check
only runs when there is an actual bet amount to evaluate.
Move payment token initialization from usePredictBuyActions transitionEnd
listener into a dedicated usePredictDefaultPaymentToken hook owned by
PredictPayWithRow. When predict balance is below MINIMUM_BET ($1), the
hook auto-selects the user's token with the highest fiat balance; otherwise
it resets to Predict balance. The hook gates on activeOrder reaching PREVIEW
state to ensure initPayWithAnyToken has completed before selecting.
@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-predict Predict team label Apr 1, 2026
caieu added 5 commits April 2, 2026 11:50
depositAmount no longer subtracts predictBalance — it is now always
currentValue + providerFee + metamaskFee, rounded up to 2 decimals.
Updates tests to reflect the new calculation and removes predictBalance
dependency from the depositAmount memo.
@matallui matallui changed the title fix(predict): improve Predict buy-with-any-token UX from UAT issues fix(predict): improve Predict buy-with-any-token UX from UAT issues cp-7.73.0 Apr 2, 2026
@caieu caieu marked this pull request as ready for review April 2, 2026 20:32
@caieu caieu requested a review from a team as a code owner April 2, 2026 20:32
Comment thread app/components/UI/Predict/views/PredictBuyWithAnyToken/hooks/usePredictBuyInfo.ts Outdated
@github-actions github-actions Bot added the risk-medium Moderate testing recommended · Possible bug introduction risk label Apr 2, 2026

@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 3 potential issues.

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.

@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 2, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 2, 2026
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePredictions, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePredict
  • Risk Level: medium
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
All 23 changed files are exclusively within the Predict/Polymarket feature area (app/components/UI/Predict/) plus locales/en.json. The changes focus on:

  1. PredictController.ts (CRITICAL): Added 'depositing' transaction status, optimistic position creation during deposit phase, and cleanup logic. This is a controller-level change affecting transaction state management.

  2. PolymarketProvider.ts: New methods for optimistic position management (createOptimisticPositionFromPreview, clearOptimisticPosition).

  3. usePredictToastRegistrations.tsx: New 'depositing' status handling with toast notifications and query invalidation.

  4. PredictBuyWithAnyToken flow: Multiple hooks updated - usePredictBuyConditions (removed canSelectToken, fixed auto-reset), usePredictBuyActions (navigation pop on DEPOSITING state), usePredictBuyInfo (deposit amount calculation fix), usePredictBuyError (new error messages for token suggestions), usePredictDefaultPaymentToken (new hook for smart token selection).

  5. PredictPayWithRow.tsx: UI changes including new "Predict balance will be used first" info text and layout improvements.

  6. locales/en.json: New string keys for new UI states.

Tag Selection Rationale:

  • SmokePredictions: Primary tag - all changes are in the Predictions/Polymarket feature. The buy flow, payment token selection, optimistic positions, and transaction status changes directly affect prediction market position opening flows tested by this tag.
  • SmokeWalletPlatform: Required per SmokePredictions tag description - "Predictions is also a section inside the Trending tab (SmokeWalletPlatform); changes to Predictions views affect Trending."
  • SmokeConfirmations: Required per SmokePredictions tag description - "opening/closing positions are on-chain transactions" and the buy-with-any-token flow involves transaction confirmations. The DEPOSITING state navigation changes directly affect the confirmation flow.

No other tags are warranted as changes are isolated to the Predict feature with no impact on accounts, networks, swaps, snaps, or other wallet features.

Performance Test Selection:
The PredictController changes introduce optimistic position creation during the deposit phase, which involves async API calls (getPositions, createOrUpdateOptimisticPosition) and query invalidation (queryClient.invalidateQueries). The new usePredictDefaultPaymentToken hook also adds token balance loading on mount. These changes could affect the responsiveness of the Predict buy flow and position display. @PerformancePredict covers prediction market list loading, position management, deposit flows, and balance display - all directly impacted by these changes.

View GitHub Actions results

@github-actions

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

Copy link
Copy Markdown

@caieu caieu added this pull request to the merge queue Apr 3, 2026
Merged via the queue into main with commit fda751e Apr 3, 2026
100 of 101 checks passed
@caieu caieu deleted the predict/uat-fixes branch April 3, 2026 02:05
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 3, 2026
@weitingsun weitingsun added release-7.74.0 Issue or pull request that will be included in release 7.74.0 and removed release-99999.1.0 labels Apr 3, 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 risk-medium Moderate testing recommended · Possible bug introduction risk size-XL team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants