Skip to content

fix: Perps/refresh hl live account cache#29217

Closed
geositta wants to merge 4 commits into
perps/fix-avail-balance-order-entryfrom
perps/refresh-HL-live-account-cache
Closed

fix: Perps/refresh hl live account cache#29217
geositta wants to merge 4 commits into
perps/fix-avail-balance-order-entryfrom
perps/refresh-HL-live-account-cache

Conversation

@geositta

@geositta geositta commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Description

This PR builds on perps/fix-avail-balance-order-entry by fixing the remaining live-update gap for HyperLiquid availableToTradeBalance.

The parent branch corrected the balance math and UI usage, but after a successful trade or margin mutation the Perps home screen could still briefly show the right value and then get overwritten by stale streamed account data, because the live HyperLiquid account stream was still using cached spot state.

The solution is to refresh the existing streamed account path after successful trade mutations instead of adding new UI side refresh logic.

An optional refreshLiveAccountState() hook was added to the provider interface, implemented for HyperLiquid, and invoked by TradingService after successful order placement, close, flip, batch close, and margin updates.

On HyperLiquid, that forces a fresh spotClearinghouseState fetch and reuses the existing account aggregation/notification path, so subscribers receive an updated availableToTradeBalance from the live stream itself rather than a temporary one-off refresh.

Changelog

CHANGELOG entry:

Related issues

Fixes:

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

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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
Touches post-trade state update paths and HyperLiquid subscription caching; mistakes could cause missed/extra refreshes or stale balances in the UI. Changes are guarded (optional provider method, no-op when unsubscribed) and covered by unit tests.

Overview
Fixes a stale-balance flicker by introducing optional refreshLiveAccountState() on PerpsProvider, implemented in HyperLiquidProvider/HyperLiquidSubscriptionService to forcibly refetch spot state and re-notify existing account subscribers.

TradingService now triggers this refresh (fire-and-forget with error logging) after successful placeOrder, cancelOrder/batch cancel, closePosition/batch close, updateMargin, and flipPosition, while keeping the behavior optional for providers that don’t implement it. Tests and mocks were updated to cover delegation via AggregatedPerpsProvider and to ensure refreshes only occur on successful mutations and only when streamed account data is already active.

Reviewed by Cursor Bugbot for commit d67be89. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbotv2 metamaskbotv2 Bot added the team-perps Perps team label Apr 22, 2026
@geositta geositta changed the base branch from main to perps/fix-avail-balance-order-entry April 22, 2026 20:47
@github-actions github-actions Bot added size-M and removed size-L labels Apr 22, 2026
@geositta geositta marked this pull request as ready for review April 22, 2026 21:47
@geositta geositta requested a review from a team as a code owner April 22, 2026 21:47

@cursor cursor Bot left a comment

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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

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.

Reviewed by Cursor Bugbot for commit 314faba. Configure here.

Comment thread app/controllers/perps/services/TradingService.ts Outdated
@geositta geositta changed the title Perps/refresh hl live account cache fix: Perps/refresh hl live account cache Apr 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - base branch is not main or a release branch (base: perps/fix-avail-balance-order-entry)

All E2E tests pre-selected.

View GitHub Actions results

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (perps/fix-avail-balance-order-entry@3c56fde). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...s/perps/services/HyperLiquidSubscriptionService.ts 77.77% 0 Missing and 2 partials ⚠️
...controllers/perps/providers/HyperLiquidProvider.ts 0.00% 1 Missing ⚠️
app/controllers/perps/services/TradingService.ts 93.33% 1 Missing ⚠️
Additional details and impacted files
@@                          Coverage Diff                           @@
##             perps/fix-avail-balance-order-entry   #29217   +/-   ##
======================================================================
  Coverage                                       ?   82.24%           
======================================================================
  Files                                          ?     5101           
  Lines                                          ?   134628           
  Branches                                       ?    30242           
======================================================================
  Hits                                           ?   110728           
  Misses                                         ?    16375           
  Partials                                       ?     7525           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
12 value mismatches detected (expected — fixture represents an existing user).
View details

@geositta geositta closed this Apr 23, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 23, 2026
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.

2 participants