fix(orders): restore filter by marketId (#3342)

This commit is contained in:
Bartłomiej Głownia 2023-04-03 23:20:31 +02:00 committed by GitHub
parent 861760b4f9
commit 381d9011a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 63 additions and 78 deletions

View File

@ -32,12 +32,16 @@ query OrderById($orderId: ID!) {
query Orders( query Orders(
$partyId: ID! $partyId: ID!
$marketIds: [ID!]
$pagination: Pagination $pagination: Pagination
$filter: OrderByMarketIdsFilter $filter: OrderFilter
) { ) {
party(id: $partyId) { party(id: $partyId) {
id id
ordersConnection(pagination: $pagination, filter: $filter) { ordersConnection(
pagination: $pagination
filter: { order: $filter, marketIds: $marketIds }
) {
edges { edges {
node { node {
...OrderFields ...OrderFields
@ -74,8 +78,8 @@ fragment OrderUpdateFields on OrderUpdate {
} }
} }
subscription OrdersUpdate($partyId: ID!) { subscription OrdersUpdate($partyId: ID!, $marketIds: [ID!]) {
orders(filter: { partyIds: [$partyId] }) { orders(filter: { partyIds: [$partyId], marketIds: $marketIds }) {
...OrderUpdateFields ...OrderUpdateFields
} }
} }

View File

@ -14,8 +14,9 @@ export type OrderByIdQuery = { __typename?: 'Query', orderByID: { __typename?: '
export type OrdersQueryVariables = Types.Exact<{ export type OrdersQueryVariables = Types.Exact<{
partyId: Types.Scalars['ID']; partyId: Types.Scalars['ID'];
marketIds?: Types.InputMaybe<Array<Types.Scalars['ID']> | Types.Scalars['ID']>;
pagination?: Types.InputMaybe<Types.Pagination>; pagination?: Types.InputMaybe<Types.Pagination>;
filter?: Types.InputMaybe<Types.OrderByMarketIdsFilter>; filter?: Types.InputMaybe<Types.OrderFilter>;
}>; }>;
@ -25,6 +26,7 @@ export type OrderUpdateFieldsFragment = { __typename?: 'OrderUpdate', id: string
export type OrdersUpdateSubscriptionVariables = Types.Exact<{ export type OrdersUpdateSubscriptionVariables = Types.Exact<{
partyId: Types.Scalars['ID']; partyId: Types.Scalars['ID'];
marketIds?: Types.InputMaybe<Array<Types.Scalars['ID']> | Types.Scalars['ID']>;
}>; }>;
@ -114,10 +116,13 @@ export type OrderByIdQueryHookResult = ReturnType<typeof useOrderByIdQuery>;
export type OrderByIdLazyQueryHookResult = ReturnType<typeof useOrderByIdLazyQuery>; export type OrderByIdLazyQueryHookResult = ReturnType<typeof useOrderByIdLazyQuery>;
export type OrderByIdQueryResult = Apollo.QueryResult<OrderByIdQuery, OrderByIdQueryVariables>; export type OrderByIdQueryResult = Apollo.QueryResult<OrderByIdQuery, OrderByIdQueryVariables>;
export const OrdersDocument = gql` export const OrdersDocument = gql`
query Orders($partyId: ID!, $pagination: Pagination, $filter: OrderByMarketIdsFilter) { query Orders($partyId: ID!, $marketIds: [ID!], $pagination: Pagination, $filter: OrderFilter) {
party(id: $partyId) { party(id: $partyId) {
id id
ordersConnection(pagination: $pagination, filter: $filter) { ordersConnection(
pagination: $pagination
filter: {order: $filter, marketIds: $marketIds}
) {
edges { edges {
node { node {
...OrderFields ...OrderFields
@ -148,6 +153,7 @@ export const OrdersDocument = gql`
* const { data, loading, error } = useOrdersQuery({ * const { data, loading, error } = useOrdersQuery({
* variables: { * variables: {
* partyId: // value for 'partyId' * partyId: // value for 'partyId'
* marketIds: // value for 'marketIds'
* pagination: // value for 'pagination' * pagination: // value for 'pagination'
* filter: // value for 'filter' * filter: // value for 'filter'
* }, * },
@ -165,8 +171,8 @@ export type OrdersQueryHookResult = ReturnType<typeof useOrdersQuery>;
export type OrdersLazyQueryHookResult = ReturnType<typeof useOrdersLazyQuery>; export type OrdersLazyQueryHookResult = ReturnType<typeof useOrdersLazyQuery>;
export type OrdersQueryResult = Apollo.QueryResult<OrdersQuery, OrdersQueryVariables>; export type OrdersQueryResult = Apollo.QueryResult<OrdersQuery, OrdersQueryVariables>;
export const OrdersUpdateDocument = gql` export const OrdersUpdateDocument = gql`
subscription OrdersUpdate($partyId: ID!) { subscription OrdersUpdate($partyId: ID!, $marketIds: [ID!]) {
orders(filter: {partyIds: [$partyId]}) { orders(filter: {partyIds: [$partyId], marketIds: $marketIds}) {
...OrderUpdateFields ...OrderUpdateFields
} }
} }
@ -185,6 +191,7 @@ export const OrdersUpdateDocument = gql`
* const { data, loading, error } = useOrdersUpdateSubscription({ * const { data, loading, error } = useOrdersUpdateSubscription({
* variables: { * variables: {
* partyId: // value for 'partyId' * partyId: // value for 'partyId'
* marketIds: // value for 'marketIds'
* }, * },
* }); * });
*/ */

View File

@ -112,9 +112,7 @@ describe('order data provider', () => {
const updatedData = update(data, delta, () => null, { const updatedData = update(data, delta, () => null, {
partyId: '0x123', partyId: '0x123',
filter: { filter: {
order: { dateRange: { end: new Date('2022-02-01').toISOString() },
dateRange: { end: new Date('2022-02-01').toISOString() },
},
}, },
}); });
expect( expect(

View File

@ -35,45 +35,40 @@ const orderMatchFilters = (
return true; return true;
} }
if ( if (
variables?.filter?.order?.status && variables?.filter?.status &&
!(order.status && variables.filter.order.status.includes(order.status)) !(order.status && variables.filter.status.includes(order.status))
) { ) {
return false; return false;
} }
if ( if (
variables?.filter?.order?.types && variables?.filter?.types &&
!(order.type && variables.filter.order.types.includes(order.type)) !(order.type && variables.filter.types.includes(order.type))
) { ) {
return false; return false;
} }
if ( if (
variables?.filter?.order?.timeInForce && variables?.filter?.timeInForce &&
!variables.filter.order.timeInForce.includes(order.timeInForce) !variables.filter.timeInForce.includes(order.timeInForce)
) { ) {
return false; return false;
} }
if ( if (variables?.filter?.excludeLiquidity && order.liquidityProvisionId) {
variables?.filter?.order?.excludeLiquidity &&
order.liquidityProvisionId
) {
return false; return false;
} }
if ( if (
variables?.filter?.order?.dateRange?.start && variables?.filter?.dateRange?.start &&
!( !(
(order.updatedAt || order.createdAt) && (order.updatedAt || order.createdAt) &&
variables.filter.order.dateRange.start < variables.filter.dateRange.start < (order.updatedAt || order.createdAt)
(order.updatedAt || order.createdAt)
) )
) { ) {
return false; return false;
} }
if ( if (
variables?.filter?.order?.dateRange?.end && variables?.filter?.dateRange?.end &&
!( !(
(order.updatedAt || order.createdAt) && (order.updatedAt || order.createdAt) &&
variables.filter.order.dateRange.end > variables.filter.dateRange.end > (order.updatedAt || order.createdAt)
(order.updatedAt || order.createdAt)
) )
) { ) {
return false; return false;
@ -243,18 +238,17 @@ export const hasActiveOrderProvider = makeDerivedDataProvider<
{ partyId: string; marketId?: string } { partyId: string; marketId?: string }
>( >(
[ [
(callback, client, variables) => (callback, client, { partyId, marketId }) =>
hasActiveOrderProviderInternal(callback, client, { hasActiveOrderProviderInternal(callback, client, {
marketIds: marketId ? [marketId] : undefined,
filter: { filter: {
order: { status: [OrderStatus.STATUS_ACTIVE],
status: [OrderStatus.STATUS_ACTIVE], excludeLiquidity: true,
excludeLiquidity: true,
},
}, },
pagination: { pagination: {
first: 1, first: 1,
}, },
...variables, partyId,
} as OrdersQueryVariables), } as OrdersQueryVariables),
], ],
(parts) => parts[0] (parts) => parts[0]

View File

@ -72,12 +72,10 @@ export const useOrderListData = ({
const allVars: OrdersQueryVariables & OrdersUpdateSubscriptionVariables = { const allVars: OrdersQueryVariables & OrdersUpdateSubscriptionVariables = {
partyId, partyId,
filter: { filter: {
order: { dateRange: filter?.updatedAt?.value,
dateRange: filter?.updatedAt?.value, status: filter?.status?.value,
status: filter?.status?.value, timeInForce: filter?.timeInForce?.value,
timeInForce: filter?.timeInForce?.value, types: filter?.type?.value,
types: filter?.type?.value,
},
}, },
pagination: { pagination: {
first: 1000, first: 1000,

View File

@ -53,14 +53,12 @@ export const useActiveOrdersVolumeAndMargin = (
update, update,
variables: { variables: {
partyId: partyId || '', partyId: partyId || '',
marketIds: [marketId],
filter: { filter: {
marketIds: [marketId], status: [
order: { OrderStatus.STATUS_ACTIVE,
status: [ OrderStatus.STATUS_PARTIALLY_FILLED,
OrderStatus.STATUS_ACTIVE, ],
OrderStatus.STATUS_PARTIALLY_FILLED,
],
},
}, },
}, },
skip: !partyId, skip: !partyId,

View File

@ -1,5 +1,5 @@
import type { MarketData, Market } from '@vegaprotocol/market-list'; import type { MarketData, Market } from '@vegaprotocol/market-list';
import type { Order } from '@vegaprotocol/orders'; import type { OrderFieldsFragment } from '@vegaprotocol/orders';
import { timeInForceLabel } from '@vegaprotocol/orders'; import { timeInForceLabel } from '@vegaprotocol/orders';
import { addDecimalsFormatNumber } from '@vegaprotocol/utils'; import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
import { t } from '@vegaprotocol/i18n'; import { t } from '@vegaprotocol/i18n';
@ -50,7 +50,7 @@ export const ActiveOrders = ({
orders, orders,
}: { }: {
market: Market; market: Market;
orders: Order[]; orders: OrderFieldsFragment[];
}) => { }) => {
const asset = market.tradableInstrument.instrument.product.settlementAsset; const asset = market.tradableInstrument.instrument.product.settlementAsset;

View File

@ -349,16 +349,15 @@ export const volumeAndMarginProvider = makeDerivedDataProvider<
PositionsQueryVariables & MarketDataQueryVariables PositionsQueryVariables & MarketDataQueryVariables
>( >(
[ [
(callback, client, variables) => (callback, client, { partyId, marketId }) =>
ordersProvider(callback, client, { ordersProvider(callback, client, {
...variables, partyId,
marketIds: [marketId],
filter: { filter: {
order: { status: [
status: [ OrderStatus.STATUS_ACTIVE,
OrderStatus.STATUS_ACTIVE, OrderStatus.STATUS_PARTIALLY_FILLED,
OrderStatus.STATUS_PARTIALLY_FILLED, ],
],
},
}, },
}), }),
(callback, client, variables) => (callback, client, variables) =>

View File

@ -1,5 +1,5 @@
import { marketDataProvider, marketProvider } from '@vegaprotocol/market-list'; import { marketDataProvider, marketProvider } from '@vegaprotocol/market-list';
import { isOrderActive, ordersWithMarketProvider } from '@vegaprotocol/orders'; import { isOrderActive, ordersProvider } from '@vegaprotocol/orders';
import type { OrdersQueryVariables } from '@vegaprotocol/orders'; import type { OrdersQueryVariables } from '@vegaprotocol/orders';
import { useDataProvider } from '@vegaprotocol/react-helpers'; import { useDataProvider } from '@vegaprotocol/react-helpers';
import { useMemo } from 'react'; import { useMemo } from 'react';
@ -13,8 +13,11 @@ export const useRequestClosePositionData = (
[marketId] [marketId]
); );
const orderVariables = useMemo<OrdersQueryVariables>( const orderVariables = useMemo<OrdersQueryVariables>(
() => ({ partyId: partyId || '' }), () => ({
[partyId] partyId: partyId || '',
marketIds: marketId ? [marketId] : undefined,
}),
[partyId, marketId]
); );
const { data: market, loading: marketLoading } = useDataProvider({ const { data: market, loading: marketLoading } = useDataProvider({
dataProvider: marketProvider, dataProvider: marketProvider,
@ -26,7 +29,7 @@ export const useRequestClosePositionData = (
variables: marketVariables, variables: marketVariables,
}); });
const { data: orderData, loading: orderDataLoading } = useDataProvider({ const { data: orderData, loading: orderDataLoading } = useDataProvider({
dataProvider: ordersWithMarketProvider, dataProvider: ordersProvider,
variables: orderVariables, variables: orderVariables,
skip: !partyId, skip: !partyId,
}); });
@ -35,23 +38,7 @@ export const useRequestClosePositionData = (
if (!orderData || !market) return []; if (!orderData || !market) return [];
return ( return (
orderData orderData
.filter((o) => { .filter((o) => o?.node && isOrderActive(o.node.status))
// Filter out orders not on market for position
if (
!o ||
!o.node ||
!o.node.market ||
o.node.market.id !== market.id
) {
return false;
}
if (!isOrderActive(o.node.status)) {
return false;
}
return true;
})
// @ts-ignore o is never null as its been filtered out above // @ts-ignore o is never null as its been filtered out above
.map((o) => o.node) .map((o) => o.node)
); );