This commit is contained in:
parent
53d3d5ac1c
commit
4fbd2e5eba
@ -31,7 +31,7 @@ describe('orders list', { tags: '@smoke' }, () => {
|
|||||||
cy.visit('/#/markets/market-0');
|
cy.visit('/#/markets/market-0');
|
||||||
cy.getByTestId('Orders').click();
|
cy.getByTestId('Orders').click();
|
||||||
cy.wait('@Orders').then(() => {
|
cy.wait('@Orders').then(() => {
|
||||||
expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce;
|
expect(subscriptionMocks.OrdersUpdate).to.be.calledTwice;
|
||||||
});
|
});
|
||||||
cy.wait('@Markets');
|
cy.wait('@Markets');
|
||||||
});
|
});
|
||||||
@ -129,7 +129,7 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
|
|||||||
cy.visit('/#/markets/market-0');
|
cy.visit('/#/markets/market-0');
|
||||||
cy.getByTestId('Orders').click();
|
cy.getByTestId('Orders').click();
|
||||||
cy.wait('@Orders').then(() => {
|
cy.wait('@Orders').then(() => {
|
||||||
expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce;
|
expect(subscriptionMocks.OrdersUpdate).to.be.calledTwice;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const orderId = '1234567890';
|
const orderId = '1234567890';
|
||||||
@ -345,7 +345,7 @@ describe('amend and cancel order', { tags: '@smoke' }, () => {
|
|||||||
cy.visit('/#/markets/market-0');
|
cy.visit('/#/markets/market-0');
|
||||||
cy.getByTestId('Orders').click();
|
cy.getByTestId('Orders').click();
|
||||||
cy.wait('@Orders').then(() => {
|
cy.wait('@Orders').then(() => {
|
||||||
expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce;
|
expect(subscriptionMocks.OrdersUpdate).to.be.calledTwice;
|
||||||
});
|
});
|
||||||
cy.mockVegaWalletTransaction();
|
cy.mockVegaWalletTransaction();
|
||||||
});
|
});
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
} from '../mocks/generate-orders';
|
} from '../mocks/generate-orders';
|
||||||
|
|
||||||
const defaultProps: OrderListTableProps = {
|
const defaultProps: OrderListTableProps = {
|
||||||
|
hasActiveOrder: true,
|
||||||
rowData: [],
|
rowData: [],
|
||||||
setEditOrder: jest.fn(),
|
setEditOrder: jest.fn(),
|
||||||
cancel: jest.fn(),
|
cancel: jest.fn(),
|
||||||
|
@ -17,6 +17,7 @@ const Template: Story = (args) => {
|
|||||||
return (
|
return (
|
||||||
<div style={{ height: 1000 }}>
|
<div style={{ height: 1000 }}>
|
||||||
<OrderListTable
|
<OrderListTable
|
||||||
|
hasActiveOrder
|
||||||
rowData={args.data}
|
rowData={args.data}
|
||||||
cancel={cancel}
|
cancel={cancel}
|
||||||
cancelAll={cancel}
|
cancelAll={cancel}
|
||||||
@ -46,6 +47,7 @@ const Template2: Story = (args) => {
|
|||||||
<>
|
<>
|
||||||
<div style={{ height: 1000 }}>
|
<div style={{ height: 1000 }}>
|
||||||
<OrderListTable
|
<OrderListTable
|
||||||
|
hasActiveOrder
|
||||||
rowData={args.data}
|
rowData={args.data}
|
||||||
cancel={cancel}
|
cancel={cancel}
|
||||||
cancelAll={cancel}
|
cancelAll={cancel}
|
||||||
|
@ -24,6 +24,7 @@ import BigNumber from 'bignumber.js';
|
|||||||
import { forwardRef, useState } from 'react';
|
import { forwardRef, useState } from 'react';
|
||||||
import type { TypedDataAgGrid } from '@vegaprotocol/ui-toolkit';
|
import type { TypedDataAgGrid } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useOrderCancel } from '../../order-hooks/use-order-cancel';
|
import { useOrderCancel } from '../../order-hooks/use-order-cancel';
|
||||||
|
import { useHasActiveOrder } from '../../order-hooks/use-has-active-order';
|
||||||
import { useOrderEdit } from '../../order-hooks/use-order-edit';
|
import { useOrderEdit } from '../../order-hooks/use-order-edit';
|
||||||
import { OrderFeedback } from '../order-feedback';
|
import { OrderFeedback } from '../order-feedback';
|
||||||
import { OrderEditDialog } from './order-edit-dialog';
|
import { OrderEditDialog } from './order-edit-dialog';
|
||||||
@ -78,11 +79,13 @@ export const OrderList = forwardRef<AgGridReact, OrderListProps>(
|
|||||||
const [editOrder, setEditOrder] = useState<Order | null>(null);
|
const [editOrder, setEditOrder] = useState<Order | null>(null);
|
||||||
const orderCancel = useOrderCancel();
|
const orderCancel = useOrderCancel();
|
||||||
const orderEdit = useOrderEdit(editOrder);
|
const orderEdit = useOrderEdit(editOrder);
|
||||||
|
const hasActiveOrder = useHasActiveOrder(props.marketId);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<OrderListTable
|
<OrderListTable
|
||||||
{...props}
|
{...props}
|
||||||
|
hasActiveOrder={hasActiveOrder}
|
||||||
cancelAll={() => {
|
cancelAll={() => {
|
||||||
orderCancel.cancel({
|
orderCancel.cancel({
|
||||||
marketId: props.marketId,
|
marketId: props.marketId,
|
||||||
@ -144,11 +147,12 @@ export const OrderList = forwardRef<AgGridReact, OrderListProps>(
|
|||||||
export type OrderListTableProps = OrderListProps & {
|
export type OrderListTableProps = OrderListProps & {
|
||||||
cancel: (order: Order) => void;
|
cancel: (order: Order) => void;
|
||||||
cancelAll: () => void;
|
cancelAll: () => void;
|
||||||
|
hasActiveOrder: boolean;
|
||||||
setEditOrder: (order: Order) => void;
|
setEditOrder: (order: Order) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
||||||
({ cancel, cancelAll, setEditOrder, ...props }, ref) => {
|
({ cancel, cancelAll, setEditOrder, hasActiveOrder, ...props }, ref) => {
|
||||||
return (
|
return (
|
||||||
<AgGrid
|
<AgGrid
|
||||||
ref={ref}
|
ref={ref}
|
||||||
@ -365,6 +369,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
|||||||
cellRenderer={({ data, node }: VegaICellRendererParams<Order>) => {
|
cellRenderer={({ data, node }: VegaICellRendererParams<Order>) => {
|
||||||
if (node?.rowPinned) {
|
if (node?.rowPinned) {
|
||||||
return (
|
return (
|
||||||
|
hasActiveOrder && (
|
||||||
<div className="flex gap-2 items-center h-full justify-end">
|
<div className="flex gap-2 items-center h-full justify-end">
|
||||||
<Button
|
<Button
|
||||||
size="xs"
|
size="xs"
|
||||||
@ -374,6 +379,7 @@ export const OrderListTable = forwardRef<AgGridReact, OrderListTableProps>(
|
|||||||
{t('Cancel all')}
|
{t('Cancel all')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (isOrderAmendable(data)) {
|
if (isOrderAmendable(data)) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
export * from './__generated__/OrderEvent';
|
export * from './__generated__/OrderEvent';
|
||||||
|
export * from './use-has-active-order';
|
||||||
export * from './use-order-cancel';
|
export * from './use-order-cancel';
|
||||||
export * from './use-order-submit';
|
export * from './use-order-submit';
|
||||||
export * from './use-order-edit';
|
export * from './use-order-edit';
|
||||||
|
47
libs/orders/src/lib/order-hooks/use-has-active-order.ts
Normal file
47
libs/orders/src/lib/order-hooks/use-has-active-order.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { useState, useEffect, useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
useOrdersUpdateSubscription,
|
||||||
|
useOrdersQuery,
|
||||||
|
} from '../components/order-data-provider/__generated__/Orders';
|
||||||
|
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||||
|
import * as Schema from '@vegaprotocol/types';
|
||||||
|
|
||||||
|
export const useHasActiveOrder = (marketId?: string) => {
|
||||||
|
const { pubKey } = useVegaWallet();
|
||||||
|
const skip = !pubKey;
|
||||||
|
const [hasActiveOrder, setHasActiveOrder] = useState(false);
|
||||||
|
const subscriptionVariables = useMemo(
|
||||||
|
() => ({
|
||||||
|
partyId: pubKey || '',
|
||||||
|
marketId,
|
||||||
|
}),
|
||||||
|
[pubKey, marketId]
|
||||||
|
);
|
||||||
|
const queryVariables = useMemo(
|
||||||
|
() => ({
|
||||||
|
...subscriptionVariables,
|
||||||
|
pagination: { first: 1 },
|
||||||
|
filter: { status: [Schema.OrderStatus.STATUS_ACTIVE] },
|
||||||
|
}),
|
||||||
|
[subscriptionVariables]
|
||||||
|
);
|
||||||
|
|
||||||
|
const { refetch, data, loading } = useOrdersQuery({
|
||||||
|
variables: queryVariables,
|
||||||
|
fetchPolicy: 'no-cache',
|
||||||
|
skip,
|
||||||
|
});
|
||||||
|
useEffect(() => {
|
||||||
|
if (!loading && data) {
|
||||||
|
setHasActiveOrder(!!data.party?.ordersConnection?.edges?.length);
|
||||||
|
}
|
||||||
|
}, [loading, data]);
|
||||||
|
|
||||||
|
useOrdersUpdateSubscription({
|
||||||
|
variables: subscriptionVariables,
|
||||||
|
onData: () => refetch(),
|
||||||
|
skip,
|
||||||
|
});
|
||||||
|
|
||||||
|
return hasActiveOrder;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user