Skip to content

fix(predict): improve crypto up/down cp-7.79.0#30662

Merged
ghgoodreau merged 8 commits into
mainfrom
predict/updown-improvements
May 27, 2026
Merged

fix(predict): improve crypto up/down cp-7.79.0#30662
ghgoodreau merged 8 commits into
mainfrom
predict/updown-improvements

Conversation

@ghgoodreau

@ghgoodreau ghgoodreau commented May 26, 2026

Copy link
Copy Markdown
Contributor

Description

Improves the crypto up/down market experience on the feed series card and market details screen.

These changes are scoped to the existing crypto up/down work behind the Predict up/down feature flag. They improve release quality for the upcoming crypto up/down experience, where the current UX is unstable for users, with minimal regression risk outside the gated feature.

This PR fixes several visible stability issues:

  • Prevents Up/Down CTA prices from briefly flickering to stale fallback prices while live CLOB price subscriptions remount or warm back up.
  • Uses a shared buy-price precedence for CTA labels: live WebSocket bestAsk → REST entry.buy → static market token price.
  • Keeps the details chart anchored to the currently live market so selecting a future time slot does not interrupt the BTC price stream.
  • Keeps the selected time slot independent from the chart market, so target price/actions can follow the selected slot while the chart remains continuous.
  • Preserves series data during transient series refetches so position rows and chart sizing do not jump during time-slot changes.
  • Keeps crypto up/down chart loading visible until the live chart has enough renderable points, avoiding a spinner → blank → chart transition.
  • Uses Polymarket event priceToBeat metadata as the target-line fallback for hourly/daily crypto up/down markets whose target price API can be unavailable.
  • Preserves the existing group item threshold fallback for crypto up/down markets that do not provide event priceToBeat metadata.
  • Improves crypto up/down chart rendering/loading behavior and bottom padding across larger chart heights/font scales.
  • Improves longer-duration countdown/reset copy for hourly/daily/weekly crypto up/down markets.
  • Keeps crypto up/down card routing behind the Predict up/down feature flag.

Changelog

CHANGELOG entry: null

Related issues

Fixes: N/A

Manual testing steps

Feature: Crypto up/down market experience

  Scenario: user views the crypto up/down series card while prices update
    Given the Predict up/down feature flag is enabled
    And a live crypto up/down market is visible in the Predict feed

    When live CLOB price updates are received for the Up and Down tokens
    Then the Up and Down CTA prices update from the live buy prices
    And the CTA prices do not briefly flicker to stale REST or static market prices

  Scenario: user opens crypto up/down market details and changes time slots
    Given the user is on a live crypto up/down market details screen
    And the market series includes a future time slot

    When user selects the future time slot
    Then the selected time slot updates
    And the chart remains anchored to the live market price stream
    And the Up and Down actions use the selected time slot market
    And the current price display remains stable while the target price loads

  Scenario: user waits for the crypto up/down chart to load
    Given the user is on a crypto up/down market details screen
    And live chart data has not produced at least two renderable points

    When the initial chart request finishes
    Then the chart loading state remains visible
    And the screen does not briefly show an empty chart area before the live line renders

  Scenario: user views hourly or daily crypto up/down target lines
    Given an hourly or daily crypto up/down market has Polymarket event price to beat metadata
    And the crypto target price API is unavailable

    When the market card or market details screen is rendered
    Then the target line uses the event price to beat metadata
    And the existing group item threshold fallback is still available if event metadata is missing

  Scenario: user views longer-duration crypto up/down markets
    Given a crypto up/down market has an hourly, daily, or weekly recurrence

    When the market card or time slot picker is rendered
    Then the countdown and reset copy use readable longer-duration formatting

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
Touches live pricing, chart anchoring, and controller fallbacks across Predict crypto up/down flows, but scope is largely behind the up/down feature flag with broad test coverage.

Overview
This PR tightens the gated crypto up/down Predict experience (feed card, details, and routing) so prices, charts, and target lines stay stable during live updates and time-slot changes.

Pricing & live data: Buy CTAs now share getPredictBuyPrice (live bestAsk → REST entry.buy → token price). useLiveMarketPrices caches recent updates so remounts do not flash stale REST/static prices. Chart loading stays active until at least two renderable points exist; current price can still propagate while loading.

Details screen: The chart stays on the live series market while the picker only changes the selected slot (target line, Up/Down actions, share). Series markets are held in a ref during refetch so positions/chart height do not jump. Target/current summaries use resolveCryptoTargetPrice with skeletons when appropriate; chart bottom padding scales with height and font scale.

Target price & Polymarket: Event priceToBeat is parsed onto markets; PredictController and UI fall back through fetched price → event metadata → groupItemThreshold. Hourly recurrence is supported in duration helpers.

UX polish: Longer countdowns use H:MM:SS when ≥1 hour; reset copy uses readable hour/day/week strings. Up/down feed cards require selectPredictUpDownEnabledFlag in addition to isCryptoUpDown.

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

- Gate PredictCryptoUpDownMarketCard with predictUpDownEnabled flag (matches details page)
- Show 'Resets every X' as natural language (1 day, 4 hours, 2 weeks)
- Format TimeSlotPicker daily countdown as H:MM:SS instead of MM:SS
- Scale chart bottom padding responsively to handle different chart heights + font scales
- Decouple current price callback from chart loading; show Skeleton for Price to beat / Current price until first tick arrives
- Stabilize seriesMarkets cache to prevent layout shift on time-slot switch
Each `usePredictSeries` refetch produces fresh market object references via
`attachSeriesToMarket` spreading. With the prior naive memo, this cascaded
through outcome/token refs and — when the resolver briefly picked a different
market on a refresh — pushed brand-new tokenIds into the live-price hook,
clearing its Map and flashing the Up/Down buttons to `token.price` defaults
(~0.51/0.49) for ~1s every few seconds.

Return the previous resolved market when its id matches the candidate so
downstream identity stays stable; advance only on a real market id change.
@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-predict Predict team label May 26, 2026
@ghgoodreau ghgoodreau changed the title fix(predict): improve crypto up/down cp-7-79.0 fix(predict): improve crypto up/down cp-7.79.0 May 26, 2026
@ghgoodreau ghgoodreau marked this pull request as ready for review May 26, 2026 23:24
@ghgoodreau ghgoodreau requested a review from a team as a code owner May 26, 2026 23:24
@github-actions github-actions Bot added size-XL and removed size-L labels May 26, 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 de7a59c. Configure here.

Comment thread app/components/UI/Predict/controllers/PredictController.ts
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.80597% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.34%. Comparing base (dbbf7e1) to head (de7a59c).
⚠️ Report is 26 commits behind head on main.

Files with missing lines Patch % Lines
...CryptoUpDownDetails/PredictCryptoUpDownDetails.tsx 72.00% 1 Missing and 6 partials ⚠️
...components/UI/Predict/hooks/useLiveMarketPrices.ts 86.95% 4 Missing and 2 partials ⚠️
app/components/UI/Predict/utils/prices.ts 91.66% 0 Missing and 1 partial ⚠️
...iews/PredictMarketDetails/hooks/useOpenOutcomes.ts 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #30662      +/-   ##
==========================================
- Coverage   82.34%   82.34%   -0.01%     
==========================================
  Files        5513     5545      +32     
  Lines      148432   149577    +1145     
  Branches    34145    34505     +360     
==========================================
+ Hits       122231   123173     +942     
- Misses      17913    18029     +116     
- Partials     8288     8375      +87     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

matallui
matallui previously approved these changes May 27, 2026
@matallui matallui added this pull request to the merge queue May 27, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch May 27, 2026
…ements

# Conflicts:
#	app/components/UI/Predict/components/PredictCryptoUpDownMarketCard/PredictCryptoUpDownMarketCard.tsx
#	app/components/UI/Predict/components/PredictMarket/PredictMarket.tsx
@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: 92%
click to see 🤖 AI reasoning details

E2E Test Selection:
All 30 changed files are exclusively within app/components/UI/Predict/. The changes are focused on the Predictions (Polymarket) feature:

  1. PredictController.ts (critical): Refactored getCryptoTargetPrice fallback to use new resolveCryptoTargetPrice utility instead of directly reading groupItemThreshold from market outcomes. This changes how the target price is resolved for crypto up/down markets.

  2. types/index.ts: Added priceToBeat field to PredictMarket type - new data field from Polymarket API.

  3. utils/cryptoUpDown.ts: Added hourly recurrence support, new getMarketTargetPrice and resolveCryptoTargetPrice functions with priority logic (priceToBeat > groupItemThreshold).

  4. utils/prices.ts (new file): Extracted getPredictBuyPrice utility with corrected price precedence (bestAsk > REST buy price > token.price) - previously used entry.sell instead of entry.buy.

  5. utils/series.ts: Improved formatSeriesDuration to display weeks/days/hours instead of HH:MM:SS format.

  6. hooks/useLiveMarketPrices.ts: Added module-level price cache (10s TTL) to prevent stale data flashes when components remount.

  7. hooks/useCryptoUpDownChartData.ts: Fixed loading state - removed dependency on liveLoading flag.

  8. hooks/useCurrentCryptoUpDownMarketData.ts: Uses resolveCryptoTargetPrice for better fallback handling.

  9. components/PredictCryptoUpDownDetails: Major refactor - stable series markets ref to prevent layout shifts, live market anchoring for chart, skeleton loading states for target/current price.

  10. components/PredictCryptoUpDownChart: Dynamic bottom padding based on font scale.

  11. components/PredictCryptoUpDownMarketCard: Uses new utility functions.

  12. components/PredictMarket: Added feature flag gate (selectPredictUpDownEnabledFlag) for CryptoUpDown market rendering.

  13. providers/polymarket/utils.ts: Parses priceToBeat from event metadata.

  14. views/PredictMarketDetails/hooks/useOpenOutcomes.ts: Uses getPredictBuyPrice with corrected buy price logic.

  15. components/TimeSlotPicker/useCountdown.ts: Added H:MM:SS format for countdowns >= 1 hour.

Tag selection rationale:

  • SmokePredictions: Primary tag - all changes are in the Predictions feature. Tests position lifecycle, balance sync, market interactions, and error handling.
  • SmokeWalletPlatform: Required per SmokePredictions description - "Predictions is also a section inside the Trending tab (SmokeWalletPlatform)". Changes to Predictions views affect Trending.
  • SmokeConfirmations: Required per SmokePredictions description - "opening/closing positions are on-chain transactions". The PredictController changes affect transaction flows.

The changes are medium risk - they refactor core prediction market logic (price resolution, chart data, live price caching) but are well-contained within the Predict feature module. The price precedence fix (sell→buy) and target price resolution changes could affect market display and betting flows.

Performance Test Selection:
The useLiveMarketPrices hook now has a module-level price cache with TTL management and the chart rendering has dynamic padding calculations based on font scale. These changes could affect prediction market loading and rendering performance. The @PerformancePredict tag covers prediction market list loading, market details, deposit flows, and balance display - all of which are touched by these changes.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@ghgoodreau ghgoodreau added this pull request to the merge queue May 27, 2026
Merged via the queue into main with commit f24ef18 May 27, 2026
194 of 199 checks passed
@ghgoodreau ghgoodreau deleted the predict/updown-improvements branch May 27, 2026 16:03
@github-actions github-actions Bot locked and limited conversation to collaborators May 27, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.80.0 Issue or pull request that will be included in release 7.80.0 label May 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants