From fbd01dc1bd50b3e63621becd228e8a02cbe3b724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Thu, 14 Sep 2023 20:18:58 +0200 Subject: [PATCH] fix(trading): use asset decimals to format liquidation price in posions table (#4787) Co-authored-by: Matthew Russell --- .../deal-ticket-stop-order.spec.tsx | 3 +++ libs/positions/src/lib/liquidation-price.tsx | 20 +++++++++++++------ libs/positions/src/lib/positions-table.tsx | 6 +++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-stop-order.spec.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-stop-order.spec.tsx index bdaaf081e..a4c7d1054 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-stop-order.spec.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-stop-order.spec.tsx @@ -84,6 +84,7 @@ const ocoPostfix = (id: string, postfix = true) => (postfix ? `${id}-oco` : id); const mockDataProvider = jest.fn((...args) => ({ data: Array(0), + reload: jest.fn(), })); jest.mock('@vegaprotocol/data-provider', () => ({ ...jest.requireActual('@vegaprotocol/data-provider'), @@ -473,6 +474,7 @@ describe('StopOrder', () => { it('shows limit of active stop orders number', async () => { mockDataProvider.mockReturnValue({ + reload: jest.fn(), data: Array(4), }); render(generateJsx()); @@ -484,6 +486,7 @@ describe('StopOrder', () => { it('counts oco as two orders', async () => { mockDataProvider.mockReturnValue({ + reload: jest.fn(), data: Array(3), }); render(generateJsx()); diff --git a/libs/positions/src/lib/liquidation-price.tsx b/libs/positions/src/lib/liquidation-price.tsx index f5afd0ccb..283dc6d6a 100644 --- a/libs/positions/src/lib/liquidation-price.tsx +++ b/libs/positions/src/lib/liquidation-price.tsx @@ -7,13 +7,21 @@ export const LiquidationPrice = ({ marketId, openVolume, collateralAvailable, - marketDecimalPlaces, + decimalPlaces, + formatDecimals, }: { marketId: string; openVolume: string; collateralAvailable: string; - marketDecimalPlaces: number; + decimalPlaces: number; + formatDecimals: number; }) => { + // NOTE! + // + // The estimate order query API gives us the liquidation price unformatted but expecting to be converted + // using asset decimal placse. + // + // We need to convert it with asset decimals, but display it formatted with market decimals precision until the API changes. const { data: currentData, previousData } = useEstimatePositionQuery({ variables: { marketId, @@ -43,8 +51,8 @@ export const LiquidationPrice = ({ /\..*/, '' ); - worstCase = addDecimalsFormatNumber(worstCase, marketDecimalPlaces); - bestCase = addDecimalsFormatNumber(bestCase, marketDecimalPlaces); + worstCase = addDecimalsFormatNumber(worstCase, decimalPlaces, formatDecimals); + bestCase = addDecimalsFormatNumber(bestCase, decimalPlaces, formatDecimals); return ( {t('Worst case')} - {worstCase} + {worstCase} {t('Best case')} - {bestCase} + {bestCase} diff --git a/libs/positions/src/lib/positions-table.tsx b/libs/positions/src/lib/positions-table.tsx index 8d7d5a652..27804419c 100644 --- a/libs/positions/src/lib/positions-table.tsx +++ b/libs/positions/src/lib/positions-table.tsx @@ -339,12 +339,16 @@ export const PositionsTable = ({ if (!data) { return '-'; } + // The estimate order query API gives us the liquidation price unformatted but expecting + // conversion using asset decimals. We need to convert it with asset decimals, but format + // it with market decimals precision until the API changes. return ( ); },