feat: Add perps live stream hooks via stream provider#40779
Merged
Conversation
…rps-controller-infrastructure-stream
Contributor
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/perps (17 files, +3355 -133)
|
Contributor
Builds ready [2c31bad]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
7 tasks
…rolled format string Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…rolled format string Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 4 total unresolved issues (including 3 from previous reviews).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
aganglada
previously approved these changes
Mar 20, 2026
|
Contributor
Builds ready [0def20b]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
aganglada
approved these changes
Mar 20, 2026
Matt561
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Description
Builds on #40769, which wired
PerpsControllerinto the background and established thePerpsStreamBridge. This PR adds the corresponding UI streaming layer that receives those background stream updates and distributes live data to components.What's included:
ui/index.js— adds theperpsStreamUpdatehandler routing background messages intogetPerpsStreamManager()PerpsStreamManager.ts— module-level singleton replacing the old mock-backed provider; fans out stream updates to subscribed channelsPerpsDataChannel.ts+CandleStreamChannel.ts— per-channel data abstractionsui/selectors/perps-controller.ts— Redux selectors for flattenedPerpsControllerstateusePerpsStreamManager,usePerpsTopOfBook— new stream hooks; existing hooks updated to consume the new providerPerpsLayout— new layout wrapper forperpsIniton mount (consumed by routes in the next PR)PerpsControllerProvider.mock.tsx+getPerpsController.mock.ts— old mock-backed files no longer neededimport/orderlint fixes acrossui/hooks/perps/andui/components/app/perps/Changelog
CHANGELOG entry: Add perps live stream hooks to UI
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Introduces a new background-driven streaming/caching layer and changes subscription lifecycles (including multiplexed candle streams and view-activation gating), which could impact real-time Perps data freshness and cleanup behavior across navigation/account switches.
Overview
Adds a UI-side Perps streaming layer that consumes
perpsStreamUpdatenotifications and fans them out through a singletonPerpsStreamManagerwith cached, BehaviorSubject-like channels (positions/orders/account/fills/markets/prices/orderBook) plus a new multiplexedCandleStreamChannelsupporting per-key subscribe/unsubscribe, throttling, and historical backfill.Updates hooks and entry points to use the real stream manager (replacing mock exports), wires
ui/index.jsto route background updates into the manager, and addsPerpsLayoutto signalperpsViewActive(true/false)so the background only emits while Perps routes are mounted.Refines background
PerpsStreamBridgecandle handling so candle subscriptions are keyed bysymbol+intervalandperpsDeactivateCandleStreamtears down only the specified stream; expands tests and adjusts Jest console baselines accordingly.Written by Cursor Bugbot for commit 0def20b. This will update automatically on new commits. Configure here.