Skip to content

feat(predict): add crypto price data plumbing#30004

Merged
ghgoodreau merged 26 commits into
mainfrom
predict/crypto-data-plumbing
May 18, 2026
Merged

feat(predict): add crypto price data plumbing#30004
ghgoodreau merged 26 commits into
mainfrom
predict/crypto-data-plumbing

Conversation

@ghgoodreau

@ghgoodreau ghgoodreau commented May 11, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds the data plumbing for Predict crypto up/down markets. It wires crypto price history and target-price queries through the Predict controller/provider layer, adds live crypto price subscription handling, and includes trace and cleanup coverage for WebSocket behavior.

This slice also keeps existing v1 order preview fee behavior intact while adding the v2 CLOB plumbing needed by the crypto up/down flow. Because this slice triggers the Predict smoke suite, it includes the wallet page-object tap stabilization needed for the existing Predictions section E2E path.

TODO

  1. This PR is stack item 2/3 and builds on feat(predict): update liveline chart foundation #30003, which should merge first.
  2. Keep this PR as draft until the stacked PRs are validated and all required checks are passing.

Changelog

CHANGELOG entry: null

Related issues

Fixes: N/A - stacked Predict crypto up/down implementation split from #29436.

Manual testing steps

Feature: Crypto up/down data plumbing

  Scenario: app loads crypto market data
    Given the Predict feature is enabled and crypto up/down markets are available

    When user opens a crypto up/down market detail screen
    Then the app can request target price, price history, and live price updates without provider errors

Screenshots/Recordings

Before

N/A

After

N/A

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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
Introduces new crypto price-history API plumbing plus live RTDS websocket tracing/buffering changes, which could impact Predict data-fetch reliability and realtime updates. Adds v2 CLOB endpoint selection for previews, which may affect order preview behavior if misconfigured.

Overview
Adds end-to-end support for crypto up/down price data in Predict: a new getCryptoPriceHistory path (types, controller action, provider fetch to a dedicated endpoint, react-query cryptoPriceHistory query) plus updated error/trace instrumentation and test coverage.

Introduces useCryptoUpDownChartData to merge historical price history with live RTDS websocket updates, including market-change resets, end-date “freeze” handling, and target-price fallback seeding when history is missing.

Refactors useLiveCryptoPrices to subscribe per-symbol and push updates via callback (instead of maintaining an internal prices map), and hardens RTDS handling in WebSocketManager (subscribe/unsubscribe semantics, buffered flush tracing, and isolating subscriber errors).

Extends Polymarket utils to support v2 CLOB base URLs and a 4h series recurrence inference, and tightens numeric validation in crypto target price + currency formatting; also stabilizes Predictions section E2E scroll/tap behavior.

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

ghgoodreau and others added 2 commits May 11, 2026 14:56
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@ghgoodreau ghgoodreau self-assigned this May 11, 2026
@github-actions

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.

@metamaskbotv2 metamaskbotv2 Bot added the team-swaps-and-bridge Swaps and Bridge team label May 11, 2026
@ghgoodreau ghgoodreau added team-predict Predict team and removed team-swaps-and-bridge Swaps and Bridge team size-XL labels May 11, 2026
@ghgoodreau ghgoodreau marked this pull request as ready for review May 11, 2026 20:16
@ghgoodreau ghgoodreau requested a review from a team as a code owner May 11, 2026 20:16
Co-authored-by: Cursor <cursoragent@cursor.com>
@ghgoodreau ghgoodreau requested a review from a team as a code owner May 11, 2026 20:37
Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread app/components/UI/Predict/hooks/useCryptoUpDownChartData.ts
Comment thread app/components/UI/Predict/utils/cryptoUpDown.ts Outdated
Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread app/components/UI/Predict/hooks/useCryptoUpDownChartData.ts
Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread app/components/UI/Predict/controllers/PredictController.test.ts
ghgoodreau and others added 2 commits May 11, 2026 16:39
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Fixture update started. Running workflow from branch predict/crypto-data-plumbing. View workflow runs

@github-actions

Copy link
Copy Markdown
Contributor

E2E fixture update failed.\n\nCommon causes:\n- CI workflow is still running — wait for 'Build iOS Apps' to complete\n- CI workflow was skipped — ensure your PR has iOS-impacting changes or use skip-smart-e2e-selection label\n- iOS build failed — check the CI workflow for errors\n\nView logs and retry

@ghgoodreau

Copy link
Copy Markdown
Contributor Author

@metamaskbot update-mobile-fixture

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Fixture update started. Running workflow from branch predict/crypto-data-plumbing. View workflow runs

@github-actions

Copy link
Copy Markdown
Contributor

E2E fixture update failed.\n\nCommon causes:\n- CI workflow is still running — wait for 'Build iOS Apps' to complete\n- CI workflow was skipped — ensure your PR has iOS-impacting changes or use skip-smart-e2e-selection label\n- iOS build failed — check the CI workflow for errors\n\nView logs and retry

matallui
matallui previously approved these changes May 15, 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 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 1d19a68. Configure here.

Comment thread app/components/UI/Predict/hooks/useCryptoUpDownChartData.ts
matallui
matallui previously approved these changes May 18, 2026
@matallui matallui enabled auto-merge May 18, 2026 14:17
@matallui matallui disabled auto-merge May 18, 2026 14:17
Comment thread tests/api-mocking/MockServerE2E.ts Outdated

@christopherferreira9 christopherferreira9 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.

tiny comment

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
All 27 changed files are focused on the Predictions/Polymarket feature area with no changes to shared wallet infrastructure (navigation, confirmations UI, account management, etc.).

Key changes:

  1. PredictController.ts (CRITICAL): New getCryptoPriceHistory method added and exposed via messenger. Price validation logic fixed (null check → typeof price === 'number' && price > 0). This is a behavioral change that could affect existing prediction market flows.
  2. PredictController-method-action-types.ts (CRITICAL): New action type for getCryptoPriceHistory.
  3. PolymarketProvider.ts: New getCryptoPriceHistory API endpoint implementation. Also fixed getCryptoTargetPrice to reject zero/negative prices.
  4. WebSocketManager.ts: Fixed RTDS unsubscribe logic (moved sendRtdsUnsubscribe to fire only when ALL subscriptions are gone, not per-subscription), added tracing, added error handling for callbacks.
  5. useLiveCryptoPrices.ts: Refactored from multi-symbol to single-symbol callback-based hook.
  6. useCryptoUpDownChartData.ts: New hook combining historical and live price data for crypto up/down charts.
  7. cryptoPriceHistory.ts: New React Query for fetching crypto price history.
  8. cryptoUpDown.ts: New utility functions for crypto symbol mapping, variant mapping, duration mapping.
  9. trace.ts: Additive - new trace names only.
  10. WalletView.ts (CRITICAL page object): Fixed scrollAndTapPredictionsSection to try both scroll directions with fallback - this is a test infrastructure fix that improves test reliability.

Tag selection rationale:

  • SmokePredictions: Primary tag - all changes are in the Predictions/Polymarket feature. The WebSocket unsubscribe fix and price validation changes could affect existing prediction flows.
  • SmokeWalletPlatform: Required by SmokePredictions tag description: "Predictions is also a section inside the Trending tab (SmokeWalletPlatform); changes to Predictions views affect Trending. When selecting SmokePredictions, also select SmokeWalletPlatform."
  • SmokeConfirmations: Required by SmokePredictions tag description: "opening/closing positions are on-chain transactions. When selecting SmokePredictions, also select SmokeConfirmations."

The WalletView.ts page object fix (scroll direction fallback) directly improves test reliability for Predictions section navigation, making SmokePredictions tests more stable.

Performance Test Selection:
The changes include a new useCryptoUpDownChartData hook that combines real-time WebSocket data with historical price data for chart rendering, and a refactored useLiveCryptoPrices hook. These changes involve real-time data processing, chart data merging, and state management that could impact prediction market rendering performance. @PerformancePredict covers prediction market list loading, market details, deposit flows, and balance display - directly relevant to these changes.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@ghgoodreau ghgoodreau added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit 85b8b30 May 18, 2026
267 of 278 checks passed
@ghgoodreau ghgoodreau deleted the predict/crypto-data-plumbing branch May 18, 2026 19:05
@github-actions github-actions Bot locked and limited conversation to collaborators May 18, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.79.0 Issue or pull request that will be included in release 7.79.0 label May 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants