Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ jest.mock('../../../../../../locales/i18n', () => ({
jest.mock('../../components/PerpsTokenLogo', () => 'PerpsTokenLogo');

jest.mock('../../utils/formatUtils', () => ({
formatPerpsFiat: jest.fn((value) => `$${value.toFixed(2)}`),
formatPerpsFiat: jest.fn((value, options) =>
options?.ranges === 'universal-ranges'
? `$${value.toString()}`
: `$${value.toFixed(2)}`,
),
formatPositionSize: jest.fn((value) => value.toFixed(4)),
formatOrderCardDate: jest.fn(() => 'Nov 25, 2025'),
PRICE_RANGES_UNIVERSAL: 'universal-ranges',
}));

// Mock component-library Button to be testable
Expand Down Expand Up @@ -295,11 +300,27 @@ describe('PerpsOrderDetailsView', () => {
expect(screen.getByText('perps.order_details.no')).toBeOnTheScreen();
});

it('renders limit price with market precision ranges', () => {
const chipOrder: Order = {
...mockOrder,
symbol: 'CHIP',
price: '0.001234',
};
mockRouteParams = { order: chipOrder };

render(<PerpsOrderDetailsView />);

expect(screen.getByText('$0.001234')).toBeOnTheScreen();
});

it('renders price below trigger condition for short take-profit orders', () => {
const { strings } = jest.requireMock('../../../../../../locales/i18n');
const triggerOrder: Order = {
...mockOrder,
isTrigger: true,
triggerPrice: '51000',
symbol: 'CHIP',
triggerPrice: '0.001234',
price: '0.0012',
detailedOrderType: 'Take Profit Limit',
reduceOnly: true,
side: 'buy',
Expand All @@ -314,7 +335,10 @@ describe('PerpsOrderDetailsView', () => {
expect(
screen.getByText('perps.order_details.price_below'),
).toBeOnTheScreen();
expect(screen.getByText('$50000.00')).toBeOnTheScreen();
expect(strings).toHaveBeenCalledWith('perps.order_details.price_below', {
price: '$0.001234',
});
expect(screen.getByText('$0.0012')).toBeOnTheScreen();
expect(screen.getByText('perps.order_details.yes')).toBeOnTheScreen();
});

Expand Down Expand Up @@ -415,7 +439,7 @@ describe('PerpsOrderDetailsView', () => {

render(<PerpsOrderDetailsView />);

expect(screen.getByText('$100.00')).toBeOnTheScreen();
expect(screen.getByText('$100')).toBeOnTheScreen();
expect(screen.getByText('$200.00')).toBeOnTheScreen();
expect(screen.queryByText('$160.00')).not.toBeOnTheScreen();
});
Expand Down Expand Up @@ -529,8 +553,8 @@ describe('PerpsOrderDetailsView', () => {
screen.getByText('perps.order_details.take_profit'),
).toBeOnTheScreen();
expect(screen.getByText('perps.order_details.stop_loss')).toBeOnTheScreen();
expect(screen.getByText('$52000.00')).toBeOnTheScreen();
expect(screen.getByText('$48000.00')).toBeOnTheScreen();
expect(screen.getByText('$52000')).toBeOnTheScreen();
expect(screen.getByText('$48000')).toBeOnTheScreen();
});

it('hides take profit and stop loss rows when prices are not available', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
formatPerpsFiat,
formatPositionSize,
formatOrderCardDate,
PRICE_RANGES_UNIVERSAL,
} from '../../utils/formatUtils';
import {
formatOrderLabel,
Expand Down Expand Up @@ -131,11 +132,15 @@ const PerpsOrderDetailsView: React.FC = () => {
const priceText =
isMarketExecution || validOrderPrice === null
? strings('perps.order_details.market')
: formatPerpsFiat(validOrderPrice);
: formatPerpsFiat(validOrderPrice, {
ranges: PRICE_RANGES_UNIVERSAL,
});

let triggerCondition: string | undefined;
if (order.isTrigger && validTriggerPrice !== null) {
const formattedTriggerPrice = formatPerpsFiat(validTriggerPrice);
const formattedTriggerPrice = formatPerpsFiat(validTriggerPrice, {
ranges: PRICE_RANGES_UNIVERSAL,
});
const conditionKey = inferTriggerConditionKey({
detailedOrderType: order.detailedOrderType,
side: order.side,
Expand Down Expand Up @@ -175,10 +180,14 @@ const PerpsOrderDetailsView: React.FC = () => {
? strings('perps.order_details.yes')
: strings('perps.order_details.no'),
takeProfitPriceText: hasTakeProfitPrice
? formatPerpsFiat(parsedTakeProfitPrice)
? formatPerpsFiat(parsedTakeProfitPrice, {
ranges: PRICE_RANGES_UNIVERSAL,
})
: undefined,
stopLossPriceText: hasStopLossPrice
? formatPerpsFiat(parsedStopLossPrice)
? formatPerpsFiat(parsedStopLossPrice, {
ranges: PRICE_RANGES_UNIVERSAL,
})
: undefined,
};
}, [order, priceMetrics]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jest.mock('../../utils/formatUtils', () => ({
formatPositionSize: jest.fn((value) => value),
formatPerpsFiat: jest.fn((value) => `$${value.toFixed(2)}`),
PRICE_RANGES_MINIMAL_VIEW: {},
PRICE_RANGES_UNIVERSAL: 'universal-ranges',
}));

jest.mock('@metamask/perps-controller', () => ({
Expand Down Expand Up @@ -111,7 +112,9 @@ describe('PerpsCompactOrderRow', () => {
const { formatPerpsFiat } = jest.requireMock('../../utils/formatUtils');
render(<PerpsCompactOrderRow order={mockTriggerOrder} />);

expect(formatPerpsFiat).toHaveBeenCalledWith(47000, expect.any(Object));
expect(formatPerpsFiat).toHaveBeenCalledWith(47000, {
ranges: 'universal-ranges',
});
});

it('falls back to order price for trigger-market orders when trigger price is invalid', () => {
Expand All @@ -128,7 +131,9 @@ describe('PerpsCompactOrderRow', () => {
<PerpsCompactOrderRow order={triggerOrderWithInvalidTriggerPrice} />,
);

expect(formatPerpsFiat).toHaveBeenCalledWith(48000, expect.any(Object));
expect(formatPerpsFiat).toHaveBeenCalledWith(48000, {
ranges: 'universal-ranges',
});
expect(screen.getByText('Market price')).toBeOnTheScreen();
expect(screen.queryByText('Trigger price')).toBeNull();
});
Expand All @@ -154,7 +159,9 @@ describe('PerpsCompactOrderRow', () => {
render(<PerpsCompactOrderRow order={mockLimitBuyOrder} />);

// Should have called formatPerpsFiat with the order price value (50000)
expect(formatPerpsFiat).toHaveBeenCalledWith(50000, expect.any(Object));
expect(formatPerpsFiat).toHaveBeenCalledWith(50000, {
ranges: 'universal-ranges',
});
});

it('calls onPress when tapped', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useStyles } from '../../../../../component-library/hooks';
import {
formatPositionSize,
formatPerpsFiat,
PRICE_RANGES_MINIMAL_VIEW,
PRICE_RANGES_UNIVERSAL,
} from '../../utils/formatUtils';
import { getPerpsDisplaySymbol, type Order } from '@metamask/perps-controller';
import { strings } from '../../../../../../locales/i18n';
Expand Down Expand Up @@ -49,7 +49,7 @@ const PerpsCompactOrderRow: React.FC<PerpsCompactOrderRowProps> = ({
const formattedPrice =
priceValue !== null
? formatPerpsFiat(priceValue, {
ranges: PRICE_RANGES_MINIMAL_VIEW,
ranges: PRICE_RANGES_UNIVERSAL,
})
: strings('perps.order.market');

Expand Down
Loading