chore(trading): remove user pnl from closed market list (#4312)
This commit is contained in:
parent
8ff46bab5b
commit
406cf22810
@ -351,12 +351,6 @@ describe('Closed markets', { tags: '@smoke' }, () => {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// 6001-MARK-017
|
|
||||||
cy.get(rowSelector)
|
|
||||||
.first()
|
|
||||||
.find('[col-id="realisedPNL"]')
|
|
||||||
.should('have.text', '-');
|
|
||||||
|
|
||||||
// 6001-MARK-018
|
// 6001-MARK-018
|
||||||
cy.get(rowSelector)
|
cy.get(rowSelector)
|
||||||
.first()
|
.first()
|
||||||
|
@ -2,7 +2,6 @@ import { act, render, screen, within, waitFor } from '@testing-library/react';
|
|||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import { Closed } from './closed';
|
import { Closed } from './closed';
|
||||||
import { MarketStateMapping, PropertyKeyType } from '@vegaprotocol/types';
|
import { MarketStateMapping, PropertyKeyType } from '@vegaprotocol/types';
|
||||||
import { PositionStatus } from '@vegaprotocol/types';
|
|
||||||
import { MarketState } from '@vegaprotocol/types';
|
import { MarketState } from '@vegaprotocol/types';
|
||||||
import { subDays } from 'date-fns';
|
import { subDays } from 'date-fns';
|
||||||
import type { MockedResponse } from '@apollo/client/testing';
|
import type { MockedResponse } from '@apollo/client/testing';
|
||||||
@ -19,11 +18,6 @@ import {
|
|||||||
} from '@vegaprotocol/markets';
|
} from '@vegaprotocol/markets';
|
||||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
||||||
import type {
|
|
||||||
PositionsQuery,
|
|
||||||
PositionFieldsFragment,
|
|
||||||
} from '@vegaprotocol/positions';
|
|
||||||
import { PositionsDocument } from '@vegaprotocol/positions';
|
|
||||||
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
||||||
import {
|
import {
|
||||||
createMarketFragment,
|
createMarketFragment,
|
||||||
@ -161,45 +155,6 @@ describe('Closed', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create mock position
|
|
||||||
const createPosition = (): PositionFieldsFragment => {
|
|
||||||
return {
|
|
||||||
__typename: 'Position' as const,
|
|
||||||
realisedPNL: '1000',
|
|
||||||
unrealisedPNL: '2000',
|
|
||||||
openVolume: '3000',
|
|
||||||
averageEntryPrice: '100',
|
|
||||||
updatedAt: new Date().toISOString(),
|
|
||||||
positionStatus: PositionStatus.POSITION_STATUS_UNSPECIFIED,
|
|
||||||
lossSocializationAmount: '1000',
|
|
||||||
market: {
|
|
||||||
__typename: 'Market',
|
|
||||||
id: marketId,
|
|
||||||
},
|
|
||||||
party: {
|
|
||||||
__typename: 'Party',
|
|
||||||
id: pubKey,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
const position = createPosition();
|
|
||||||
const positionsMock: MockedResponse<PositionsQuery> = {
|
|
||||||
request: {
|
|
||||||
query: PositionsDocument,
|
|
||||||
variables: {
|
|
||||||
partyIds: [pubKey],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
result: {
|
|
||||||
data: {
|
|
||||||
positions: {
|
|
||||||
__typename: 'PositionConnection',
|
|
||||||
edges: [{ __typename: 'PositionEdge', node: position }],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
originalNow = Date.now;
|
originalNow = Date.now;
|
||||||
Date.now = jest.fn().mockReturnValue(mockNowTimestamp);
|
Date.now = jest.fn().mockReturnValue(mockNowTimestamp);
|
||||||
@ -214,12 +169,7 @@ describe('Closed', () => {
|
|||||||
render(
|
render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<MockedProvider
|
<MockedProvider
|
||||||
mocks={[
|
mocks={[marketsMock, marketsDataMock, oracleDataMock]}
|
||||||
marketsMock,
|
|
||||||
marketsDataMock,
|
|
||||||
positionsMock,
|
|
||||||
oracleDataMock,
|
|
||||||
]}
|
|
||||||
>
|
>
|
||||||
<VegaWalletContext.Provider
|
<VegaWalletContext.Provider
|
||||||
value={{ pubKey } as VegaWalletContextShape}
|
value={{ pubKey } as VegaWalletContextShape}
|
||||||
@ -243,7 +193,6 @@ describe('Closed', () => {
|
|||||||
'Best offer',
|
'Best offer',
|
||||||
'Mark price',
|
'Mark price',
|
||||||
'Settlement price',
|
'Settlement price',
|
||||||
'Realised PNL',
|
|
||||||
'Settlement asset',
|
'Settlement asset',
|
||||||
'', // actions row
|
'', // actions row
|
||||||
];
|
];
|
||||||
@ -266,7 +215,6 @@ describe('Closed', () => {
|
|||||||
addDecimalsFormatNumber(marketsData!.markPrice, market.decimalPlaces),
|
addDecimalsFormatNumber(marketsData!.markPrice, market.decimalPlaces),
|
||||||
/* eslint-enable @typescript-eslint/no-non-null-assertion */
|
/* eslint-enable @typescript-eslint/no-non-null-assertion */
|
||||||
addDecimalsFormatNumber(property.value, market.decimalPlaces),
|
addDecimalsFormatNumber(property.value, market.decimalPlaces),
|
||||||
addDecimalsFormatNumber(position.realisedPNL, market.decimalPlaces),
|
|
||||||
market.tradableInstrument.instrument.product.settlementAsset.symbol,
|
market.tradableInstrument.instrument.product.settlementAsset.symbol,
|
||||||
'', // actions row
|
'', // actions row
|
||||||
];
|
];
|
||||||
@ -327,12 +275,7 @@ describe('Closed', () => {
|
|||||||
render(
|
render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<MockedProvider
|
<MockedProvider
|
||||||
mocks={[
|
mocks={[mixedMarketsMock, marketsDataMock, oracleDataMock]}
|
||||||
mixedMarketsMock,
|
|
||||||
marketsDataMock,
|
|
||||||
positionsMock,
|
|
||||||
oracleDataMock,
|
|
||||||
]}
|
|
||||||
>
|
>
|
||||||
<VegaWalletContext.Provider
|
<VegaWalletContext.Provider
|
||||||
value={{ pubKey } as VegaWalletContextShape}
|
value={{ pubKey } as VegaWalletContextShape}
|
||||||
@ -419,12 +362,7 @@ describe('Closed', () => {
|
|||||||
render(
|
render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<MockedProvider
|
<MockedProvider
|
||||||
mocks={[
|
mocks={[mixedMarketsMock, marketsDataMock, oracleDataMock]}
|
||||||
mixedMarketsMock,
|
|
||||||
marketsDataMock,
|
|
||||||
positionsMock,
|
|
||||||
oracleDataMock,
|
|
||||||
]}
|
|
||||||
>
|
>
|
||||||
<VegaWalletContext.Provider
|
<VegaWalletContext.Provider
|
||||||
value={{ pubKey } as VegaWalletContextShape}
|
value={{ pubKey } as VegaWalletContextShape}
|
||||||
|
@ -16,7 +16,6 @@ import {
|
|||||||
addDecimalsFormatNumber,
|
addDecimalsFormatNumber,
|
||||||
getMarketExpiryDate,
|
getMarketExpiryDate,
|
||||||
} from '@vegaprotocol/utils';
|
} from '@vegaprotocol/utils';
|
||||||
import { usePositionsQuery } from '@vegaprotocol/positions';
|
|
||||||
import type {
|
import type {
|
||||||
DataSourceFilterFragment,
|
DataSourceFilterFragment,
|
||||||
MarketMaybeWithData,
|
MarketMaybeWithData,
|
||||||
@ -26,7 +25,6 @@ import {
|
|||||||
closedMarketsWithDataProvider,
|
closedMarketsWithDataProvider,
|
||||||
marketProvider,
|
marketProvider,
|
||||||
} from '@vegaprotocol/markets';
|
} from '@vegaprotocol/markets';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
|
||||||
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
|
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
|
||||||
import type { ColDef } from 'ag-grid-community';
|
import type { ColDef } from 'ag-grid-community';
|
||||||
import { SettlementDateCell } from './settlement-date-cell';
|
import { SettlementDateCell } from './settlement-date-cell';
|
||||||
@ -53,34 +51,18 @@ interface Row {
|
|||||||
setlementDataSourceFilter: DataSourceFilterFragment | undefined;
|
setlementDataSourceFilter: DataSourceFilterFragment | undefined;
|
||||||
tradingTerminationOracleId: string;
|
tradingTerminationOracleId: string;
|
||||||
settlementAsset: SettlementAsset;
|
settlementAsset: SettlementAsset;
|
||||||
realisedPNL: string | undefined;
|
|
||||||
successorMarketID: string | undefined | null;
|
successorMarketID: string | undefined | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Closed = () => {
|
export const Closed = () => {
|
||||||
const { pubKey } = useVegaWallet();
|
const { data: marketData, error } = useDataProvider({
|
||||||
const {
|
|
||||||
data: marketData,
|
|
||||||
error,
|
|
||||||
reload,
|
|
||||||
} = useDataProvider({
|
|
||||||
dataProvider: closedMarketsWithDataProvider,
|
dataProvider: closedMarketsWithDataProvider,
|
||||||
variables: undefined,
|
variables: undefined,
|
||||||
});
|
});
|
||||||
const { data: positionData } = usePositionsQuery({
|
|
||||||
variables: {
|
|
||||||
partyIds: pubKey ? [pubKey] : [],
|
|
||||||
},
|
|
||||||
skip: !pubKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
// find a position for each market and add the realised pnl to
|
// find a position for each market and add the realised pnl to
|
||||||
// a normalized object
|
// a normalized object
|
||||||
const rowData = compact(marketData).map((market) => {
|
const rowData = compact(marketData).map((market) => {
|
||||||
const position = positionData?.positions?.edges?.find((edge) => {
|
|
||||||
return edge.node.market.id === market.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
const instrument = market.tradableInstrument.instrument;
|
const instrument = market.tradableInstrument.instrument;
|
||||||
|
|
||||||
const spec =
|
const spec =
|
||||||
@ -115,7 +97,6 @@ export const Closed = () => {
|
|||||||
tradingTerminationOracleId:
|
tradingTerminationOracleId:
|
||||||
instrument.product.dataSourceSpecForTradingTermination.id,
|
instrument.product.dataSourceSpecForTradingTermination.id,
|
||||||
settlementAsset: instrument.product.settlementAsset,
|
settlementAsset: instrument.product.settlementAsset,
|
||||||
realisedPNL: position?.node.realisedPNL,
|
|
||||||
successorMarketID: market.successorMarketID,
|
successorMarketID: market.successorMarketID,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -123,7 +104,7 @@ export const Closed = () => {
|
|||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<div className="h-full relative">
|
<div className="h-full relative">
|
||||||
<ClosedMarketsDataGrid rowData={rowData} error={error} reload={reload} />
|
<ClosedMarketsDataGrid rowData={rowData} error={error} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -153,11 +134,9 @@ export const SuccessorMarketRenderer = ({
|
|||||||
const ClosedMarketsDataGrid = ({
|
const ClosedMarketsDataGrid = ({
|
||||||
rowData,
|
rowData,
|
||||||
error,
|
error,
|
||||||
reload,
|
|
||||||
}: {
|
}: {
|
||||||
rowData: Row[];
|
rowData: Row[];
|
||||||
error: Error | undefined;
|
error: Error | undefined;
|
||||||
reload: () => void;
|
|
||||||
}) => {
|
}) => {
|
||||||
const openAssetDialog = useAssetDetailsDialogStore((store) => store.open);
|
const openAssetDialog = useAssetDetailsDialogStore((store) => store.open);
|
||||||
const colDefs = useMemo(() => {
|
const colDefs = useMemo(() => {
|
||||||
@ -289,25 +268,11 @@ const ClosedMarketsDataGrid = ({
|
|||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
headerName: t('Realised PNL'),
|
|
||||||
field: 'realisedPNL',
|
|
||||||
cellClass: 'font-mono ag-right-aligned-cell',
|
|
||||||
type: 'numericColumn',
|
|
||||||
valueFormatter: ({
|
|
||||||
value,
|
|
||||||
data,
|
|
||||||
}: VegaValueFormatterParams<Row, 'realisedPNL'>) => {
|
|
||||||
if (!value || !data) return '-';
|
|
||||||
return addDecimalsFormatNumber(value, data.decimalPlaces);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
headerName: t('Settlement asset'),
|
headerName: t('Settlement asset'),
|
||||||
field: 'settlementAsset',
|
field: 'settlementAsset',
|
||||||
cellRenderer: ({
|
cellRenderer: ({
|
||||||
value,
|
value,
|
||||||
data,
|
|
||||||
}: VegaValueFormatterParams<Row, 'settlementAsset'>) => (
|
}: VegaValueFormatterParams<Row, 'settlementAsset'>) => (
|
||||||
<button
|
<button
|
||||||
className="underline"
|
className="underline"
|
||||||
|
Loading…
Reference in New Issue
Block a user