chore(trading): cherry pick position pnl formatting fix (#4347)
This commit is contained in:
parent
406cf22810
commit
e55cf5ecc6
@ -6,6 +6,7 @@ import type { Position } from './positions-data-providers';
|
|||||||
import * as Schema from '@vegaprotocol/types';
|
import * as Schema from '@vegaprotocol/types';
|
||||||
import { PositionStatus, PositionStatusMapping } from '@vegaprotocol/types';
|
import { PositionStatus, PositionStatusMapping } from '@vegaprotocol/types';
|
||||||
import type { ICellRendererParams } from 'ag-grid-community';
|
import type { ICellRendererParams } from 'ag-grid-community';
|
||||||
|
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
||||||
|
|
||||||
jest.mock('./liquidation-price', () => ({
|
jest.mock('./liquidation-price', () => ({
|
||||||
LiquidationPrice: () => (
|
LiquidationPrice: () => (
|
||||||
@ -19,7 +20,7 @@ const singleRow: Position = {
|
|||||||
assetSymbol: 'BTC',
|
assetSymbol: 'BTC',
|
||||||
averageEntryPrice: '133',
|
averageEntryPrice: '133',
|
||||||
currentLeverage: 1.1,
|
currentLeverage: 1.1,
|
||||||
decimals: 2,
|
decimals: 2, // this is settlementAsset.decimals
|
||||||
quantum: '0.1',
|
quantum: '0.1',
|
||||||
lossSocializationAmount: '0',
|
lossSocializationAmount: '0',
|
||||||
marginAccountBalance: '12345600',
|
marginAccountBalance: '12345600',
|
||||||
@ -177,12 +178,23 @@ it('displays allocated margin', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('displays realised and unrealised PNL', 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 () => {
|
await act(async () => {
|
||||||
render(<PositionsTable rowData={singleRowData} isReadOnly={false} />);
|
render(<PositionsTable rowData={singleRowData} isReadOnly={false} />);
|
||||||
});
|
});
|
||||||
|
|
||||||
const cells = screen.getAllByRole('gridcell');
|
const cells = screen.getAllByRole('gridcell');
|
||||||
expect(cells[9].textContent).toEqual('12.3');
|
expect(cells[9].textContent).toEqual(expectedRealised);
|
||||||
expect(cells[10].textContent).toEqual('45.6');
|
expect(cells[10].textContent).toEqual(expectedUnrealised);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays close button', async () => {
|
it('displays close button', async () => {
|
||||||
|
@ -375,10 +375,7 @@ export const PositionsTable = forwardRef<AgGridReact, Props>(
|
|||||||
}: VegaValueFormatterParams<Position, 'realisedPNL'>) => {
|
}: VegaValueFormatterParams<Position, 'realisedPNL'>) => {
|
||||||
return !data
|
return !data
|
||||||
? ''
|
? ''
|
||||||
: addDecimalsFormatNumber(
|
: addDecimalsFormatNumber(data.realisedPNL, data.decimals);
|
||||||
data.realisedPNL,
|
|
||||||
data.marketDecimalPlaces
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
headerTooltip: t(
|
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.'
|
'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<AgGridReact, Props>(
|
|||||||
valueGetter: ({ data }: VegaValueGetterParams<Position>) => {
|
valueGetter: ({ data }: VegaValueGetterParams<Position>) => {
|
||||||
return !data
|
return !data
|
||||||
? undefined
|
? undefined
|
||||||
: toBigNum(
|
: toBigNum(data.unrealisedPNL, data.decimals).toNumber();
|
||||||
data.unrealisedPNL,
|
|
||||||
data.marketDecimalPlaces
|
|
||||||
).toNumber();
|
|
||||||
},
|
},
|
||||||
valueFormatter: ({
|
valueFormatter: ({
|
||||||
data,
|
data,
|
||||||
}: VegaValueFormatterParams<Position, 'unrealisedPNL'>) =>
|
}: VegaValueFormatterParams<Position, 'unrealisedPNL'>) =>
|
||||||
!data
|
!data
|
||||||
? ''
|
? ''
|
||||||
: addDecimalsFormatNumber(
|
: addDecimalsFormatNumber(data.unrealisedPNL, data.decimals),
|
||||||
data.unrealisedPNL,
|
|
||||||
data.marketDecimalPlaces
|
|
||||||
),
|
|
||||||
headerTooltip: t(
|
headerTooltip: t(
|
||||||
'Unrealised profit is the current profit on your open position. Margin is still allocated to your position.'
|
'Unrealised profit is the current profit on your open position. Margin is still allocated to your position.'
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user