Commit 9ec45c6
authored
fix(perps): add fallback subscriptions for missing HyperLiquid API fields cp-7.60.4 (MetaMask#23753)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
This PR fixes missing data issues in HyperLiquid WebSocket subscriptions
by implementing fallback subscription mechanisms. The HyperLiquid API
has changed its structure, and fields like `clearinghouseState` and
`openOrders` that were previously available in `webData2` and `webData3`
subscriptions are now missing or have been moved to separate
subscription types.
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: Fixed missing position and order data in HyperLiquid
perpetuals by implementing fallback subscription mechanisms for API
changes
## **Related issues**
Fixes: MetaMask#23721
Incident: https://consensys.slack.com/archives/C0A1HK3MZ6K
## **Manual testing steps**
```gherkin
Feature: HyperLiquid Perpetuals Data Subscription
Scenario: user views positions when API fields are missing
Given user has an active HyperLiquid perpetuals position
And the HyperLiquid API is missing clearinghouseState in webData3 response
When user opens the perpetuals screen
Then positions should be displayed correctly using fallback subscription
And position data should update in real-time
Scenario: user views orders when API fields are missing
Given user has open orders on HyperLiquid
And the HyperLiquid API is missing openOrders in webData3 response
When user opens the perpetuals screen
Then orders should be displayed correctly using fallback subscription
And order data should update in real-time
Scenario: user views account state when API fields are missing
Given user is connected to HyperLiquid
And the HyperLiquid API is missing clearinghouseState in webData2 response
When user views their account balance
Then account state should be displayed correctly using fallback subscription
And account data should update in real-time
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
<img width="1206" height="2622" alt="Simulator Screenshot - iPhone 17
Pro - 2025-12-06 at 10 07 33"
src="https://github.com/user-attachments/assets/7436b059-fa3e-4af4-ab56-94cd2e39a259"
/>
### **After**
<!-- [screenshots/recordings] -->
<img width="1206" height="2622" alt="Simulator Screenshot - iPhone 17
Pro - 2025-12-06 at 10 03 55"
src="https://github.com/user-attachments/assets/120abe77-3ead-4bee-8ac3-fce3d805d3cb"
/>
## **Pre-merge author checklist**
- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds fallback `clearinghouseState` and `openOrders` subscriptions and
centralized aggregation to handle missing HyperLiquid WebSocket fields,
with robust error handling and cleanup.
>
> - **HyperLiquid perps subscription service
(`app/components/UI/Perps/services/HyperLiquidSubscriptionService.ts`)**:
> - **Fallback data sources**:
> - Add per-DEX fallback subscriptions for `clearinghouseState` and
`openOrders` when absent in `webData3`, with caches
(`fallbackClearinghouseStateCache`, `fallbackOpenOrdersCache`).
> - Auto-ensure fallbacks during `webData3` processing; use cached
fallback data when available.
> - **Aggregation & notification**:
> - Introduce `aggregateAndNotifySubscribers()` to unify per-DEX caches
into aggregated positions, orders, and account and notify only on
change.
> - **Resilience & logging**:
> - Wrap `webData2`/`webData3` callbacks in try/catch with detailed
`Logger.error` context.
> - Guard against missing fields in `webData2`/`webData3` before access.
> - **Lifecycle management**:
> - Track/manage fallback subscriptions
(`clearinghouseStateSubscriptions`, `openOrdersSubscriptions`).
> - Cleanup fallbacks and caches in
`cleanupSharedWebData3Subscription()` and `clearAll()`.
> - **Misc**:
> - Maintain OI caps extraction and notification; preserve per-DEX
caches and HIP-3 handling.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
98a7365. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent d9d239c commit 9ec45c6
1 file changed
Lines changed: 564 additions & 202 deletions
0 commit comments