feat(predict): Live Trade Activity Overlay reusable Hook#30415
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
| const tw = useTailwind(); | ||
| const { colors } = useTheme(); | ||
| const navigation = | ||
| useNavigation<NavigationProp<PredictNavigationParamList>>(); |
There was a problem hiding this comment.
Unused navigation import in market card component
Low Severity
The useNavigation call at line 995–996 assigns to navigation, which is only passed to usePredictActionGuard({ navigation }). However, navigateToMarketDetails (from usePredictNavigation) internally calls its own useNavigation, meaning the card component obtains navigation twice — once explicitly and once inside usePredictNavigation. The explicit useNavigation plus the NavigationProp type import exist solely to pass navigation to the action guard, adding unnecessary coupling.
Reviewed by Cursor Bugbot for commit 54dd5f7. Configure here.
|
@metamaskbot update-mobile-fixture |
|
🔄 Fixture update started. Running workflow from branch |
|
❌ 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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #30415 +/- ##
==========================================
+ Coverage 82.03% 82.07% +0.04%
==========================================
Files 5454 5470 +16
Lines 145830 147196 +1366
Branches 33411 33815 +404
==========================================
+ Hits 119629 120812 +1183
- Misses 18016 18080 +64
- Partials 8185 8304 +119 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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 5976a54. Configure here.
|
One item from codex review: [P2] getCryptoPriceHistory no longer fetches the requested historical window. The previous request sent eventStartTime/endDate; the new Chainlink request only sends symbol, interval, and limit, then filters locally. That works for fresh/live data, but older details views and selected past slots can get an empty chart even when historical data exists. |
@caieu @MarioAslau disregard this for this PR; this is being handled in my next PR. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Tag reasoning:
No other tags are affected - changes are isolated to the Predict/Polymarket feature area with no impact on accounts, networks, swaps, browser, snaps, or other wallet features. Performance Test Selection: |
|





Description
This PR delivers two related pieces of work for the Predict crypto up/down details screen:
A reusable
usePredictOrderbookhook that streams live Polymarket orderbook depth into the existingLivelineChartso the chart shows real bid/ask activity overlaid on the price line. The hook is plumbed through the existing controller / provider / WebSocket stack — no new APIs needed at the engine layer.The data flow:
The WebSocket manager handles per-token reference counting, a 250 ms emit throttle to protect the RN↔WebView bridge,
bookevent ingestion, and opportunistic top-of-book pruning onprice_changeevents. The REST bootstrap runs at the provider layer (where the active CLOB protocol is known) and seeds the cache before the first WS event arrives.Chart UX/UI polish to match the Figma reference for
BTC Up or Down:padding.top: 48 → 12).padding.right: 80 → 64).padding.bottom: 48 → 80)..00from the y-axis price labels per design (whole-dollar formatter).h:mm:ssformatTimeso the time-axis labels fit the live 30s window without overlap-culling.CRYPTO_UP_DOWN_FORMAT_VALUEandCRYPTO_UP_DOWN_FORMAT_TIMEas named exports so the WebView-bridged formatter bodies can be regression-tested withit.each.The PR also includes a self-review pass that fixed:
orderbookState+ throttle timers indisconnectMarket).errorfield on the orderbook hook's public type.tokenIdslipping past the subscribe guard.applyTopOfBook(it prunes, doesn't splice).createMockChartRefhelper + 19 unusedchartReflocals + 2 orphanedappendPointassertions inuseCryptoUpDownChartData.test.ts(the hook signature dropped itschartRefarg upstream).Deferred to follow-ups (intentional)
patch-packageonlivelinefor: (a) orderbook depth fade threshold (currently fades only in the top 45% — design wants midpoint), (b) time-axis edge-fade reduction, (c) palette opacity bumps. All require modifyingnode_modules/liveline/dist/index.jsand rebundling viayarn build:liveline-webview; tracked separately because they coordinate with chart-team work.setOrderbookonLivelineChartRefto skip a fullSET_PROPSround-trip on every depth tick (perf optimization that needs upstreamlivelinecooperation).Price to beat/Current price/Target(nopredict.crypto_up_downnamespace exists yet — broader Predict-feature concern).Changelog
CHANGELOG entry: Added live orderbook depth visualization and refined the chart layout for Crypto Up/Down markets.
Related issues
Refs:
Manual testing steps
Screenshots/Recordings
Before
After
Uploading upDown.mov…
Pre-merge author checklist
usePredictOrderbook.test.ts(new) — subscribe/unsubscribe lifecycle, snapshot mapping, mount/unmount safety, connection polling.WebSocketManager.test.ts— extended with positive coverage forbookevents, REST seed, reference counting, reconnect, throttle, opportunistic TOB prune.PolymarketProvider.test.ts—subscribeToOrderbookREST bootstrap success/failure.PredictController.test.ts— passthrough +MESSENGER_EXPOSED_METHODSregistration.PredictCryptoUpDownChart.test.tsx— orderbook wiring, prop forwarding,CRYPTO_UP_DOWN_FORMAT_VALUEandCRYPTO_UP_DOWN_FORMAT_TIMEit.eachregression suites.usePredictOrderbook,CRYPTO_UP_DOWN_FORMAT_VALUE,CRYPTO_UP_DOWN_FORMAT_TIME,CHART_HEIGHT_VIEWPORT_FRACTION, and the new WebSocketManager orderbook methods.team-predict(or the appropriate Predict team label),area-predict. Addneeds-qaif the on-device cadence of orderbook depth needs review.Performance checks (if applicable)
DevLogger. If Sentry traces are desired onsubscribeToOrderbookREST + WS handshake timing, can add in a follow-up.Pre-merge reviewer checklist
Appendix — quality gate
yarn lint:tscyarn jest(focused Predict suites: chart, details, hooks, WebSocketManager)runAfterInteractions, an existingReactshadow in mocks) all predate this branch — not introduced here.Appendix — files touched (high level)
app/components/UI/Predict/hooks/usePredictOrderbook.ts(+ test)WebSocketManager.ts(orderbook subscription map, throttle, lifecycle),PolymarketProvider.ts(passthrough + REST seed),PredictController.ts(passthrough +MESSENGER_EXPOSED_METHODS),types/index.ts(OrderbookLevel/Snapshot/Callback),providers/types.ts(optional method in interface).PredictCryptoUpDownChart.tsx(+ test),PredictCryptoUpDownDetails.tsx,useCryptoUpDownChartData.ts(+ test).Note
Medium Risk
Adds a new real-time orderbook subscription pipeline (controller/provider/WebSocketManager) and feeds it into a WebView-backed chart, which can impact live data correctness and reconnect/unsubscribe behavior.
Overview
Adds live orderbook depth streaming for Predict crypto Up/Down charts. Introduces a reusable
usePredictOrderbookhook, exposesPredictController.subscribeToOrderbook, and implementsPolymarketProvider.subscribeToOrderbookwith a RESTgetOrderBookbootstrap that seeds the WS cache.Extends
WebSocketManagerto supportbookevents. Adds per-token orderbook subscriptions with cached snapshot replay, REST seeding, and a 250ms emit throttle; updates unsubscribe/reconnect/cleanup logic and connection status to account for orderbook subscribers.Updates chart wiring and formatting.
PredictCryptoUpDownChartnow forwardsorderbookintoLivelineChart, adds a compactCRYPTO_UP_DOWN_FORMAT_TIMEformatter, and expands test coverage across the new hook, controller/provider passthroughs, WS behavior, and formatter regression cases; also tweaks Crypto Up/Down details chart height calculation constant usage and fixes websocket mock tests to use OS-assigned ports.Reviewed by Cursor Bugbot for commit 33c3365. Bugbot is set up for automated code reviews on this repo. Configure here.