chore: replace Order type with existing OrderSubmissionBody['orderSubission'] (#1518)
* chore: replace Order type with existing OrderSubmissionBody['orderSubmission'] * chore: drop WithMarket from Order, Trade and Fill types * chore: fix order list mock
This commit is contained in:
parent
edb31e0f46
commit
9486db134c
@ -11,7 +11,7 @@ import {
|
||||
import { InputError } from '@vegaprotocol/ui-toolkit';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import { MarketSelector } from '@vegaprotocol/deal-ticket';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { useVegaWallet, VegaTxStatus } from '@vegaprotocol/wallet';
|
||||
import {
|
||||
t,
|
||||
@ -61,7 +61,7 @@ export const DealTicketSteps = ({
|
||||
watch,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm<Order>({
|
||||
} = useForm<OrderSubmissionBody['orderSubmission']>({
|
||||
mode: 'onChange',
|
||||
defaultValues: getDefaultOrder(market),
|
||||
});
|
||||
@ -205,7 +205,7 @@ export const DealTicketSteps = ({
|
||||
);
|
||||
|
||||
const onSubmit = useCallback(
|
||||
(order: Order) => {
|
||||
(order: OrderSubmissionBody['orderSubmission']) => {
|
||||
if (transactionStatus !== 'pending') {
|
||||
submit({
|
||||
...order,
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import type { DealTicketMarketFragment } from '@vegaprotocol/deal-ticket';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { SIDE_NAMES } from './side-selector';
|
||||
import SimpleMarketExpires from '../simple-market-list/simple-market-expires';
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
@ -36,7 +36,7 @@ interface Props {
|
||||
market: DealTicketMarketFragment;
|
||||
isDisabled: boolean;
|
||||
transactionStatus?: string;
|
||||
order: Order;
|
||||
order: OrderSubmissionBody['orderSubmission'];
|
||||
estCloseOut: string;
|
||||
estMargin: string;
|
||||
quoteName: string;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useRef } from 'react';
|
||||
import { useOutletContext } from 'react-router-dom';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import type { TradeWithMarket } from '@vegaprotocol/fills';
|
||||
import type { Trade } from '@vegaprotocol/fills';
|
||||
import { useFillsList } from '@vegaprotocol/fills';
|
||||
import type { BodyScrollEndEvent, BodyScrollEvent } from 'ag-grid-community';
|
||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||
@ -37,7 +37,7 @@ const FillsManager = () => {
|
||||
data={data?.length ? data : null}
|
||||
noDataMessage={NO_DATA_MESSAGE}
|
||||
>
|
||||
<ConsoleLiteGrid<TradeWithMarket>
|
||||
<ConsoleLiteGrid<Trade>
|
||||
ref={gridRef}
|
||||
rowModelType="infinite"
|
||||
datasource={{ getRows }}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from 'react';
|
||||
import type { ColDef, ValueFormatterParams } from 'ag-grid-community';
|
||||
import type { TradeWithMarket } from '@vegaprotocol/fills';
|
||||
import type { Trade } from '@vegaprotocol/fills';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
addDecimal,
|
||||
@ -34,7 +34,7 @@ const useColumnDefinitions = ({ partyId }: Props) => {
|
||||
headerClass: 'uppercase',
|
||||
field: 'size',
|
||||
width: 100,
|
||||
cellClass: ({ data }: { data: TradeWithMarket }) => {
|
||||
cellClass: ({ data }: { data: Trade }) => {
|
||||
return classNames('!flex h-full items-center justify-center', {
|
||||
[positiveClassNames]: data?.buyer.id === partyId,
|
||||
[negativeClassNames]: data?.seller.id,
|
||||
|
@ -2,7 +2,7 @@ import { useRef, useState } from 'react';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import type { BodyScrollEndEvent, BodyScrollEvent } from 'ag-grid-community';
|
||||
import { useOutletContext } from 'react-router-dom';
|
||||
import type { OrderWithMarket } from '@vegaprotocol/orders';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import {
|
||||
useOrderCancel,
|
||||
useOrderListData,
|
||||
@ -20,7 +20,7 @@ import useColumnDefinitions from './use-column-definitions';
|
||||
|
||||
const OrdersManager = () => {
|
||||
const { partyId } = useOutletContext<{ partyId: string }>();
|
||||
const [editOrder, setEditOrder] = useState<OrderWithMarket | null>(null);
|
||||
const [editOrder, setEditOrder] = useState<Order | null>(null);
|
||||
const orderCancel = useOrderCancel();
|
||||
const orderEdit = useOrderEdit(editOrder);
|
||||
const { columnDefs, defaultColDef } = useColumnDefinitions({
|
||||
@ -54,7 +54,7 @@ const OrdersManager = () => {
|
||||
data={data?.length ? data : null}
|
||||
noDataMessage={NO_DATA_MESSAGE}
|
||||
>
|
||||
<ConsoleLiteGrid<OrderWithMarket>
|
||||
<ConsoleLiteGrid<Order>
|
||||
ref={gridRef}
|
||||
rowModelType={data?.length ? 'infinite' : 'clientSide'}
|
||||
rowData={data?.length ? undefined : []}
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
} from '@vegaprotocol/react-helpers';
|
||||
import type {
|
||||
Orders_party_ordersConnection_edges_node,
|
||||
OrderWithMarket,
|
||||
Order,
|
||||
CancelOrderArgs,
|
||||
} from '@vegaprotocol/orders';
|
||||
import { isOrderActive } from '@vegaprotocol/orders';
|
||||
@ -35,7 +35,7 @@ type StatusKey = keyof typeof OrderStatusMapping;
|
||||
type RejectReasonKey = keyof typeof OrderRejectionReasonMapping;
|
||||
type OrderTimeKey = keyof typeof OrderTimeInForceMapping;
|
||||
interface Props {
|
||||
setEditOrder: (order: OrderWithMarket) => void;
|
||||
setEditOrder: (order: Order) => void;
|
||||
orderCancel: {
|
||||
cancel: (args: CancelOrderArgs) => void;
|
||||
[key: string]: unknown;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import useCalculateSlippage from './use-calculate-slippage';
|
||||
|
||||
const mockData = {
|
||||
@ -84,7 +84,10 @@ describe('useCalculateSlippage Hook', () => {
|
||||
() =>
|
||||
useCalculateSlippage({
|
||||
marketId: 'marketId',
|
||||
order: { size: '10', side: Side.SIDE_BUY } as Order,
|
||||
order: {
|
||||
size: '10',
|
||||
side: Side.SIDE_BUY,
|
||||
} as OrderSubmissionBody['orderSubmission'],
|
||||
}),
|
||||
{
|
||||
wrapper: MockedProvider,
|
||||
@ -98,7 +101,10 @@ describe('useCalculateSlippage Hook', () => {
|
||||
() =>
|
||||
useCalculateSlippage({
|
||||
marketId: 'marketId',
|
||||
order: { size: '10', side: Side.SIDE_SELL } as Order,
|
||||
order: {
|
||||
size: '10',
|
||||
side: Side.SIDE_SELL,
|
||||
} as OrderSubmissionBody['orderSubmission'],
|
||||
}),
|
||||
{
|
||||
wrapper: MockedProvider,
|
||||
@ -121,7 +127,10 @@ describe('useCalculateSlippage Hook', () => {
|
||||
() =>
|
||||
useCalculateSlippage({
|
||||
marketId: 'marketId',
|
||||
order: { size: '10', side: Side.SIDE_SELL } as Order,
|
||||
order: {
|
||||
size: '10',
|
||||
side: Side.SIDE_SELL,
|
||||
} as OrderSubmissionBody['orderSubmission'],
|
||||
}),
|
||||
{
|
||||
wrapper: MockedProvider,
|
||||
|
@ -3,7 +3,7 @@ import { Side } from '@vegaprotocol/types';
|
||||
import { useOrderBookData } from '@vegaprotocol/market-depth';
|
||||
import { marketProvider } from '@vegaprotocol/market-list';
|
||||
import type { Market } from '@vegaprotocol/market-list';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import {
|
||||
formatNumber,
|
||||
@ -13,7 +13,7 @@ import {
|
||||
|
||||
interface Props {
|
||||
marketId: string;
|
||||
order: Order;
|
||||
order: OrderSubmissionBody['orderSubmission'];
|
||||
}
|
||||
|
||||
const useCalculateSlippage = ({ marketId, order }: Props) => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import useMarketPositions from './use-market-positions';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import type { PartyBalanceQuery_party_accounts } from '../components/deal-ticket/__generated__/PartyBalanceQuery';
|
||||
import { useSettlementAccount } from './use-settlement-account';
|
||||
import { AccountType, Side } from '@vegaprotocol/types';
|
||||
@ -11,7 +11,7 @@ interface Props {
|
||||
marketId: string;
|
||||
price?: string;
|
||||
settlementAssetId: string;
|
||||
order: Order;
|
||||
order: OrderSubmissionBody['orderSubmission'];
|
||||
}
|
||||
|
||||
const getSize = (balance: string, price: string) =>
|
||||
|
@ -2,7 +2,7 @@ import * as React from 'react';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import useOrderCloseOut from './use-order-closeout';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import type { DealTicketMarketFragment } from '@vegaprotocol/deal-ticket';
|
||||
import type { PartyBalanceQuery } from '../components/deal-ticket/__generated__/PartyBalanceQuery';
|
||||
|
||||
@ -48,7 +48,7 @@ describe('useOrderCloseOut Hook', () => {
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
useOrderCloseOut({
|
||||
order: order as Order,
|
||||
order: order as OrderSubmissionBody['orderSubmission'],
|
||||
market: market as DealTicketMarketFragment,
|
||||
partyData: partyData as PartyBalanceQuery,
|
||||
}),
|
||||
@ -65,7 +65,10 @@ describe('useOrderCloseOut Hook', () => {
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
useOrderCloseOut({
|
||||
order: { ...order, side: 'SIDE_SELL' } as Order,
|
||||
order: {
|
||||
...order,
|
||||
side: 'SIDE_SELL',
|
||||
} as OrderSubmissionBody['orderSubmission'],
|
||||
market: market as DealTicketMarketFragment,
|
||||
partyData: partyData as PartyBalanceQuery,
|
||||
}),
|
||||
@ -82,7 +85,10 @@ describe('useOrderCloseOut Hook', () => {
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
useOrderCloseOut({
|
||||
order: { ...order, side: 'SIDE_SELL' } as Order,
|
||||
order: {
|
||||
...order,
|
||||
side: 'SIDE_SELL',
|
||||
} as OrderSubmissionBody['orderSubmission'],
|
||||
market: market as DealTicketMarketFragment,
|
||||
}),
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import type { DealTicketMarketFragment } from '@vegaprotocol/deal-ticket';
|
||||
import type { PartyBalanceQuery } from '../components/deal-ticket/__generated__/PartyBalanceQuery';
|
||||
import { useSettlementAccount } from './use-settlement-account';
|
||||
@ -46,7 +46,7 @@ const CLOSEOUT_PRICE_QUERY = gql`
|
||||
`;
|
||||
|
||||
interface Props {
|
||||
order: Order;
|
||||
order: OrderSubmissionBody['orderSubmission'];
|
||||
market: DealTicketMarketFragment;
|
||||
partyData?: PartyBalanceQuery;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import type { DealTicketMarketFragment } from '@vegaprotocol/deal-ticket';
|
||||
import type { PositionMargin } from './use-market-positions';
|
||||
import useOrderMargin from './use-order-margin';
|
||||
@ -53,7 +53,7 @@ describe('useOrderMargin Hook', () => {
|
||||
it('margin should be properly calculated', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useOrderMargin({
|
||||
order: order as Order,
|
||||
order: order as OrderSubmissionBody['orderSubmission'],
|
||||
market: market as DealTicketMarketFragment,
|
||||
partyId,
|
||||
})
|
||||
@ -71,7 +71,7 @@ describe('useOrderMargin Hook', () => {
|
||||
it('fees should be properly calculated', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useOrderMargin({
|
||||
order: order as Order,
|
||||
order: order as OrderSubmissionBody['orderSubmission'],
|
||||
market: market as DealTicketMarketFragment,
|
||||
partyId,
|
||||
})
|
||||
@ -83,7 +83,7 @@ describe('useOrderMargin Hook', () => {
|
||||
mockMarketPositions = null;
|
||||
const { result } = renderHook(() =>
|
||||
useOrderMargin({
|
||||
order: order as Order,
|
||||
order: order as OrderSubmissionBody['orderSubmission'],
|
||||
market: market as DealTicketMarketFragment,
|
||||
partyId,
|
||||
})
|
||||
@ -110,7 +110,7 @@ describe('useOrderMargin Hook', () => {
|
||||
};
|
||||
const { result } = renderHook(() =>
|
||||
useOrderMargin({
|
||||
order: order as Order,
|
||||
order: order as OrderSubmissionBody['orderSubmission'],
|
||||
market: market as DealTicketMarketFragment,
|
||||
partyId,
|
||||
})
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import type {
|
||||
EstimateOrder,
|
||||
@ -46,7 +46,7 @@ export const ESTIMATE_ORDER_QUERY = gql`
|
||||
`;
|
||||
|
||||
interface Props {
|
||||
order: Order;
|
||||
order: OrderSubmissionBody['orderSubmission'];
|
||||
market: DealTicketMarketFragment;
|
||||
partyId: string;
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { toDecimal } from '@vegaprotocol/react-helpers';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { OrderTimeInForce, OrderType, Side } from '@vegaprotocol/types';
|
||||
|
||||
export const getDefaultOrder = (market: {
|
||||
id: string;
|
||||
positionDecimalPlaces: number;
|
||||
}): Order => ({
|
||||
}): OrderSubmissionBody['orderSubmission'] => ({
|
||||
marketId: market.id,
|
||||
type: OrderType.TYPE_MARKET,
|
||||
side: Side.SIDE_BUY,
|
||||
|
@ -10,8 +10,8 @@ import {
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { Tooltip } from '@vegaprotocol/ui-toolkit';
|
||||
import type { Order } from './get-default-order';
|
||||
import { ERROR_SIZE_DECIMAL } from './validate-size';
|
||||
import { MarketDataGrid } from '../trading-mode-tooltip';
|
||||
import { compileGridData } from '../trading-mode-tooltip/compile-grid-data';
|
||||
@ -30,7 +30,7 @@ export type ValidationProps = {
|
||||
market: DealTicketMarketFragment;
|
||||
orderType: OrderType;
|
||||
orderTimeInForce: OrderTimeInForce;
|
||||
fieldErrors?: FieldErrors<Order>;
|
||||
fieldErrors?: FieldErrors<OrderSubmissionBody['orderSubmission']>;
|
||||
};
|
||||
|
||||
export const marketTranslations = (marketState: MarketState) => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { UseFormRegister } from 'react-hook-form';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { DealTicketMarketAmount } from './deal-ticket-market-amount';
|
||||
import { DealTicketLimitAmount } from './deal-ticket-limit-amount';
|
||||
import type { DealTicketMarketFragment } from './__generated__/DealTicket';
|
||||
@ -8,7 +8,7 @@ import { Schema } from '@vegaprotocol/types';
|
||||
export interface DealTicketAmountProps {
|
||||
orderType: Schema.OrderType;
|
||||
market: DealTicketMarketFragment;
|
||||
register: UseFormRegister<Order>;
|
||||
register: UseFormRegister<OrderSubmissionBody['orderSubmission']>;
|
||||
quoteName: string;
|
||||
price?: string;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import { fireEvent, render, screen, act } from '@testing-library/react';
|
||||
import { DealTicket } from './deal-ticket';
|
||||
import type { DealTicketMarketFragment } from './__generated__/DealTicket';
|
||||
import { Schema } from '@vegaprotocol/types';
|
||||
import type { Order } from '@vegaprotocol/orders';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
|
||||
const market: DealTicketMarketFragment = {
|
||||
__typename: 'Market',
|
||||
@ -43,7 +43,7 @@ const market: DealTicketMarketFragment = {
|
||||
const submit = jest.fn();
|
||||
const transactionStatus = 'default';
|
||||
|
||||
function generateJsx(order?: Order) {
|
||||
function generateJsx(order?: OrderSubmissionBody['orderSubmission']) {
|
||||
return (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
<VegaWalletContext.Provider value={{} as any}>
|
||||
|
@ -12,8 +12,8 @@ import { DealTicketAmount } from './deal-ticket-amount';
|
||||
import { TimeInForceSelector } from './time-in-force-selector';
|
||||
import type { DealTicketMarketFragment } from './__generated__/DealTicket';
|
||||
import { ExpirySelector } from './expiry-selector';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { OrderTimeInForce, OrderType } from '@vegaprotocol/types';
|
||||
import type { Order } from '../deal-ticket-validation';
|
||||
import { getDefaultOrder } from '../deal-ticket-validation';
|
||||
import { useOrderValidation } from '../deal-ticket-validation/use-order-validation';
|
||||
import { MarketTradingMode } from '@vegaprotocol/types';
|
||||
@ -22,9 +22,9 @@ export type TransactionStatus = 'default' | 'pending';
|
||||
|
||||
export interface DealTicketProps {
|
||||
market: DealTicketMarketFragment;
|
||||
submit: (order: Order) => void;
|
||||
submit: (order: OrderSubmissionBody['orderSubmission']) => void;
|
||||
transactionStatus: TransactionStatus;
|
||||
defaultOrder?: Order;
|
||||
defaultOrder?: OrderSubmissionBody['orderSubmission'];
|
||||
}
|
||||
|
||||
export const DealTicket = ({
|
||||
@ -39,7 +39,7 @@ export const DealTicket = ({
|
||||
watch,
|
||||
formState: { errors },
|
||||
setValue,
|
||||
} = useForm<Order>({
|
||||
} = useForm<OrderSubmissionBody['orderSubmission']>({
|
||||
mode: 'onChange',
|
||||
defaultValues: getDefaultOrder(market),
|
||||
});
|
||||
@ -55,7 +55,7 @@ export const DealTicket = ({
|
||||
const isDisabled = transactionStatus === 'pending' || disabled;
|
||||
|
||||
const onSubmit = useCallback(
|
||||
(order: Order) => {
|
||||
(order: OrderSubmissionBody['orderSubmission']) => {
|
||||
if (!isDisabled) {
|
||||
submit({
|
||||
...order,
|
||||
|
@ -3,8 +3,8 @@ import { formatForInput } from '@vegaprotocol/react-helpers';
|
||||
import { t } from '@vegaprotocol/react-helpers';
|
||||
|
||||
interface ExpirySelectorProps {
|
||||
value?: Date;
|
||||
onSelect: (expiration: Date | null) => void;
|
||||
value?: string;
|
||||
onSelect: (expiration: string | null) => void;
|
||||
}
|
||||
|
||||
export const ExpirySelector = ({ value, onSelect }: ExpirySelectorProps) => {
|
||||
@ -19,7 +19,7 @@ export const ExpirySelector = ({ value, onSelect }: ExpirySelectorProps) => {
|
||||
name="expiration"
|
||||
type="datetime-local"
|
||||
value={dateFormatted}
|
||||
onChange={(e) => onSelect(new Date(e.target.value))}
|
||||
onChange={(e) => onSelect(e.target.value)}
|
||||
min={minDate}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
@ -54,11 +54,10 @@ const update = (
|
||||
});
|
||||
};
|
||||
|
||||
export type Trade = FillFieldsFragment;
|
||||
export type TradeWithMarket = Omit<Trade, 'market'> & { market?: Market };
|
||||
export type TradeWithMarketEdge = {
|
||||
export type Trade = Omit<FillFieldsFragment, 'market'> & { market?: Market };
|
||||
export type TradeEdge = {
|
||||
cursor: FillEdgeFragment['cursor'];
|
||||
node: TradeWithMarket;
|
||||
node: Trade;
|
||||
};
|
||||
|
||||
const getData = (responseData: FillsQuery): FillEdgeFragment[] =>
|
||||
@ -84,11 +83,11 @@ export const fillsProvider = makeDataProvider({
|
||||
});
|
||||
|
||||
export const fillsWithMarketProvider = makeDerivedDataProvider<
|
||||
(TradeWithMarketEdge | null)[],
|
||||
TradeWithMarket[]
|
||||
(TradeEdge | null)[],
|
||||
Trade[]
|
||||
>(
|
||||
[fillsProvider, marketsProvider],
|
||||
(partsData): (TradeWithMarketEdge | null)[] =>
|
||||
(partsData): (TradeEdge | null)[] =>
|
||||
(partsData[0] as ReturnType<typeof getData>)?.map(
|
||||
(edge) =>
|
||||
edge && {
|
||||
@ -101,11 +100,11 @@ export const fillsWithMarketProvider = makeDerivedDataProvider<
|
||||
},
|
||||
}
|
||||
) || null,
|
||||
(parts): TradeWithMarket[] | undefined => {
|
||||
(parts): Trade[] | undefined => {
|
||||
if (!parts[0].isUpdate) {
|
||||
return;
|
||||
}
|
||||
// map FillsSub_trades[] from subscription to updated TradeWithMarket[]
|
||||
// map FillsSub_trades[] from subscription to updated Trade[]
|
||||
return (parts[0].delta as ReturnType<typeof getDelta>).map(
|
||||
(deltaTrade) => ({
|
||||
...((parts[0].data as ReturnType<typeof getData>)?.find(
|
||||
|
@ -2,7 +2,7 @@ import { render, screen, waitFor } from '@testing-library/react';
|
||||
import { getDateTimeFormat } from '@vegaprotocol/react-helpers';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
import type { TradeWithMarket } from './fills-data-provider';
|
||||
import type { Trade } from './fills-data-provider';
|
||||
|
||||
import { FillsTable } from './fills-table';
|
||||
import { generateFill } from './test-helpers';
|
||||
@ -21,7 +21,7 @@ const waitForDataToHaveLoaded = () => {
|
||||
};
|
||||
|
||||
describe('FillsTable', () => {
|
||||
let defaultFill: PartialDeep<TradeWithMarket>;
|
||||
let defaultFill: PartialDeep<Trade>;
|
||||
|
||||
beforeEach(() => {
|
||||
defaultFill = {
|
||||
|
@ -15,7 +15,7 @@ import { forwardRef } from 'react';
|
||||
import type { ValueFormatterParams } from 'ag-grid-community';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import type { AgGridReactProps, AgReactUiProps } from 'ag-grid-react';
|
||||
import type { TradeWithMarket } from './fills-data-provider';
|
||||
import type { Trade } from './fills-data-provider';
|
||||
import type { Market } from '@vegaprotocol/market-list';
|
||||
import classNames from 'classnames';
|
||||
|
||||
@ -27,7 +27,7 @@ type AccountsTableValueFormatterParams = Omit<
|
||||
ValueFormatterParams,
|
||||
'data' | 'value'
|
||||
> & {
|
||||
data: TradeWithMarket | null;
|
||||
data: Trade | null;
|
||||
};
|
||||
|
||||
export const FillsTable = forwardRef<AgGridReact, Props>(
|
||||
@ -49,7 +49,7 @@ export const FillsTable = forwardRef<AgGridReact, Props>(
|
||||
headerName={t('Size')}
|
||||
type="rightAligned"
|
||||
field="size"
|
||||
cellClass={({ data }: { data: TradeWithMarket }) => {
|
||||
cellClass={({ data }: { data: Trade }) => {
|
||||
return classNames('text-right', {
|
||||
[positiveClassNames]: data?.buyer.id === partyId,
|
||||
[negativeClassNames]: data?.seller.id,
|
||||
@ -86,7 +86,7 @@ export const FillsTable = forwardRef<AgGridReact, Props>(
|
||||
valueFormatter={({
|
||||
value,
|
||||
}: AccountsTableValueFormatterParams & {
|
||||
value: TradeWithMarket['createdAt'];
|
||||
value: Trade['createdAt'];
|
||||
}) => {
|
||||
if (value === undefined) {
|
||||
return value;
|
||||
@ -103,7 +103,7 @@ const formatPrice = ({
|
||||
value,
|
||||
data,
|
||||
}: AccountsTableValueFormatterParams & {
|
||||
value?: TradeWithMarket['price'];
|
||||
value?: Trade['price'];
|
||||
}) => {
|
||||
if (value === undefined || !data || !data?.market) {
|
||||
return undefined;
|
||||
@ -122,7 +122,7 @@ const formatSize = (partyId: string) => {
|
||||
value,
|
||||
data,
|
||||
}: AccountsTableValueFormatterParams & {
|
||||
value?: TradeWithMarket['size'];
|
||||
value?: Trade['size'];
|
||||
}) => {
|
||||
if (value === undefined || !data || !data?.market) {
|
||||
return undefined;
|
||||
@ -146,7 +146,7 @@ const formatTotal = ({
|
||||
value,
|
||||
data,
|
||||
}: AccountsTableValueFormatterParams & {
|
||||
value?: TradeWithMarket['price'];
|
||||
value?: Trade['price'];
|
||||
}) => {
|
||||
if (value === undefined || !data || !data?.market) {
|
||||
return undefined;
|
||||
@ -168,7 +168,7 @@ const formatRole = (partyId: string) => {
|
||||
value,
|
||||
data,
|
||||
}: AccountsTableValueFormatterParams & {
|
||||
value?: TradeWithMarket['aggressor'];
|
||||
value?: Trade['aggressor'];
|
||||
}) => {
|
||||
if (value === undefined) {
|
||||
return value;
|
||||
|
@ -1,10 +1,10 @@
|
||||
import merge from 'lodash/merge';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
import { MarketState, MarketTradingMode, Side } from '@vegaprotocol/types';
|
||||
import type { TradeWithMarket } from './fills-data-provider';
|
||||
import type { Trade } from './fills-data-provider';
|
||||
|
||||
export const generateFill = (override?: PartialDeep<TradeWithMarket>) => {
|
||||
const defaultFill: TradeWithMarket = {
|
||||
export const generateFill = (override?: PartialDeep<Trade>) => {
|
||||
const defaultFill: Trade = {
|
||||
__typename: 'Trade',
|
||||
id: '0',
|
||||
createdAt: '2005-04-02T19:37:00.000Z',
|
||||
|
@ -2,11 +2,11 @@ import type { AgGridReact } from 'ag-grid-react';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { useFillsList } from './use-fills-list';
|
||||
import type { TradeWithMarketEdge } from './fills-data-provider';
|
||||
import type { TradeEdge } from './fills-data-provider';
|
||||
|
||||
let mockData = null;
|
||||
let mockDataProviderData = {
|
||||
data: mockData as (TradeWithMarketEdge | null)[] | null,
|
||||
data: mockData as (TradeEdge | null)[] | null,
|
||||
error: undefined,
|
||||
loading: true,
|
||||
};
|
||||
@ -61,12 +61,12 @@ describe('useFillsList Hook', () => {
|
||||
node: {
|
||||
id: 'data_id_1',
|
||||
},
|
||||
} as unknown as TradeWithMarketEdge,
|
||||
} as unknown as TradeEdge,
|
||||
{
|
||||
node: {
|
||||
id: 'data_id_2',
|
||||
},
|
||||
} as unknown as TradeWithMarketEdge,
|
||||
} as unknown as TradeEdge,
|
||||
];
|
||||
mockDataProviderData = {
|
||||
...mockDataProviderData,
|
||||
|
@ -5,10 +5,7 @@ import {
|
||||
makeInfiniteScrollGetRows,
|
||||
useDataProvider,
|
||||
} from '@vegaprotocol/react-helpers';
|
||||
import type {
|
||||
TradeWithMarket,
|
||||
TradeWithMarketEdge,
|
||||
} from './fills-data-provider';
|
||||
import type { Trade, TradeEdge } from './fills-data-provider';
|
||||
import { fillsWithMarketProvider } from './fills-data-provider';
|
||||
|
||||
interface Props {
|
||||
@ -18,7 +15,7 @@ interface Props {
|
||||
}
|
||||
|
||||
export const useFillsList = ({ partyId, gridRef, scrolledToTop }: Props) => {
|
||||
const dataRef = useRef<(TradeWithMarketEdge | null)[] | null>(null);
|
||||
const dataRef = useRef<(TradeEdge | null)[] | null>(null);
|
||||
const totalCountRef = useRef<number | undefined>(undefined);
|
||||
const newRows = useRef(0);
|
||||
|
||||
@ -41,8 +38,8 @@ export const useFillsList = ({ partyId, gridRef, scrolledToTop }: Props) => {
|
||||
data,
|
||||
delta,
|
||||
}: {
|
||||
data: (TradeWithMarketEdge | null)[] | null;
|
||||
delta: TradeWithMarket[];
|
||||
data: (TradeEdge | null)[] | null;
|
||||
delta: Trade[];
|
||||
}) => {
|
||||
if (!gridRef.current?.api) {
|
||||
return false;
|
||||
@ -71,7 +68,7 @@ export const useFillsList = ({ partyId, gridRef, scrolledToTop }: Props) => {
|
||||
data,
|
||||
totalCount,
|
||||
}: {
|
||||
data: (TradeWithMarketEdge | null)[] | null;
|
||||
data: (TradeEdge | null)[] | null;
|
||||
totalCount?: number;
|
||||
}) => {
|
||||
dataRef.current = data;
|
||||
@ -84,13 +81,13 @@ export const useFillsList = ({ partyId, gridRef, scrolledToTop }: Props) => {
|
||||
const variables = useMemo(() => ({ partyId }), [partyId]);
|
||||
|
||||
const { data, error, loading, load, totalCount } = useDataProvider<
|
||||
(TradeWithMarketEdge | null)[],
|
||||
TradeWithMarket[]
|
||||
(TradeEdge | null)[],
|
||||
Trade[]
|
||||
>({ dataProvider: fillsWithMarketProvider, update, insert, variables });
|
||||
totalCountRef.current = totalCount;
|
||||
dataRef.current = data;
|
||||
|
||||
const getRows = makeInfiniteScrollGetRows<TradeWithMarketEdge>(
|
||||
const getRows = makeInfiniteScrollGetRows<TradeEdge>(
|
||||
newRows,
|
||||
dataRef,
|
||||
totalCountRef,
|
||||
|
@ -7,11 +7,11 @@ import {
|
||||
OrderType,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { OrderWithMarket } from '../';
|
||||
import type { Order } from '../';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
|
||||
export const generateOrder = (partialOrder?: PartialDeep<OrderWithMarket>) => {
|
||||
const order: OrderWithMarket = {
|
||||
export const generateOrder = (partialOrder?: PartialDeep<Order>) => {
|
||||
const order: Order = {
|
||||
__typename: 'Order',
|
||||
id: 'order-id2',
|
||||
market: {
|
||||
@ -90,7 +90,7 @@ export const marketOrder = generateOrder({
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
});
|
||||
|
||||
export const generateMockOrders = (): OrderWithMarket[] => {
|
||||
export const generateMockOrders = (): Order[] => {
|
||||
return [
|
||||
generateOrder({
|
||||
id: '066468C06549101DAF7BC51099E1412A0067DC08C246B7D8013C9D0CBF1E8EE7',
|
||||
@ -140,6 +140,6 @@ export const generateMockOrders = (): OrderWithMarket[] => {
|
||||
];
|
||||
};
|
||||
|
||||
export const generateOrdersArray = (): OrderWithMarket[] => {
|
||||
export const generateOrdersArray = (): Order[] => {
|
||||
return [marketOrder, limitOrder, ...generateMockOrders()];
|
||||
};
|
||||
|
@ -137,11 +137,11 @@ export const update = (
|
||||
});
|
||||
};
|
||||
|
||||
// #TODO Order name is in conflict with interface defines in use-order-submit
|
||||
type Order = Orders_party_ordersConnection_edges_node;
|
||||
export type OrderWithMarket = Omit<Order, 'market'> & { market?: Market };
|
||||
export type OrderWithMarketEdge = {
|
||||
node: OrderWithMarket;
|
||||
export type Order = Omit<Orders_party_ordersConnection_edges_node, 'market'> & {
|
||||
market?: Market;
|
||||
};
|
||||
export type OrderEdge = {
|
||||
node: Order;
|
||||
cursor: Orders_party_ordersConnection_edges['cursor'];
|
||||
};
|
||||
|
||||
@ -169,11 +169,11 @@ export const ordersProvider = makeDataProvider({
|
||||
});
|
||||
|
||||
export const ordersWithMarketProvider = makeDerivedDataProvider<
|
||||
OrderWithMarketEdge[],
|
||||
OrderWithMarket[]
|
||||
OrderEdge[],
|
||||
Order[]
|
||||
>(
|
||||
[ordersProvider, marketsProvider],
|
||||
(partsData): OrderWithMarketEdge[] =>
|
||||
(partsData): OrderEdge[] =>
|
||||
((partsData[0] as Parameters<typeof update>['0']) || []).map((edge) => ({
|
||||
cursor: edge.cursor,
|
||||
node: {
|
||||
@ -183,11 +183,11 @@ export const ordersWithMarketProvider = makeDerivedDataProvider<
|
||||
),
|
||||
},
|
||||
})),
|
||||
(parts): OrderWithMarket[] | undefined => {
|
||||
(parts): Order[] | undefined => {
|
||||
if (!parts[0].isUpdate) {
|
||||
return;
|
||||
}
|
||||
// map OrderSub_orders[] from subscription to updated OrderWithMarket[]
|
||||
// map OrderSub_orders[] from subscription to updated Order[]
|
||||
return (parts[0].delta as ReturnType<typeof getDelta>).map(
|
||||
(deltaOrder) => ({
|
||||
...((parts[0].data as ReturnType<typeof getData>)?.find(
|
||||
|
@ -2,11 +2,9 @@ import { render, screen } from '@testing-library/react';
|
||||
import { OrderListManager } from './order-list-manager';
|
||||
import * as useDataProviderHook from '@vegaprotocol/react-helpers';
|
||||
import type { Orders_party_ordersConnection_edges_node } from '../';
|
||||
import * as orderListMock from '../';
|
||||
import * as orderListMock from '../order-list/order-list';
|
||||
import { forwardRef } from 'react';
|
||||
|
||||
jest.mock('./order-list');
|
||||
|
||||
it('Renders a loading state while awaiting orders', () => {
|
||||
jest.spyOn(useDataProviderHook, 'useDataProvider').mockReturnValue({
|
||||
data: [],
|
||||
|
@ -3,7 +3,7 @@ import { useRef } from 'react';
|
||||
import type { BodyScrollEvent, BodyScrollEndEvent } from 'ag-grid-community';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
|
||||
import { OrderList } from '../';
|
||||
import { OrderList } from '../order-list/order-list';
|
||||
import { useOrderListData } from './use-order-list-data';
|
||||
|
||||
interface OrderListManagerProps {
|
||||
|
@ -6,7 +6,7 @@ import {
|
||||
useDataProvider,
|
||||
} from '@vegaprotocol/react-helpers';
|
||||
import { ordersWithMarketProvider } from '../';
|
||||
import type { OrderWithMarketEdge, OrderWithMarket } from '../';
|
||||
import type { OrderEdge, Order } from '../';
|
||||
|
||||
interface Props {
|
||||
partyId: string;
|
||||
@ -19,7 +19,7 @@ export const useOrderListData = ({
|
||||
gridRef,
|
||||
scrolledToTop,
|
||||
}: Props) => {
|
||||
const dataRef = useRef<(OrderWithMarketEdge | null)[] | null>(null);
|
||||
const dataRef = useRef<(OrderEdge | null)[] | null>(null);
|
||||
const totalCountRef = useRef<number | undefined>(undefined);
|
||||
const newRows = useRef(0);
|
||||
|
||||
@ -40,13 +40,7 @@ export const useOrderListData = ({
|
||||
}, [gridRef]);
|
||||
|
||||
const update = useCallback(
|
||||
({
|
||||
data,
|
||||
delta,
|
||||
}: {
|
||||
data: (OrderWithMarketEdge | null)[];
|
||||
delta: OrderWithMarket[];
|
||||
}) => {
|
||||
({ data, delta }: { data: (OrderEdge | null)[]; delta: Order[] }) => {
|
||||
if (!gridRef.current?.api) {
|
||||
return false;
|
||||
}
|
||||
@ -74,7 +68,7 @@ export const useOrderListData = ({
|
||||
data,
|
||||
totalCount,
|
||||
}: {
|
||||
data: (OrderWithMarketEdge | null)[];
|
||||
data: (OrderEdge | null)[];
|
||||
totalCount?: number;
|
||||
}) => {
|
||||
dataRef.current = data;
|
||||
@ -93,7 +87,7 @@ export const useOrderListData = ({
|
||||
totalCountRef.current = totalCount;
|
||||
dataRef.current = data;
|
||||
|
||||
const getRows = makeInfiniteScrollGetRows<OrderWithMarketEdge>(
|
||||
const getRows = makeInfiniteScrollGetRows<OrderEdge>(
|
||||
newRows,
|
||||
dataRef,
|
||||
totalCountRef,
|
||||
|
@ -16,12 +16,12 @@ import {
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { OrderTimeInForce } from '@vegaprotocol/types';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import type { OrderWithMarket } from '../order-data-provider';
|
||||
import type { Order } from '../order-data-provider';
|
||||
|
||||
interface OrderEditDialogProps {
|
||||
isOpen: boolean;
|
||||
onChange: (isOpen: boolean) => void;
|
||||
order: OrderWithMarket;
|
||||
order: Order;
|
||||
onSubmit: (fields: FormFields) => void;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import type { VegaTxState } from '@vegaprotocol/wallet';
|
||||
import { VegaTransactionDialog, VegaTxStatus } from '@vegaprotocol/wallet';
|
||||
import { generateOrdersArray } from '../mocks';
|
||||
import { OrderEditDialog } from './order-edit-dialog';
|
||||
import type { OrderWithMarket } from '../order-data-provider';
|
||||
import type { Order } from '../order-data-provider';
|
||||
|
||||
export default {
|
||||
component: OrderList,
|
||||
@ -29,7 +29,7 @@ const Template: Story = (args) => {
|
||||
|
||||
const Template2: Story = (args) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [editOrder, setEditOrder] = useState<OrderWithMarket>();
|
||||
const [editOrder, setEditOrder] = useState<Order>();
|
||||
const cancel = () => {
|
||||
setOpen(!open);
|
||||
return Promise.resolve();
|
||||
|
@ -32,14 +32,14 @@ import BigNumber from 'bignumber.js';
|
||||
import { useOrderCancel } from '../../order-hooks/use-order-cancel';
|
||||
import { useOrderEdit } from '../../order-hooks/use-order-edit';
|
||||
import { OrderEditDialog } from './order-edit-dialog';
|
||||
import type { OrderWithMarket } from '../';
|
||||
import type { Order } from '../';
|
||||
import { OrderFeedback } from '../order-feedback';
|
||||
|
||||
type OrderListProps = AgGridReactProps;
|
||||
|
||||
export const OrderList = forwardRef<AgGridReact, OrderListProps>(
|
||||
(props, ref) => {
|
||||
const [editOrder, setEditOrder] = useState<OrderWithMarket | null>(null);
|
||||
const [editOrder, setEditOrder] = useState<Order | null>(null);
|
||||
const orderCancel = useOrderCancel();
|
||||
const orderEdit = useOrderEdit(editOrder);
|
||||
|
||||
@ -93,8 +93,8 @@ export const OrderList = forwardRef<AgGridReact, OrderListProps>(
|
||||
);
|
||||
|
||||
export type OrderListTableProps = AgGridReactProps & {
|
||||
cancel: (order: OrderWithMarket) => void;
|
||||
setEditOrder: (order: OrderWithMarket) => void;
|
||||
cancel: (order: Order) => void;
|
||||
setEditOrder: (order: Order) => void;
|
||||
};
|
||||
|
||||
export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
@ -119,15 +119,15 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
cellClass="font-mono text-right"
|
||||
type="rightAligned"
|
||||
cellClassRules={{
|
||||
[positiveClassNames]: ({ data }: { data: OrderWithMarket }) =>
|
||||
[positiveClassNames]: ({ data }: { data: Order }) =>
|
||||
data?.side === Side.SIDE_BUY,
|
||||
[negativeClassNames]: ({ data }: { data: OrderWithMarket }) =>
|
||||
[negativeClassNames]: ({ data }: { data: Order }) =>
|
||||
data?.side === Side.SIDE_SELL,
|
||||
}}
|
||||
valueFormatter={({
|
||||
value,
|
||||
data,
|
||||
}: VegaValueFormatterParams<OrderWithMarket, 'size'>) => {
|
||||
}: VegaValueFormatterParams<Order, 'size'>) => {
|
||||
if (!data.market) {
|
||||
return '-';
|
||||
}
|
||||
@ -145,7 +145,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
field="type"
|
||||
valueFormatter={({
|
||||
value,
|
||||
}: VegaValueFormatterParams<OrderWithMarket, 'type'>) => {
|
||||
}: VegaValueFormatterParams<Order, 'type'>) => {
|
||||
if (!value) return '-';
|
||||
return OrderTypeMapping[value];
|
||||
}}
|
||||
@ -155,7 +155,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
valueFormatter={({
|
||||
value,
|
||||
data,
|
||||
}: VegaValueFormatterParams<OrderWithMarket, 'status'>) => {
|
||||
}: VegaValueFormatterParams<Order, 'status'>) => {
|
||||
if (value === OrderStatus.STATUS_REJECTED) {
|
||||
return `${OrderStatusMapping[value]}: ${
|
||||
data.rejectionReason &&
|
||||
@ -173,7 +173,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
valueFormatter={({
|
||||
data,
|
||||
value,
|
||||
}: VegaValueFormatterParams<OrderWithMarket, 'remaining'>) => {
|
||||
}: VegaValueFormatterParams<Order, 'remaining'>) => {
|
||||
if (!data.market) {
|
||||
return '-';
|
||||
}
|
||||
@ -194,7 +194,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
valueFormatter={({
|
||||
value,
|
||||
data,
|
||||
}: VegaValueFormatterParams<OrderWithMarket, 'price'>) => {
|
||||
}: VegaValueFormatterParams<Order, 'price'>) => {
|
||||
if (!data.market || data.type === OrderType.TYPE_MARKET) {
|
||||
return '-';
|
||||
}
|
||||
@ -206,7 +206,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
valueFormatter={({
|
||||
value,
|
||||
data,
|
||||
}: VegaValueFormatterParams<OrderWithMarket, 'timeInForce'>) => {
|
||||
}: VegaValueFormatterParams<Order, 'timeInForce'>) => {
|
||||
if (
|
||||
value === OrderTimeInForce.TIME_IN_FORCE_GTT &&
|
||||
data.expiresAt
|
||||
@ -224,7 +224,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
field="createdAt"
|
||||
valueFormatter={({
|
||||
value,
|
||||
}: VegaValueFormatterParams<OrderWithMarket, 'createdAt'>) => {
|
||||
}: VegaValueFormatterParams<Order, 'createdAt'>) => {
|
||||
return value ? getDateTimeFormat().format(new Date(value)) : value;
|
||||
}}
|
||||
/>
|
||||
@ -232,7 +232,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
field="updatedAt"
|
||||
valueFormatter={({
|
||||
value,
|
||||
}: VegaValueFormatterParams<OrderWithMarket, 'updatedAt'>) => {
|
||||
}: VegaValueFormatterParams<Order, 'updatedAt'>) => {
|
||||
return value ? getDateTimeFormat().format(new Date(value)) : '-';
|
||||
}}
|
||||
/>
|
||||
@ -240,9 +240,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||
colId="amend"
|
||||
headerName=""
|
||||
field="status"
|
||||
cellRenderer={({
|
||||
data,
|
||||
}: VegaICellRendererParams<OrderWithMarket>) => {
|
||||
cellRenderer={({ data }: VegaICellRendererParams<Order>) => {
|
||||
if (isOrderAmendable(data)) {
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
@ -286,7 +284,7 @@ export const isOrderActive = (status: OrderStatus) => {
|
||||
].includes(status);
|
||||
};
|
||||
|
||||
export const isOrderAmendable = (order: OrderWithMarket | undefined) => {
|
||||
export const isOrderAmendable = (order: Order | undefined) => {
|
||||
if (!order || order.peggedOrder || order.liquidityProvision) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { useState, useCallback } from 'react';
|
||||
import { useVegaTransaction, useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import type { OrderEvent_busEvents_event_Order } from './';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import type { OrderWithMarket } from '../components';
|
||||
import type { Order } from '../components';
|
||||
import { useOrderEvent } from './use-order-event';
|
||||
|
||||
// Can only edit price for now
|
||||
@ -11,7 +11,7 @@ export interface EditOrderArgs {
|
||||
price: string;
|
||||
}
|
||||
|
||||
export const useOrderEdit = (order: OrderWithMarket | null) => {
|
||||
export const useOrderEdit = (order: Order | null) => {
|
||||
const { keypair } = useVegaWallet();
|
||||
|
||||
const [updatedOrder, setUpdatedOrder] =
|
||||
@ -51,7 +51,7 @@ export const useOrderEdit = (order: OrderWithMarket | null) => {
|
||||
timeInForce: order.timeInForce,
|
||||
sizeDelta: 0,
|
||||
expiresAt: order.expiresAt
|
||||
? toNanoSeconds(new Date(order.expiresAt)) // Wallet expects timestamp in nanoseconds
|
||||
? toNanoSeconds(order.expiresAt) // Wallet expects timestamp in nanoseconds
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { Order } from './use-order-submit';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { useOrderSubmit } from './use-order-submit';
|
||||
import type { OrderEvent, OrderEvent_busEvents } from './';
|
||||
import { ORDER_EVENT_SUB } from './order-event-query';
|
||||
@ -159,7 +159,7 @@ describe('useOrderSubmit', () => {
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTT,
|
||||
side: Side.SIDE_BUY,
|
||||
price: '123456789',
|
||||
expiresAt: new Date('2022-01-01'),
|
||||
expiresAt: new Date('2022-01-01').toISOString(),
|
||||
};
|
||||
await act(async () => {
|
||||
result.current.submit({ ...order, marketId: defaultMarket.id });
|
||||
@ -197,7 +197,7 @@ describe('useOrderSubmit', () => {
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
price: '123456789',
|
||||
expiresAt: new Date('2022-01-01'),
|
||||
expiresAt: new Date('2022-01-01').toISOString(),
|
||||
};
|
||||
await act(async () => {
|
||||
result.current.submit({ ...order, marketId: defaultMarket.id });
|
||||
@ -235,7 +235,7 @@ describe('useOrderSubmit', () => {
|
||||
keypair: null,
|
||||
});
|
||||
await act(async () => {
|
||||
result.current.submit({} as Order);
|
||||
result.current.submit({} as OrderSubmissionBody['orderSubmission']);
|
||||
});
|
||||
expect(mockSendTx).not.toHaveBeenCalled();
|
||||
});
|
||||
@ -251,7 +251,7 @@ describe('useOrderSubmit', () => {
|
||||
keypair,
|
||||
});
|
||||
await act(async () => {
|
||||
result.current.submit({} as Order);
|
||||
result.current.submit({} as OrderSubmissionBody['orderSubmission']);
|
||||
});
|
||||
expect(mockSendTx).not.toHaveBeenCalled();
|
||||
});
|
||||
|
@ -6,21 +6,11 @@ import { determineId, toNanoSeconds } from '@vegaprotocol/react-helpers';
|
||||
import { useVegaTransaction } from '@vegaprotocol/wallet';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { useOrderEvent } from './use-order-event';
|
||||
import type { Side } from '@vegaprotocol/types';
|
||||
import { OrderTimeInForce } from '@vegaprotocol/types';
|
||||
import { OrderType, OrderStatus } from '@vegaprotocol/types';
|
||||
import { Icon, Intent } from '@vegaprotocol/ui-toolkit';
|
||||
import { t } from '@vegaprotocol/react-helpers';
|
||||
|
||||
export interface Order {
|
||||
marketId: string;
|
||||
type: OrderType;
|
||||
size: string;
|
||||
side: Side;
|
||||
timeInForce: OrderTimeInForce;
|
||||
price?: string;
|
||||
expiresAt?: Date;
|
||||
}
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
|
||||
export const getOrderDialogTitle = (
|
||||
status?: OrderStatus
|
||||
@ -116,7 +106,7 @@ export const useOrderSubmit = () => {
|
||||
}, [resetTransaction]);
|
||||
|
||||
const submit = useCallback(
|
||||
async (order: Order) => {
|
||||
async (order: OrderSubmissionBody['orderSubmission']) => {
|
||||
if (!keypair || !order.side) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
export const toNanoSeconds = (date: Date) => {
|
||||
return date.getTime().toString() + '000000';
|
||||
export const toNanoSeconds = (date: Date | string) => {
|
||||
return new Date(date).getTime().toString() + '000000';
|
||||
};
|
||||
|
@ -8,10 +8,7 @@ import { useCallback, useMemo, useRef } from 'react';
|
||||
import type { BodyScrollEvent, BodyScrollEndEvent } from 'ag-grid-community';
|
||||
import { MAX_TRADES, tradesWithMarketProvider } from './trades-data-provider';
|
||||
import { TradesTable } from './trades-table';
|
||||
import type {
|
||||
TradeWithMarket,
|
||||
TradeWithMarketEdge,
|
||||
} from './trades-data-provider';
|
||||
import type { Trade, TradeEdge } from './trades-data-provider';
|
||||
import type { TradesVariables } from './__generated__/Trades';
|
||||
|
||||
interface TradesContainerProps {
|
||||
@ -20,7 +17,7 @@ interface TradesContainerProps {
|
||||
|
||||
export const TradesContainer = ({ marketId }: TradesContainerProps) => {
|
||||
const gridRef = useRef<AgGridReact | null>(null);
|
||||
const dataRef = useRef<(TradeWithMarketEdge | null)[] | null>(null);
|
||||
const dataRef = useRef<(TradeEdge | null)[] | null>(null);
|
||||
const totalCountRef = useRef<number | undefined>(undefined);
|
||||
const newRows = useRef(0);
|
||||
const scrolledToTop = useRef(true);
|
||||
@ -45,13 +42,7 @@ export const TradesContainer = ({ marketId }: TradesContainerProps) => {
|
||||
}, []);
|
||||
|
||||
const update = useCallback(
|
||||
({
|
||||
data,
|
||||
delta,
|
||||
}: {
|
||||
data: (TradeWithMarketEdge | null)[];
|
||||
delta: TradeWithMarket[];
|
||||
}) => {
|
||||
({ data, delta }: { data: (TradeEdge | null)[]; delta: Trade[] }) => {
|
||||
if (!gridRef.current?.api) {
|
||||
return false;
|
||||
}
|
||||
@ -79,7 +70,7 @@ export const TradesContainer = ({ marketId }: TradesContainerProps) => {
|
||||
data,
|
||||
totalCount,
|
||||
}: {
|
||||
data: (TradeWithMarketEdge | null)[];
|
||||
data: (TradeEdge | null)[];
|
||||
totalCount?: number;
|
||||
}) => {
|
||||
dataRef.current = data;
|
||||
@ -98,7 +89,7 @@ export const TradesContainer = ({ marketId }: TradesContainerProps) => {
|
||||
totalCountRef.current = totalCount;
|
||||
dataRef.current = data;
|
||||
|
||||
const getRows = makeInfiniteScrollGetRows<TradeWithMarketEdge>(
|
||||
const getRows = makeInfiniteScrollGetRows<TradeEdge>(
|
||||
newRows,
|
||||
dataRef,
|
||||
totalCountRef,
|
||||
|
@ -94,11 +94,13 @@ const update = (
|
||||
});
|
||||
};
|
||||
|
||||
export type Trade = Trades_market_tradesConnection_edges_node;
|
||||
export type TradeWithMarket = Omit<Trade, 'market'> & { market?: Market };
|
||||
export type TradeWithMarketEdge = {
|
||||
export type Trade = Omit<
|
||||
Trades_market_tradesConnection_edges_node,
|
||||
'market'
|
||||
> & { market?: Market };
|
||||
export type TradeEdge = {
|
||||
cursor: Trades_market_tradesConnection_edges['cursor'];
|
||||
node: TradeWithMarket;
|
||||
node: Trade;
|
||||
};
|
||||
|
||||
const getData = (
|
||||
@ -126,11 +128,11 @@ export const tradesProvider = makeDataProvider({
|
||||
});
|
||||
|
||||
export const tradesWithMarketProvider = makeDerivedDataProvider<
|
||||
(TradeWithMarketEdge | null)[],
|
||||
TradeWithMarket[]
|
||||
(TradeEdge | null)[],
|
||||
Trade[]
|
||||
>(
|
||||
[tradesProvider, marketsProvider],
|
||||
(partsData): TradeWithMarketEdge[] | null =>
|
||||
(partsData): TradeEdge[] | null =>
|
||||
(partsData[0] as ReturnType<typeof getData>)?.map((edge) => ({
|
||||
cursor: edge.cursor,
|
||||
node: {
|
||||
@ -140,11 +142,11 @@ export const tradesWithMarketProvider = makeDerivedDataProvider<
|
||||
),
|
||||
},
|
||||
})) || null,
|
||||
(parts): TradeWithMarket[] | undefined => {
|
||||
(parts): Trade[] | undefined => {
|
||||
if (!parts[0].isUpdate) {
|
||||
return;
|
||||
}
|
||||
// map FillsSub_trades[] from subscription to updated TradeWithMarket[]
|
||||
// map FillsSub_trades[] from subscription to updated Trade[]
|
||||
return (parts[0].delta as ReturnType<typeof getDelta>).map(
|
||||
(deltaTrade) => ({
|
||||
...((parts[0].data as ReturnType<typeof getData>)?.find(
|
||||
|
@ -11,7 +11,7 @@ import {
|
||||
import type { IDatasource, IGetRowsParams } from 'ag-grid-community';
|
||||
import type { CellClassParams, ValueFormatterParams } from 'ag-grid-community';
|
||||
import type { AgGridReactProps } from 'ag-grid-react';
|
||||
import type { TradeWithMarket } from './trades-data-provider';
|
||||
import type { Trade } from './trades-data-provider';
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
export const UP_CLASS = 'text-vega-green-dark dark:text-vega-green';
|
||||
@ -39,10 +39,7 @@ const changeCellClass =
|
||||
};
|
||||
|
||||
export interface GetRowsParams extends Omit<IGetRowsParams, 'successCallback'> {
|
||||
successCallback(
|
||||
rowsThisBlock: (TradeWithMarket | null)[],
|
||||
lastRow?: number
|
||||
): void;
|
||||
successCallback(rowsThisBlock: (Trade | null)[], lastRow?: number): void;
|
||||
}
|
||||
|
||||
export interface Datasource extends IDatasource {
|
||||
@ -50,7 +47,7 @@ export interface Datasource extends IDatasource {
|
||||
}
|
||||
|
||||
interface Props extends AgGridReactProps {
|
||||
rowData?: TradeWithMarket[] | null;
|
||||
rowData?: Trade[] | null;
|
||||
datasource?: Datasource;
|
||||
}
|
||||
|
||||
@ -58,7 +55,7 @@ type TradesTableValueFormatterParams = Omit<
|
||||
ValueFormatterParams,
|
||||
'data' | 'value'
|
||||
> & {
|
||||
data: TradeWithMarket | null;
|
||||
data: Trade | null;
|
||||
};
|
||||
|
||||
export const TradesTable = forwardRef<AgGridReact, Props>((props, ref) => {
|
||||
@ -83,7 +80,7 @@ export const TradesTable = forwardRef<AgGridReact, Props>((props, ref) => {
|
||||
value,
|
||||
data,
|
||||
}: TradesTableValueFormatterParams & {
|
||||
value: TradeWithMarket['price'];
|
||||
value: Trade['price'];
|
||||
}) => {
|
||||
if (!data?.market) {
|
||||
return null;
|
||||
@ -100,7 +97,7 @@ export const TradesTable = forwardRef<AgGridReact, Props>((props, ref) => {
|
||||
value,
|
||||
data,
|
||||
}: TradesTableValueFormatterParams & {
|
||||
value: TradeWithMarket['size'];
|
||||
value: Trade['size'];
|
||||
}) => {
|
||||
if (!data?.market) {
|
||||
return null;
|
||||
@ -116,7 +113,7 @@ export const TradesTable = forwardRef<AgGridReact, Props>((props, ref) => {
|
||||
valueFormatter={({
|
||||
value,
|
||||
}: TradesTableValueFormatterParams & {
|
||||
value: TradeWithMarket['createdAt'];
|
||||
value: Trade['createdAt'];
|
||||
}) => {
|
||||
return value && getDateTimeFormat().format(new Date(value));
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user