Skip to content

feat: Add perps live stream hooks via stream provider#40779

Merged
gambinish merged 98 commits intomainfrom
feat/integrate-perps-controller-streaming-hooks
Mar 20, 2026
Merged

feat: Add perps live stream hooks via stream provider#40779
gambinish merged 98 commits intomainfrom
feat/integrate-perps-controller-streaming-hooks

Conversation

@gambinish
Copy link
Copy Markdown
Member

@gambinish gambinish commented Mar 10, 2026

Description

Builds on #40769, which wired PerpsController into the background and established the PerpsStreamBridge. 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 the perpsStreamUpdate handler routing background messages into getPerpsStreamManager()
  • PerpsStreamManager.ts — module-level singleton replacing the old mock-backed provider; fans out stream updates to subscribed channels
  • PerpsDataChannel.ts + CandleStreamChannel.ts — per-channel data abstractions
  • ui/selectors/perps-controller.ts — Redux selectors for flattened PerpsController state
  • usePerpsStreamManager, usePerpsTopOfBook — new stream hooks; existing hooks updated to consume the new provider
  • PerpsLayout — new layout wrapper for perpsInit on mount (consumed by routes in the next PR)
  • Deleted PerpsControllerProvider.mock.tsx + getPerpsController.mock.ts — old mock-backed files no longer needed
  • import/order lint fixes across ui/hooks/perps/ and ui/components/app/perps/

Open in GitHub Codespaces

Changelog

CHANGELOG entry: Add perps live stream hooks to UI

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

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

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 perpsStreamUpdate notifications and fans them out through a singleton PerpsStreamManager with cached, BehaviorSubject-like channels (positions/orders/account/fills/markets/prices/orderBook) plus a new multiplexed CandleStreamChannel supporting 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.js to route background updates into the manager, and adds PerpsLayout to signal perpsViewActive(true/false) so the background only emits while Perps routes are mounted.

Refines background PerpsStreamBridge candle handling so candle subscriptions are keyed by symbol+interval and perpsDeactivateCandleStream tears 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.

@metamaskbotv2
Copy link
Copy Markdown
Contributor

metamaskbotv2 bot commented Mar 10, 2026

✨ Files requiring CODEOWNER review ✨

👨‍🔧 @MetaMask/perps (17 files, +3355 -133)
  • 📁 app/
    • 📁 scripts/
      • 📁 controllers/
        • 📁 perps/
          • 📄 perps-stream-bridge.test.ts +41 -1
          • 📄 perps-stream-bridge.ts +46 -18
  • 📁 ui/
    • 📁 components/
      • 📁 app/
        • 📁 perps/
          • 📄 perps-tab-view.tsx +2 -3
    • 📁 hooks/
      • 📁 perps/
        • 📁 stream/
          • 📄 index.ts +102 -4
          • 📄 usePerpsChannel.ts +29 -5
          • 📄 usePerpsStreamManager.ts +20 -17
          • 📄 usePerpsTopOfBook.ts +52 -53
    • 📁 pages/
      • 📁 perps/
        • 📄 perps-layout.tsx +37 -0
    • 📁 providers/
      • 📁 perps/
        • 📁 PerpsStreamManager/
          • 📄 index.ts +6 -4
          • 📄 CandleStreamChannel.test.ts +842 -0
          • 📄 CandleStreamChannel.ts +425 -0
          • 📄 index.mock.ts +1 -24
          • 📄 index.ts +49 -4
          • 📄 PerpsDataChannel.test.ts +401 -0
          • 📄 PerpsDataChannel.ts +212 -0
          • 📄 PerpsStreamManager.test.ts +560 -0
          • 📄 PerpsStreamManager.ts +530 -0

@gambinish gambinish changed the title feat: Add live stream hooks via stream provider feat: Add perps live stream hooks via stream provider Mar 10, 2026
@metamaskbotv2
Copy link
Copy Markdown
Contributor

metamaskbotv2 bot commented Mar 10, 2026

Builds ready [2c31bad]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account27526629512271295
total27526629512271295
Confirm Txconfirm_tx6053603560681260556068
total6053603560681260556068
Bridge User Actionsbridge_load_page22620224816237248
bridge_load_asset_picker19313924644243246
bridge_search_token7087027207708720
total1136107512306912111230
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14961246198011115481672
load12431022174710813011421
domContentLoaded12341017167910212931397
domInteractive3017119222592
firstPaint164721242135206338
backgroundConnect22120029218223257
firstReactRender20144462132
initialActions107123
loadScripts1032820147210110961191
setupStore1473461725
numNetworkReqs362794182785
Power User HomeuiStartup5284211811739176762257993
load12631124169612513141510
domContentLoaded12441116168811912891482
domInteractive3519185253177
firstPaint210791199160258339
backgroundConnect18033086038146628054331
firstReactRender28206673038
initialActions105113
loadScripts1024898144610710641241
setupStore1666991730
numNetworkReqs1566331543172252
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2192182191219219
srpButtonToSrpForm98941034103103
confirmSrpToPwForm23222512425
pwFormToMetricsScreen16151811718
metricsToWalletReadyScreen17161911819
doneButtonToHomeScreen65360071548704715
openAccountMenuToAccountListLoaded2933291229531529472953
total3961388740346140234034
Onboarding New WalletcreateWalletToSocialScreen2182172191218219
srpButtonToPwForm1081061091108109
createPwToRecoveryScreen888088
skipBackupToMetricsScreen35343513535
agreeButtonToOnboardingSuccess16161601616
doneButtonToAssetList59248070989642709
total97786910968910241096
Asset DetailsassetClickToPriceChart13812114810146148
total13812114810146148
Solana Asset DetailsassetClickToPriceChart88789889398
total88789889398
Import Srp HomeloginToHomeScreen2266219423405723012340
openAccountMenuAfterLogin65607146671
homeAfterImportWithNewWallet23442220248410824612484
total47254474504921348915049
Send TransactionsopenSendPageFromHome351768194568
selectTokenToSendFormLoaded20192002020
reviewTransactionToConfirmationPage90884610831018561083
total9548851119969111119
SwapopenSwapPageFromHome25183462734
fetchAndDisplaySwapQuotes268526762694626902694
total270826982716827162716
🌐 Dapp Page Load Benchmarks

Current Commit: 2c31bad | Date: 3/10/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.07s (±42ms) 🟡 | historical mean value: 1.03s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 754ms (±63ms) 🟢 | historical mean value: 727ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 86ms (±42ms) 🟢 | historical mean value: 82ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.07s 42ms 1.04s 1.40s 1.10s 1.40s
domContentLoaded 754ms 63ms 725ms 1.33s 778ms 1.33s
firstPaint 86ms 42ms 64ms 504ms 92ms 504ms
firstContentfulPaint 86ms 42ms 64ms 504ms 92ms 504ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 7.6 MiB (100%)
  • ui: 8.36 MiB (100%)
  • common: 11 MiB (100%)

@gambinish gambinish marked this pull request as ready for review March 11, 2026 01:19
@gambinish gambinish requested a review from a team as a code owner March 11, 2026 01:19
…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>
Copy link
Copy Markdown

@cursor cursor bot left a comment

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.

There are 4 total unresolved issues (including 3 from previous reviews).

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.

aganglada
aganglada previously approved these changes Mar 20, 2026
@sonarqubecloud
Copy link
Copy Markdown

@gambinish gambinish enabled auto-merge March 20, 2026 18:48
@gambinish gambinish disabled auto-merge March 20, 2026 18:48
@gambinish gambinish enabled auto-merge March 20, 2026 18:54
@metamaskbotv2
Copy link
Copy Markdown
Contributor

metamaskbotv2 bot commented Mar 20, 2026

Builds ready [0def20b]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account29026531822314318
total29026531822314318
Confirm Txconfirm_tx6050603560601060566060
total6050603560601060566060
Bridge User Actionsbridge_load_page24020626521259265
bridge_load_asset_picker22818426134257261
bridge_search_token74970977024766770
total1217115512865112551286
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14791256202310915031667
load1225102216669812501417
domContentLoaded1218101716589612451388
domInteractive30171072226100
firstPaint173731212159217365
backgroundConnect22220327512228243
firstReactRender20136362229
initialActions105123
loadScripts101081614499510331180
setupStore1473551723
numNetworkReqs403187163777
Power User HomeuiStartup57061791149422521637010524
load13081150221517213181669
domContentLoaded12851136208016312961642
domInteractive39202894133133
firstPaint225851254140279396
backgroundConnect184331212374220327506199
firstReactRender23174152533
initialActions105113
loadScripts1057916181615510631397
setupStore1667291732
numNetworkReqs2016840357217312
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2212182243224224
srpButtonToSrpForm94929939499
confirmSrpToPwForm22222302323
pwFormToMetricsScreen15151501515
metricsToWalletReadyScreen16151711717
doneButtonToHomeScreen54051756318551563
openAccountMenuToAccountListLoaded3002292731098631063109
total39573813406810040374068
Onboarding New WalletcreateWalletToSocialScreen2172162181218218
srpButtonToPwForm1081041113109111
createPwToRecoveryScreen888088
skipBackupToMetricsScreen39384214042
agreeButtonToOnboardingSuccess16151601616
doneButtonToAssetList5074965158515515
total89988191113911911
Asset DetailsassetClickToPriceChart46405664556
total46405664556
Solana Asset DetailsassetClickToPriceChart17816519111186191
total17816519111186191
Import Srp HomeloginToHomeScreen2321221424649023162464
openAccountMenuAfterLogin634589166689
homeAfterImportWithNewWallet1551312244096923532440
total40222705479591747794795
Send TransactionsopenSendPageFromHome29234382643
selectTokenToSendFormLoaded29263433134
reviewTransactionToConfirmationPage1237997151119314111511
total13111086158619815101586
SwapopenSwapPageFromHome982813940124139
fetchAndDisplaySwapQuotes269526812707927002707
total2792272528273728232827
🌐 Dapp Page Load Benchmarks

Current Commit: 0def20b | Date: 3/20/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 988ms (±114ms) 🟢 | historical mean value: 1.04s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 698ms (±135ms) 🟢 | historical mean value: 731ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 97ms (±200ms) 🟢 | historical mean value: 86ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 988ms 114ms 953ms 2.09s 1.01s 2.09s
domContentLoaded 698ms 135ms 665ms 2.02s 708ms 2.02s
firstPaint 97ms 200ms 64ms 2.08s 88ms 2.08s
firstContentfulPaint 97ms 200ms 64ms 2.08s 88ms 2.08s
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 322 Bytes (0%)
  • ui: 18.45 KiB (0.22%)
  • common: 20 Bytes (0%)

@gambinish gambinish added this pull request to the merge queue Mar 20, 2026
Merged via the queue into main with commit 350d9a4 Mar 20, 2026
206 of 207 checks passed
@gambinish gambinish deleted the feat/integrate-perps-controller-streaming-hooks branch March 20, 2026 19:53
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2026
@metamaskbot metamaskbot added the release-13.25.0 Issue or pull request that will be included in release 13.25.0 label Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-13.25.0 Issue or pull request that will be included in release 13.25.0 size-XL team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants