feat(predict): add buy with any token flow#27369
Conversation
|
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. |
1d347db to
045750d
Compare
| isShowingToWinSkeleton, | ||
| }: PredictBuyAmountSectionProps) => { | ||
| const tw = useTailwind(); | ||
| const pulseAnim = useRef(new Animated.Value(1)).current; |
| import type { PredictMarket, PredictOutcomeToken } from '../types'; | ||
| import type { PredictEntryPoint } from '../types/navigation'; | ||
|
|
||
| export function parseAnalyticsProperties( |
There was a problem hiding this comment.
Maybe rename to parsePredictBuyAnalyticsProperties
Add PredictBuyWithAnyToken view, components, and hooks for the pay-with-any-token order flow. Includes PredictController, payment token selection, fee summary, order tracking, navigation, active order management, feature flag selectors, and full test coverage.
e3de0fe to
28ae0b0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 4 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| return { | ||
| success: true, | ||
| response: { batchId: PREDICTION_ERROR_TRANSACTION_BATCH_ID }, | ||
| }; |
There was a problem hiding this comment.
User denial returns success instead of indicating cancellation
High Severity
When a user denies the transaction signature in payWithAnyTokenConfirmation, the catch block returns { success: true, response: { batchId: PREDICTION_ERROR_TRANSACTION_BATCH_ID } }. Returning success: true for a user cancellation is misleading — callers treating the result as a successful submission will proceed with order tracking and UI updates for a transaction that never happened. The batchId is set to 'NA', which downstream code may try to track or poll.
| marketType: | ||
| market?.outcomes?.length === 1 | ||
| ? PredictEventValues.MARKET_TYPE.BINARY | ||
| : PredictEventValues.MARKET_TYPE.MULTI_OUTCOME, |
There was a problem hiding this comment.
Market type detection incorrect for binary markets
Medium Severity
The marketType detection uses market?.outcomes?.length === 1 to determine a BINARY market, but binary markets typically have 2 outcomes (Yes/No). A market with exactly 1 outcome is unusual, while a market with 2 outcomes is the standard binary case. Markets with 3+ outcomes are multi-outcome. When market is undefined, the expression evaluates to undefined === 1 which is false, so it defaults to MULTI_OUTCOME — also potentially wrong for the undefined case.
| } | ||
| }, | ||
| [payWithAnyTokenConfirmation, handleDepositError, navigateToConfirmation], | ||
| ); |
There was a problem hiding this comment.
triggerPayWithAnyToken ignores its params argument entirely
Medium Severity
The triggerPayWithAnyToken callback's parameter list is commented out (//(params: PredictPayWithAnyTokenParams) => {) and replaced with () => {. Callers pass { market, outcome, outcomeToken } arguments but they are silently ignored. The route params (market, outcome, outcomeToken, preview) in the commented-out navigateToConfirmation block are also never passed. While marked with a TODO, this means the confirmation screen receives no context about which market/outcome the user is betting on.
| preview, | ||
| placeOrder, | ||
| depositAmount: total - depositFee, | ||
| setIsConfirming, |
There was a problem hiding this comment.
depositAmount calculation may subtract wrong fee component
Medium Severity
The depositAmount is computed as total - depositFee and passed to both usePredictBuyActions (line 158) and PredictPayWithAnyTokenInfo (line 327). If depositFee is undefined (which is possible since usePredictBuyInfo may return it as optional), then total - undefined evaluates to NaN, which would propagate as NaN through the deposit flow and potentially cause incorrect transaction amounts or UI display issues.
Additional Locations (1)
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: Because Predictions is embedded within the Trending tab and affects shared wallet activity/history display, SmokeWalletPlatform must also run. Prediction flows involve on-chain transactions (opening positions, deposits, claims), so SmokeConfirmations is required to validate the confirmation UI and transaction handling integration. No other domains (accounts, networks, snaps, perps, ramps, multi-chain API) were modified. Given the Engine controller changes and broad UI/hook refactors, this is high risk within the Predictions vertical and requires full validation of that flow and its wallet integrations. Performance Test Selection: |
|
✅ E2E Fixture Validation — Schema is up to date |
|





Add PredictBuyWithAnyToken view, components, and hooks for the pay-with-any-token order flow. Includes PredictController, payment token selection, fee summary, order tracking, navigation, active order management, feature flag selectors, and full test coverage.
Description
Adds the "Buy With Any Token" flow to prediction markets, enabling users to place bets using any token in their wallet (not just their predict balance). When a user doesn't have sufficient USDC.e balance on Polygon, this flow handles the deposit + order as a single transaction batch through the confirmations framework.
This is PR 1 of 2 — contains only
@MetaMask/predict-owned code. A follow-up PR will add the confirmations integration (registering the newpredictDepositAndOrdertransaction type, pay-with-modal changes, and navigation support).What's included
New view —
PredictBuyWithAnyTokenFull buy preview screen with amount input, fee summary, action button, and payment token selection. Renders both standalone (predict routes) and within confirmations (as info-root content).
PredictController state extensions
activeOrder— tracks order lifecycle (preview → confirming → success/error)selectedPaymentToken— stores the user's chosen payment tokenNew hooks (13)
usePredictActiveOrderusePredictNavigationusePredictPayWithAnyTokenusePredictPaymentTokenusePredictBalanceTokenFilterusePredictBuyPreviewActionsusePredictBuyConditionsusePredictBuyInfousePredictBuyInputStateusePredictBuyAvailableBalanceusePredictBuyBackSwipeusePredictOrderTrackingusePredictPayWithAnyTokenTrackingNew components (8): PredictBuyActionButton, PredictBuyAmountSection, PredictBuyBottomContent, PredictBuyMinimumError, PredictBuyPreviewHeader, PredictFeeSummary, PredictPayWithRow, PredictPayWithAnyTokenInfo
Feature flag selectors:
selectPredictFakOrdersEnabledFlag,selectPredictWithAnyTokenEnabledFlag— gated behind remotepredictWithAnyTokenflag.Other changes:
Changelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
High Risk
Adds a new deposit+order transaction-batching path (
payWithAnyTokenConfirmation) and new controller state for active orders/payment-token selection, which affects confirmation routing and transaction submission. Although gated by a remote flag, mistakes could break Predict order placement/deposit flows or create incorrect confirmation behavior.Overview
Introduces a new Buy With Any Token Predict buy-preview flow, gated by the remote
predictWithAnyTokenflag, and wires Predict routing to swapBUY_PREVIEWbetween the legacy screen and the newPredictBuyWithAnyTokenview.Extends
PredictControllerwith ephemeralactiveOrderandselectedPaymentTokenstate plus setters, and addspayWithAnyTokenConfirmation()to submit a deposit transaction batch that re-tagspredictDeposittxs aspredictDepositAndOrderto drive a new confirmation/info experience.Adds supporting hooks/utilities for navigation (
usePredictNavigation), active order and token selection (usePredictActiveOrder,usePredictPaymentToken,usePredictBalanceTokenFilter), order preview initialization (initialPreview), and shared error/toast + analytics helpers; updates buy UI components to reflect the new fee summary/deposit-fee row and improved deposit-in-progress handling. Test coverage is expanded broadly across the new hooks, selectors, navigation, and controller behavior.Written by Cursor Bugbot for commit 7f6706f. This will update automatically on new commits. Configure here.