Commit e19ee34
authored
fix(perps): adjust liquidation distance value when zero (MetaMask#24128)
## **Description**
When a position has a liquidation price of $0 (e.g., cross-margin
positions), the Adjust Margin view was displaying "0%" for liquidation
distance, which is misleading since 0% would normally indicate imminent
liquidation.
This PR adds a fallback display ("--") when the liquidation price is $0,
consistent with how other displays handle unavailable data in the Perps
feature.
## **Changelog**
CHANGELOG entry: Fixed liquidation distance showing 0% instead of
fallback when liquidation price is unavailable
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2200
## **Manual testing steps**
```gherkin
Feature: Adjust Margin View - Liquidation Distance Display
Scenario: User views liquidation distance when liquidation price is $0
Given user has an open position with liquidation price of $0
When user opens the Adjust Margin view
Then liquidation distance displays "--" instead of "0%"
Scenario: User views liquidation distance with valid liquidation price
Given user has an open position with a valid liquidation price
When user opens the Adjust Margin view
Then liquidation distance displays the correct percentage (e.g., "25%")
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- Liquidation distance shows "0%" when liquidation price is $0 -->
<img width="1206" height="2622" alt="Simulator Screenshot -
iPhone16Pro-Gamma - 2025-12-18 at 11 44 31"
src="https://github.com/user-attachments/assets/d0a5a7f1-d53d-4c0e-820b-cb54110d6404"
/>
### **After**
<img width="1206" height="2622" alt="Simulator Screenshot -
iPhone16Pro-Delta - 2025-12-18 at 11 47 32"
src="https://github.com/user-attachments/assets/ad72b39b-c58c-486f-a398-c1e755010cf7"
/>
## **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]
> Use a formatter to display a fallback (e.g., "--") for liquidation
distance when liquidation price is 0 in the Adjust Margin view.
>
> - **Perps Adjust Margin View (`PerpsAdjustMarginView.tsx`)**:
> - **Liquidation Distance**:
> - Add `formatLiquidationDistance` helper to return
`PERPS_CONSTANTS.FALLBACK_DATA_DISPLAY` when `liquidationPrice === 0`.
> - Replace direct percentage rendering with `formatLiquidationDistance`
for current and new values.
> - **Config**: Import `PERPS_CONSTANTS` from `constants/perpsConfig`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
3c7f695. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 46ab400 commit e19ee34
1 file changed
Lines changed: 24 additions & 3 deletions
Lines changed: 24 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
155 | 167 | | |
156 | 168 | | |
157 | 169 | | |
| |||
347 | 359 | | |
348 | 360 | | |
349 | 361 | | |
350 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
351 | 366 | | |
352 | 367 | | |
353 | 368 | | |
354 | 369 | | |
355 | 370 | | |
356 | 371 | | |
357 | 372 | | |
358 | | - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
359 | 377 | | |
360 | 378 | | |
361 | 379 | | |
362 | 380 | | |
363 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
364 | 385 | | |
365 | 386 | | |
366 | 387 | | |
| |||
0 commit comments