Skip to content

Commit e19ee34

Browse files
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

File tree

app/components/UI/Perps/Views/PerpsAdjustMarginView/PerpsAdjustMarginView.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
PRICE_RANGES_UNIVERSAL,
4141
PRICE_RANGES_MINIMAL_VIEW,
4242
} from '../../utils/formatUtils';
43+
import { PERPS_CONSTANTS } from '../../constants/perpsConfig';
4344

4445
interface AdjustMarginRouteParams {
4546
position: Position;
@@ -152,6 +153,17 @@ const PerpsAdjustMarginView: React.FC = () => {
152153
setSelectedTooltip(null);
153154
}, []);
154155

156+
// Helper to format liquidation distance with fallback when liquidation price is unavailable
157+
const formatLiquidationDistance = useCallback(
158+
(distance: number, liquidationPrice: number): string => {
159+
if (liquidationPrice === 0) {
160+
return PERPS_CONSTANTS.FALLBACK_DATA_DISPLAY;
161+
}
162+
return `${distance.toFixed(0)}%`;
163+
},
164+
[],
165+
);
166+
155167
const handleConfirm = useCallback(async () => {
156168
if (marginAmount <= 0 || !position) return;
157169

@@ -347,20 +359,29 @@ const PerpsAdjustMarginView: React.FC = () => {
347359
variant={TextVariant.BodyMD}
348360
color={TextColor.Alternative}
349361
>
350-
{currentLiquidationDistance.toFixed(0)}%
362+
{formatLiquidationDistance(
363+
currentLiquidationDistance,
364+
currentLiquidationPrice,
365+
)}
351366
</Text>
352367
<Icon
353368
name={IconName.Arrow2Right}
354369
size={IconSize.Sm}
355370
color={colors.icon.alternative}
356371
/>
357372
<Text variant={TextVariant.BodyMD}>
358-
{newLiquidationDistance.toFixed(0)}%
373+
{formatLiquidationDistance(
374+
newLiquidationDistance,
375+
newLiquidationPrice,
376+
)}
359377
</Text>
360378
</View>
361379
) : (
362380
<Text variant={TextVariant.BodyMD}>
363-
{currentLiquidationDistance.toFixed(0)}%
381+
{formatLiquidationDistance(
382+
currentLiquidationDistance,
383+
currentLiquidationPrice,
384+
)}
364385
</Text>
365386
)}
366387
</View>

0 commit comments

Comments
 (0)