Commit c77dd1a
chore(perps): Refactor HL subscription service (#24015)
<!--
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 refactors the HyperLiquid subscription service to drop
subscription fallbacks.
This refactor was raised during the offsite, as it is needed as a result
of the hotfix we had to deploy to address Perps loading issue during the
weekend. The initial PR
#23753 introduced a
fallback mechanism that would create new subscriptions when the
properties in the data coming from the old subscriptions were missing.
Given that these properties will be always missing, this PR uses the new
subscriptions as a default.
## **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: null
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
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**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
No visible change
### **After**
No visible change
## **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]
> Replaces HIP‑3 webData3 fallback with per‑DEX
clearinghouseState/openOrders subscriptions, adds `triggerPrice` to
orders, and hardens TP/SL extraction with price-based fallback and cache
re-use; tests updated accordingly.
>
> - **Perps Subscription Service (HIP‑3)**:
> - Switch to individual subscriptions: `clearinghouseState`
(positions/account) and `openOrders` (orders); use `webData3` only for
OI caps.
> - Remove fallback caches/handlers; centralize aggregation and cache
updates; update cleanup/restore logic to handle new subs.
> - Re-extract TP/SL from cached orders on `clearinghouseState` updates
to prevent flicker.
> - Update hashing/change-detection and notify paths; broaden
reconnection restoration across subtypes.
> - **TP/SL Processing**:
> - New shared helper to extract TP/SL from orders; adds price-based
fallback for ambiguous `Trigger` types (long/short aware) and counts
TP/SL.
> - **Order Model & Adapter**:
> - Extend `Order` with `triggerPrice`.
> - `adaptOrderFromSDK` sets `triggerPrice` (uses `triggerPx`) and
prioritizes `limitPx` for price; child TP/SL preserved.
> - **Tests**:
> - Overhaul to reflect new HIP‑3 flow: assert
`clearinghouseState`/`openOrders` usage; OI caps via `webData3`.
> - Replace timeouts with `jest.runAllTimersAsync()`; add coverage for
TP/SL classification, cache re-use, short/long logic, L2 book handling,
and feature-flag updates.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
cd9bbb0. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: abretonc7s <[email protected]>1 parent 9cce51e commit c77dd1a
File tree
5 files changed
+1308
-615
lines changed- app/components/UI/Perps
- controllers/types
- services
- utils
5 files changed
+1308
-615
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
773 | 773 | | |
774 | 774 | | |
775 | 775 | | |
| 776 | + | |
776 | 777 | | |
777 | 778 | | |
778 | 779 | | |
| |||
0 commit comments