fix(trading): iceberg order fills (#4460)

This commit is contained in:
m.ray 2023-08-02 16:55:49 +03:00 committed by GitHub
parent d18a0c7e15
commit 674baa1ee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View File

@ -6,7 +6,7 @@ import type { PartialDeep } from 'type-fest';
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
import { VegaWalletContext } from '@vegaprotocol/wallet';
import { MockedProvider } from '@apollo/client/testing';
import type { OrderListTableProps } from '../';
import type { OrderFieldsFragment, OrderListTableProps } from '../';
import { OrderListTable } from '../';
import {
generateOrder,
@ -110,6 +110,39 @@ describe('OrderListTable', () => {
);
});
it('should apply correct formatting applied for an iceberg order', async () => {
const icebergOrder = {
...limitOrder,
icebergOrder: {
__typename: 'IcebergOrder',
minimumVisibleSize: '100',
peakSize: '50',
reservedRemaining: '50',
} as OrderFieldsFragment['icebergOrder'],
};
await act(async () => {
render(generateJsx({ rowData: [icebergOrder] }));
});
const cells = screen.getAllByRole('gridcell');
const expectedValues: string[] = [
icebergOrder.market?.tradableInstrument.instrument.code || '',
'0.05',
'0.10',
Schema.OrderTypeMapping[
icebergOrder.type || Schema.OrderType.TYPE_LIMIT
] + ' (Iceberg)',
Schema.OrderStatusMapping[icebergOrder.status],
'-',
`${
Schema.OrderTimeInForceCode[icebergOrder.timeInForce]
}: ${getDateTimeFormat().format(new Date(icebergOrder.expiresAt ?? ''))}`,
getDateTimeFormat().format(new Date(icebergOrder.createdAt)),
];
expectedValues.forEach((expectedValue, i) =>
expect(cells[i]).toHaveTextContent(expectedValue)
);
});
it('should apply correct formatting for a rejected order', async () => {
const rejectedOrder = {
...marketOrder,

View File

@ -69,6 +69,18 @@ export const OrderListTable = memo<
cellClass: 'font-mono text-right',
type: 'rightAligned',
valueGetter: ({ data }: VegaValueGetterParams<Order>) => {
if (data?.icebergOrder) {
return data?.size && data.market
? toBigNum(
(
BigInt(data.size) -
BigInt(data.remaining) -
BigInt(data.icebergOrder.reservedRemaining)
).toString(),
data.market.positionDecimalPlaces ?? 0
).toNumber()
: undefined;
}
return data?.size && data.market
? toBigNum(
(BigInt(data.size) - BigInt(data.remaining)).toString(),