Skip to content

fix(predict): Limit chart data points to ensure low-end device support#25016

Closed
kevinbluer wants to merge 0 commit into
mainfrom
fix/predict-market-details-chart-max
Closed

fix(predict): Limit chart data points to ensure low-end device support#25016
kevinbluer wants to merge 0 commit into
mainfrom
fix/predict-market-details-chart-max

Conversation

@kevinbluer
Copy link
Copy Markdown
Contributor

@kevinbluer kevinbluer commented Jan 21, 2026

Description

Fixes chart rendering performance issues on low-end devices (e.g., Galaxy A32) when the MAX timeframe is selected with large datasets (e.g. longer running markets). Implements data limiting via dynamic fidelity calculation, with "client-side" safety net.

Changes

  • Add startTime field to PredictMarket type
  • Map startTime from Polymarket API response in parsePolymarketEvents
  • Calculate dynamic fidelity for MAX timeframe based on market age
  • Target ~100 data points regardless of market age
  • Falls back to default fidelity (1440) when startTime unavailable
  • Add MAX_CHART_POINTS constant (150) in PredictDetailsChart

Changelog

CHANGELOG entry: null

Related issues

Fixes: 24523

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

Before

After

screenshot

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

No changes detected in the diff; no files were added, modified, or removed.

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

@metamaskbot metamaskbot added the team-predict Predict team label Jan 21, 2026
@kevinbluer kevinbluer force-pushed the fix/predict-market-details-chart-max branch from ac56a7a to a7fc655 Compare January 21, 2026 23:42
@kevinbluer kevinbluer marked this pull request as ready for review January 21, 2026 23:42
@kevinbluer kevinbluer requested a review from a team as a code owner January 21, 2026 23:42
@github-actions github-actions Bot added size-M and removed size-S labels Jan 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePredictions
  • Risk Level: low
  • AI Confidence: 92%
click to see 🤖 AI reasoning details

The PR makes changes exclusively to the Predict (Predictions) feature:

  1. PredictDetailsChart.tsx: Added performance optimization to limit chart data points to 150 (MAX_CHART_POINTS) to prevent performance issues on lower-end devices.

  2. polymarket/utils.ts: Added startTime field mapping from Polymarket events to internal market model.

  3. types/index.ts: Added optional startTime field to PredictMarket type.

  4. PredictMarketDetails.tsx: Refactored MAX timeframe fidelity calculation - now uses market's startTime instead of complex adaptive logic based on price history data. This simplifies the code by removing refs and effects.

  5. Test files: Updated unit tests to cover the new behavior.

All changes are isolated to the Predict feature with no impact on core wallet functionality, navigation, or shared components. The E2E tests in e2e/specs/predict/ (tagged with SmokePredictions) cover the predictions flow including market details, opening positions, and claiming winnings - these should verify the changes work correctly.

Risk is low because:

  • Changes are performance optimizations and code simplifications
  • No changes to critical paths (Engine, Controllers, navigation)
  • Feature is self-contained with its own E2E test coverage
  • Unit tests have been updated to cover new behavior

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Comment on lines +300 to +319
seriesToRender.map((series) => {
// Limit data points to prevent performance issues on lower-end devices
const limitedData =
series.data.length > MAX_CHART_POINTS
? series.data.filter(
(_, i, arr) =>
i % Math.ceil(arr.length / MAX_CHART_POINTS) === 0 ||
i === arr.length - 1,
)
: series.data;
return {
...series,
data: limitedData.map((point) => ({
...point,
label: formatPriceHistoryLabel(point.timestamp, selectedTimeframe, {
timeRangeMs: chartTimeRangeMs,
}),
})),
};
}),
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.

Is this fetching everything and filtering data out on the React component?

My suggestion is we move this logic to the hook and also do not over-fetch, since the API allows more granular control over the data we get.

? PredictMarketStatus.CLOSED
: PredictMarketStatus.OPEN,
recurrence: getRecurrence(event.series),
startTime: event.startTime,
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.

Did you confirm this event.startTime? When I fetch events from the API I see startDate, rather than startTime

Comment on lines +330 to +343
const startTs = market?.startTime
? new Date(market.startTime).getTime()
: null;

if (!startTs) {
// Fallback to default if no start time available
return DEFAULT_FIDELITY_BY_INTERVAL[PredictPriceHistoryInterval.MAX];
}

const rangeMinutes = (Date.now() - startTs) / (60 * 1000);
const calculatedFidelity = Math.ceil(rangeMinutes / MAX_HISTORY_SAMPLES);

// Ensure fidelity is at least 1 minute
return Math.max(1, calculatedFidelity);
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.

same here... I would take this opportunity to remove ALL chart / history data logic into the hook, so we're not adding so much logic directly into components

@kevinbluer kevinbluer closed this Jan 22, 2026
@kevinbluer kevinbluer force-pushed the fix/predict-market-details-chart-max branch from a7fc655 to 51f8b9a Compare January 22, 2026 17:02
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 22, 2026
@kevinbluer kevinbluer deleted the fix/predict-market-details-chart-max branch January 22, 2026 17:07
@kevinbluer kevinbluer restored the fix/predict-market-details-chart-max branch January 22, 2026 17:09
@kevinbluer kevinbluer deleted the fix/predict-market-details-chart-max branch January 22, 2026 17:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Predict - MAX graph for a prediction market is always blank

3 participants