feat: add filters to Orders query (#2446)
This commit is contained in:
parent
1c57ec4df1
commit
dbba734672
@ -22,10 +22,19 @@ fragment OrderFields on Order {
|
||||
}
|
||||
}
|
||||
|
||||
query Orders($partyId: ID!, $pagination: Pagination, $dateRange: DateRange) {
|
||||
query Orders(
|
||||
$partyId: ID!
|
||||
$pagination: Pagination
|
||||
$dateRange: DateRange
|
||||
$filter: OrderFilter
|
||||
) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
ordersConnection(pagination: $pagination, dateRange: $dateRange) {
|
||||
ordersConnection(
|
||||
pagination: $pagination
|
||||
dateRange: $dateRange
|
||||
filter: $filter
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...OrderFields
|
||||
|
@ -9,6 +9,7 @@ export type OrdersQueryVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
pagination?: Types.InputMaybe<Types.Pagination>;
|
||||
dateRange?: Types.InputMaybe<Types.DateRange>;
|
||||
filter?: Types.InputMaybe<Types.OrderFilter>;
|
||||
}>;
|
||||
|
||||
|
||||
@ -71,10 +72,14 @@ export const OrderUpdateFieldsFragmentDoc = gql`
|
||||
}
|
||||
`;
|
||||
export const OrdersDocument = gql`
|
||||
query Orders($partyId: ID!, $pagination: Pagination, $dateRange: DateRange) {
|
||||
query Orders($partyId: ID!, $pagination: Pagination, $dateRange: DateRange, $filter: OrderFilter) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
ordersConnection(pagination: $pagination, dateRange: $dateRange) {
|
||||
ordersConnection(
|
||||
pagination: $pagination
|
||||
dateRange: $dateRange
|
||||
filter: $filter
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...OrderFields
|
||||
@ -107,6 +112,7 @@ export const OrdersDocument = gql`
|
||||
* partyId: // value for 'partyId'
|
||||
* pagination: // value for 'pagination'
|
||||
* dateRange: // value for 'dateRange'
|
||||
* filter: // value for 'filter'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
|
@ -42,6 +42,64 @@ interface Props {
|
||||
scrolledToTop: RefObject<boolean>;
|
||||
}
|
||||
|
||||
const filterOrders = (
|
||||
orders: (OrderEdge | null)[] | null,
|
||||
variables: OrdersQueryVariables & OrdersUpdateSubscriptionVariables
|
||||
) => {
|
||||
if (!orders) {
|
||||
return orders;
|
||||
}
|
||||
return orders.filter((order) => {
|
||||
if (variables.marketId && order?.node.market?.id !== variables.marketId) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.filter?.status &&
|
||||
!(
|
||||
order?.node?.status &&
|
||||
variables.filter.status.includes(order.node.status)
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.filter?.types &&
|
||||
!(order?.node?.type && variables.filter.types.includes(order.node.type))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.filter?.timeInForce &&
|
||||
!(
|
||||
order?.node?.timeInForce &&
|
||||
variables.filter.timeInForce.includes(order.node.timeInForce)
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.dateRange?.start &&
|
||||
!(
|
||||
(order?.node?.updatedAt || order?.node?.createdAt) &&
|
||||
variables.dateRange.start <
|
||||
(order.node.updatedAt || order.node.createdAt)
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
variables?.dateRange?.end &&
|
||||
!(
|
||||
(order?.node?.updatedAt || order?.node?.createdAt) &&
|
||||
variables.dateRange.end > (order.node.updatedAt || order.node.createdAt)
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
export const useOrderListData = ({
|
||||
partyId,
|
||||
marketId,
|
||||
@ -57,7 +115,16 @@ export const useOrderListData = ({
|
||||
const variables = useMemo<
|
||||
OrdersQueryVariables & OrdersUpdateSubscriptionVariables
|
||||
>(
|
||||
() => ({ partyId, dateRange: filter?.updatedAt?.value, marketId }),
|
||||
() => ({
|
||||
partyId,
|
||||
dateRange: filter?.updatedAt?.value,
|
||||
marketId,
|
||||
filter: {
|
||||
status: filter?.status?.value,
|
||||
timeInForce: filter?.timeInForce?.value,
|
||||
types: filter?.type?.value,
|
||||
},
|
||||
}),
|
||||
[partyId, marketId, filter]
|
||||
);
|
||||
|
||||
@ -88,18 +155,15 @@ export const useOrderListData = ({
|
||||
).length;
|
||||
}
|
||||
}
|
||||
dataRef.current = filterOrders(data, variables);
|
||||
const avoidRerender = !!(
|
||||
(dataRef.current?.length && data?.length) ||
|
||||
(!dataRef.current?.length && !data?.length)
|
||||
);
|
||||
dataRef.current =
|
||||
!!marketId && !!data
|
||||
? data.filter((d) => d?.node.market?.id === marketId)
|
||||
: data;
|
||||
gridRef.current?.api?.refreshInfiniteCache();
|
||||
return avoidRerender;
|
||||
},
|
||||
[gridRef, scrolledToTop, marketId]
|
||||
[gridRef, scrolledToTop, variables]
|
||||
);
|
||||
|
||||
const insert = useCallback(
|
||||
@ -110,14 +174,11 @@ export const useOrderListData = ({
|
||||
data: (OrderEdge | null)[] | null;
|
||||
totalCount?: number;
|
||||
}) => {
|
||||
dataRef.current =
|
||||
!!marketId && !!data
|
||||
? data.filter((d) => d?.node.market?.id === marketId)
|
||||
: data;
|
||||
dataRef.current = filterOrders(data, variables);
|
||||
totalCountRef.current = totalCount;
|
||||
return true;
|
||||
},
|
||||
[marketId]
|
||||
[variables]
|
||||
);
|
||||
|
||||
const { data, error, loading, load, totalCount } = useDataProvider({
|
||||
|
82
libs/types/src/__generated__/types.ts
generated
82
libs/types/src/__generated__/types.ts
generated
@ -473,35 +473,6 @@ export type ContinuousTrading = {
|
||||
tickSize: Scalars['String'];
|
||||
};
|
||||
|
||||
/** Connection type for retrieving cursor-based paginated core snapshot data */
|
||||
export type CoreSnapshotConnection = {
|
||||
__typename?: 'CoreSnapshotConnection';
|
||||
/** The positions in this connection */
|
||||
edges?: Maybe<Array<CoreSnapshotEdge>>;
|
||||
/** The pagination information */
|
||||
pageInfo?: Maybe<PageInfo>;
|
||||
};
|
||||
|
||||
/** A snapshot taken by the core */
|
||||
export type CoreSnapshotData = {
|
||||
__typename?: 'CoreSnapshotData';
|
||||
/** The block hash at the snapshot block height */
|
||||
blockHash: Scalars['String'];
|
||||
/** At which block the snapshot was taken */
|
||||
blockHeight: Scalars['String'];
|
||||
/** The current version of vega core */
|
||||
vegaCoreVersion: Scalars['String'];
|
||||
};
|
||||
|
||||
/** Edge type containing the core snapshot cursor information */
|
||||
export type CoreSnapshotEdge = {
|
||||
__typename?: 'CoreSnapshotEdge';
|
||||
/** Cursor identifying the core snapashot data */
|
||||
cursor: Scalars['String'];
|
||||
/** The core snapshot data */
|
||||
node: CoreSnapshotData;
|
||||
};
|
||||
|
||||
/** A data source contains the data sent by a data source */
|
||||
export type Data = {
|
||||
__typename?: 'Data';
|
||||
@ -890,33 +861,6 @@ export type EpochParticipation = {
|
||||
totalRewards?: Maybe<Scalars['Float']>;
|
||||
};
|
||||
|
||||
/** an aggregated reward summary for a combination of epoch/asset/market/reward type */
|
||||
export type EpochRewardSummary = {
|
||||
__typename?: 'EpochRewardSummary';
|
||||
/** Total quantity of rewards awarded in this asset/market/reward type in this epoch */
|
||||
amount: Scalars['String'];
|
||||
/** ID of the Asset */
|
||||
assetId: Scalars['ID'];
|
||||
/** The epoch for which summary is generated */
|
||||
epoch: Scalars['Int'];
|
||||
/** ID of the market */
|
||||
marketId?: Maybe<Scalars['ID']>;
|
||||
/** Type of the reward */
|
||||
rewardType: AccountType;
|
||||
};
|
||||
|
||||
export type EpochRewardSummaryConnection = {
|
||||
__typename?: 'EpochRewardSummaryConnection';
|
||||
edges?: Maybe<Array<Maybe<EpochRewardSummaryEdge>>>;
|
||||
pageInfo?: Maybe<PageInfo>;
|
||||
};
|
||||
|
||||
export type EpochRewardSummaryEdge = {
|
||||
__typename?: 'EpochRewardSummaryEdge';
|
||||
cursor: Scalars['String'];
|
||||
node: EpochRewardSummary;
|
||||
};
|
||||
|
||||
/** Describes in both human readable and block time when an epoch spans. */
|
||||
export type EpochTimestamps = {
|
||||
__typename?: 'EpochTimestamps';
|
||||
@ -1488,8 +1432,6 @@ export type Market = {
|
||||
liquidityMonitoringParameters: LiquidityMonitoringParameters;
|
||||
/** The list of the liquidity provision commitments for this market */
|
||||
liquidityProvisionsConnection?: Maybe<LiquidityProvisionsConnection>;
|
||||
/** Liquidity Provision order price range */
|
||||
lpPriceRange: Scalars['String'];
|
||||
/** Timestamps for state changes in the market */
|
||||
marketTimestamps: MarketTimestamps;
|
||||
/**
|
||||
@ -1869,8 +1811,6 @@ export type NewMarket = {
|
||||
decimalPlaces: Scalars['Int'];
|
||||
/** New market instrument configuration */
|
||||
instrument: InstrumentConfiguration;
|
||||
/** Liquidity Provision order price range */
|
||||
lpPriceRange: Scalars['String'];
|
||||
/** Metadata for this instrument, tags */
|
||||
metadata?: Maybe<Array<Scalars['String']>>;
|
||||
/** New market risk configuration */
|
||||
@ -3196,16 +3136,12 @@ export type Query = {
|
||||
assetsConnection?: Maybe<AssetsConnection>;
|
||||
/** Get historical balances for an account within the given date range */
|
||||
balanceChanges: AggregatedBalanceConnection;
|
||||
/** List core snapshots */
|
||||
coreSnapshots?: Maybe<CoreSnapshotConnection>;
|
||||
/** Find a deposit using its ID */
|
||||
deposit?: Maybe<Deposit>;
|
||||
/** Fetch all deposits */
|
||||
deposits?: Maybe<DepositsConnection>;
|
||||
/** Get data for a specific epoch, if ID omitted it gets the current epoch. If the string is 'next', fetch the next epoch */
|
||||
epoch: Epoch;
|
||||
/** List reward summary per epoch by asset, market, reward type */
|
||||
epochRewardSummaries?: Maybe<EpochRewardSummaryConnection>;
|
||||
/** Get the signatures bundle to allowlist an ERC20 token in the collateral bridge */
|
||||
erc20ListAssetBundle?: Maybe<Erc20ListAssetBundle>;
|
||||
/** Get the signature bundle to add a particular validator to the signer list of the multisig contract */
|
||||
@ -3311,12 +3247,6 @@ export type QuerybalanceChangesArgs = {
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QuerycoreSnapshotsArgs = {
|
||||
pagination?: InputMaybe<Pagination>;
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QuerydepositArgs = {
|
||||
id: Scalars['ID'];
|
||||
@ -3336,14 +3266,6 @@ export type QueryepochArgs = {
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QueryepochRewardSummariesArgs = {
|
||||
fromEpoch?: InputMaybe<Scalars['Int']>;
|
||||
pagination?: InputMaybe<Pagination>;
|
||||
toEpoch?: InputMaybe<Scalars['Int']>;
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type Queryerc20ListAssetBundleArgs = {
|
||||
assetId: Scalars['ID'];
|
||||
@ -4343,8 +4265,8 @@ export enum TransferType {
|
||||
TRANSFER_TYPE_MTM_LOSS = 'TRANSFER_TYPE_MTM_LOSS',
|
||||
/** Funds added to margin account after mark to market gain */
|
||||
TRANSFER_TYPE_MTM_WIN = 'TRANSFER_TYPE_MTM_WIN',
|
||||
/** Reward payout received */
|
||||
TRANSFER_TYPE_REWARD_PAYOUT = 'TRANSFER_TYPE_REWARD_PAYOUT',
|
||||
/** Staking reward received */
|
||||
TRANSFER_TYPE_STAKE_REWARD = 'TRANSFER_TYPE_STAKE_REWARD',
|
||||
/** A network internal instruction for the collateral engine to move funds from the pending transfers pool account into the destination account */
|
||||
TRANSFER_TYPE_TRANSFER_FUNDS_DISTRIBUTE = 'TRANSFER_TYPE_TRANSFER_FUNDS_DISTRIBUTE',
|
||||
/** A network internal instruction for the collateral engine to move funds from a user's general account into the pending transfers pool */
|
||||
|
@ -401,7 +401,7 @@ export const TransferTypeMapping: TransferTypeMap = {
|
||||
TRANSFER_TYPE_WITHDRAW: 'Withdrawal',
|
||||
TRANSFER_TYPE_DEPOSIT: 'Deposit',
|
||||
TRANSFER_TYPE_BOND_SLASHING: 'Bond slashed',
|
||||
TRANSFER_TYPE_REWARD_PAYOUT: 'Rewards funded',
|
||||
TRANSFER_TYPE_STAKE_REWARD: 'Rewards funded',
|
||||
TRANSFER_TYPE_TRANSFER_FUNDS_SEND: 'Transfer sent',
|
||||
TRANSFER_TYPE_TRANSFER_FUNDS_DISTRIBUTE: 'Transfer received',
|
||||
TRANSFER_TYPE_CLEAR_ACCOUNT: 'Market accounts cleared',
|
||||
@ -427,7 +427,7 @@ export const DescriptionTransferTypeMapping: TransferTypeMap = {
|
||||
TRANSFER_TYPE_WITHDRAW: `Funds withdrawn from your general account`,
|
||||
TRANSFER_TYPE_DEPOSIT: `Funds deposited to your general account`,
|
||||
TRANSFER_TYPE_BOND_SLASHING: `Bond account penalized when liquidity commitment not met`,
|
||||
TRANSFER_TYPE_REWARD_PAYOUT: `Collateral deducted from your general account to fund rewards you've set up`,
|
||||
TRANSFER_TYPE_STAKE_REWARD: `Collateral deducted from your general account to fund rewards you've set up`,
|
||||
TRANSFER_TYPE_TRANSFER_FUNDS_SEND: `Funds deducted from your general account to fulfil a transfer`,
|
||||
TRANSFER_TYPE_TRANSFER_FUNDS_DISTRIBUTE: `Funds added to your general account to fulfil a transfer`,
|
||||
TRANSFER_TYPE_CLEAR_ACCOUNT: `Market-related accounts emptied, and balances moved, because the market has closed`,
|
||||
|
Loading…
Reference in New Issue
Block a user