perf(perps): stop re-fetching HyperLiquid data the homepage already has - #34511
perf(perps): stop re-fetching HyperLiquid data the homepage already has#34511juanmigdr wants to merge 3 commits into
Conversation
On wallet unlock, the homepage's Perpetuals section was making a burst of calls straight to HyperLiquid: one for the base price feed, plus one candleSnapshot call per trending tile for sparklines. All of that data is already sitting in the Terminal API response the app fetches for the same markets, once @metamask/perps-controller is updated to expose it. useHomepageSparklines now reads the trend field already present on each market object instead of opening a per-symbol candle stream subscription. PerpsSectionMain and usePerpsFeed pass market objects through instead of bare symbol strings, and pull-to-refresh now refreshes the market list directly rather than just re-subscribing to candles. Requires the paired @metamask/perps-controller change: https://github.com/MetaMask/core/pull/TBD
PR template — items to address before "Ready for review"Warnings — informational, address before merging:
See docs/readme/ready-for-review.md for the full Definition of Ready for Review. |
🧪 Flaky unit test detectionRun history flaky detectionHistorical failure rate is a hint, not proof — review each suggestion in context. See the flaky-test-detection skill for the full pattern reference and manual audit workflow. Failures / runs sampled per window:
AI-detected flaky patterns
|
… release PerpsMarketData.trend isn't in the currently published perps-controller package types yet - that lands with the paired core PR. Read it through a local type until the dependency is bumped, and fix the mock typing in usePerpsFeed's test that was tripping up on an untyped spread.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
SmokePerps: Directly tests Perps functionality including the Add Funds flow, balance verification, and market display. The sparkline rendering and pull-to-refresh behavior changes need validation. SmokeWalletPlatform: Per the tag description, Perps is a section inside the Trending tab. Changes to Perps views (headers, lists, full views) affect Trending. The SmokeConfirmations: Per SmokePerps description, Add Funds deposits are on-chain transactions requiring confirmation flows. Required when selecting SmokePerps. The test files are unit tests only (no E2E smoke specs), so they don't directly map to additional E2E tags beyond what the functional changes warrant. Performance Test Selection: |
|
⚡ Performance Test Results
✅ All tests passed · 2 tests · 1 device 📱 Devices tested (1)Android: Google Pixel 8 Pro (v14.0) ✅ Passed Tests (2)
Branch: |



Description
On wallet unlock, the homepage's Perpetuals section (trending tiles + sparklines) was hitting HyperLiquid directly for data that the Terminal API response already contains: one base price call (
allMids/metaAndAssetCtxs), plus onecandleSnapshotcall per trending tile just to build a sparkline.The companion
@metamask/perps-controllerchange (MetaMask/core#9808) surfaces theprice/trendfields already present in the Terminal API response. This PR updates the mobile side to consume that instead of re-fetching from HyperLiquid:useHomepageSparklinesnow derives sparklines from thetrendfield already present on each market object, instead of opening a per-symbol candle stream subscription.PerpsSectionMainandusePerpsFeednow pass market objects intouseHomepageSparklinesinstead of bare symbol strings.Depends on: MetaMask/core#9808 (needs to merge and release first for the HyperLiquid call reduction to take effect; this PR is safe to merge independently since it keeps working against the existing provider fallback path).
Changelog
CHANGELOG entry: Improved homepage load performance by reducing redundant network requests for the Perpetuals section's trending tiles and sparklines.
Related issues
Refs: ASSETS-3858
Manual testing steps
Screenshots/Recordings
N/A — this is a data-fetching refactor with no UI/visual changes. The trending carousel and sparklines render identically to before.
Before
N/A
After
N/A
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Medium Risk
Changes homepage perps data sourcing and refresh behavior on a high-traffic unlock path; sparkline freshness shifts to hourly trend data until the paired perps-controller release exposes
trendreliably.Overview
Homepage Perpetuals sparklines no longer open a WebSocket candle subscription per trending tile.
useHomepageSparklinesnow takes market objects (not symbol strings), reads each market’strendfrom the existing markets fetch, downsamples to ~50 points, and drops the hook’srefreshAPI.Call sites (
PerpsSectionMain,usePerpsFeed) pass sliced carousel markets into that hook. When the trending carousel is visible, pull-to-refresh on the section callsrefreshMarketsfromusePerpsTrendingCarouselData(wired throughusePerpsMarkets) instead of re-triggering sparkline stream subscriptions.Sparklines trade live 15m candles for hourly trend data from the Terminal response—intentional to cut redundant HyperLiquid
candleSnapshottraffic on unlock/reconnect. Tests cover trend parsing, refresh wiring, and feed sparkline inputs.Reviewed by Cursor Bugbot for commit 878395a. Bugbot is set up for automated code reviews on this repo. Configure here.