fix(predict): improve Predict buy-with-any-token UX from UAT issues cp-7.73.0#28302
Conversation
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.
|
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. |
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Tag Selection Rationale:
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: |
|
✅ E2E Fixture Validation — Schema is up to date |
|




Description
Addresses several UAT issues in the Predict buy-with-any-token flow:
usePredictDefaultPaymentTokenhook 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.canSelectTokengate — the pay-with-token row is now always interactive (disabled only while placing an order).depositAmountnow 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.totalPayForPredictBalance > 0guard so the auto-reset effect only fires when there is an actual bet amount, preventing the selected token from being cleared immediately after selection.Changelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
https://www.loom.com/share/c25681fd77a444e496f999a23a55b0e6
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
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
orderevent statusdepositingand 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 viaclearOptimisticPositionwhenplaceOrderfails or when adepositAndOrdertransaction fails.Refines buy screen UX: auto-selects a default payment token when Predict balance is below
MINIMUM_BET(newusePredictDefaultPaymentToken), removes thecanSelectTokengate (row only disabled while placing), navigates back when enteringDEPOSITING, 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.