diff --git a/libs/positions/src/lib/positions-table.spec.tsx b/libs/positions/src/lib/positions-table.spec.tsx
index 4cd4d6658..7fa285f04 100644
--- a/libs/positions/src/lib/positions-table.spec.tsx
+++ b/libs/positions/src/lib/positions-table.spec.tsx
@@ -6,6 +6,7 @@ import type { Position } from './positions-data-providers';
import * as Schema from '@vegaprotocol/types';
import { PositionStatus, PositionStatusMapping } from '@vegaprotocol/types';
import type { ICellRendererParams } from 'ag-grid-community';
+import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
jest.mock('./liquidation-price', () => ({
LiquidationPrice: () => (
@@ -19,7 +20,7 @@ const singleRow: Position = {
assetSymbol: 'BTC',
averageEntryPrice: '133',
currentLeverage: 1.1,
- decimals: 2,
+ decimals: 2, // this is settlementAsset.decimals
quantum: '0.1',
lossSocializationAmount: '0',
marginAccountBalance: '12345600',
@@ -177,12 +178,23 @@ it('displays allocated margin', async () => {
});
it('displays realised and unrealised PNL', async () => {
+ // pnl cells should be rendered with asset dps
+ const expectedRealised = addDecimalsFormatNumber(
+ singleRow.realisedPNL,
+ singleRow.decimals
+ );
+ const expectedUnrealised = addDecimalsFormatNumber(
+ singleRow.unrealisedPNL,
+ singleRow.decimals
+ );
+
await act(async () => {
render();
});
+
const cells = screen.getAllByRole('gridcell');
- expect(cells[9].textContent).toEqual('12.3');
- expect(cells[10].textContent).toEqual('45.6');
+ expect(cells[9].textContent).toEqual(expectedRealised);
+ expect(cells[10].textContent).toEqual(expectedUnrealised);
});
it('displays close button', async () => {
diff --git a/libs/positions/src/lib/positions-table.tsx b/libs/positions/src/lib/positions-table.tsx
index 9ce48d269..5abcf64ef 100644
--- a/libs/positions/src/lib/positions-table.tsx
+++ b/libs/positions/src/lib/positions-table.tsx
@@ -375,10 +375,7 @@ export const PositionsTable = forwardRef(
}: VegaValueFormatterParams) => {
return !data
? ''
- : addDecimalsFormatNumber(
- data.realisedPNL,
- data.marketDecimalPlaces
- );
+ : addDecimalsFormatNumber(data.realisedPNL, data.decimals);
},
headerTooltip: t(
'Profit or loss is realised whenever your position is reduced to zero and the margin is released back to your collateral balance. P&L excludes any fees paid.'
@@ -396,20 +393,14 @@ export const PositionsTable = forwardRef(
valueGetter: ({ data }: VegaValueGetterParams) => {
return !data
? undefined
- : toBigNum(
- data.unrealisedPNL,
- data.marketDecimalPlaces
- ).toNumber();
+ : toBigNum(data.unrealisedPNL, data.decimals).toNumber();
},
valueFormatter: ({
data,
}: VegaValueFormatterParams) =>
!data
? ''
- : addDecimalsFormatNumber(
- data.unrealisedPNL,
- data.marketDecimalPlaces
- ),
+ : addDecimalsFormatNumber(data.unrealisedPNL, data.decimals),
headerTooltip: t(
'Unrealised profit is the current profit on your open position. Margin is still allocated to your position.'
),