fix: query type generation and type errors
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import compact from 'lodash/compact';
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { getAssets, t } from '@vegaprotocol/react-helpers';
|
||||
import { t } from '@vegaprotocol/react-helpers';
|
||||
import React from 'react';
|
||||
import { RouteTitle } from '../../components/route-title';
|
||||
import { SubHeading } from '../../components/sub-heading';
|
||||
@@ -39,7 +40,7 @@ export const ASSETS_QUERY = gql`
|
||||
const Assets = () => {
|
||||
const { data } = useQuery<AssetsQuery>(ASSETS_QUERY);
|
||||
|
||||
const assets = getAssets(data);
|
||||
const assets = compact(data?.assetsConnection?.edges).map((e) => e.node);
|
||||
|
||||
return (
|
||||
<section>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import compact from 'lodash/compact';
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { t } from '@vegaprotocol/react-helpers';
|
||||
import React from 'react';
|
||||
@@ -99,9 +100,10 @@ const Governance = () => {
|
||||
const { data } = useQuery<ProposalsQuery>(PROPOSALS_QUERY, {
|
||||
errorPolicy: 'ignore',
|
||||
});
|
||||
const proposals = getProposals(
|
||||
data
|
||||
) as ProposalsQuery_proposalsConnection_edges_node[];
|
||||
|
||||
const proposals = compact(data?.proposalsConnection?.edges).map(
|
||||
(e) => e.node
|
||||
);
|
||||
|
||||
if (!data) return null;
|
||||
return (
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ProposalVotesTable } from '../proposal-votes-table';
|
||||
import { VoteDetails } from '../vote-details';
|
||||
|
||||
interface ProposalProps {
|
||||
proposal: Proposal_proposal;
|
||||
proposal: Proposal_proposal | null;
|
||||
}
|
||||
|
||||
export const Proposal = ({ proposal }: ProposalProps) => {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import compact from 'lodash/compact';
|
||||
import orderBy from 'lodash/orderBy';
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { getNotRejectedProposals } from '@vegaprotocol/governance';
|
||||
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { SplashLoader } from '../../../components/splash-loader';
|
||||
import { ProposalsList } from '../components/proposals-list';
|
||||
import { PROPOSAL_FRAGMENT } from '../proposal-fragment';
|
||||
import type { Proposals } from './__generated__/Proposals';
|
||||
import { ProposalState } from '@vegaprotocol/types';
|
||||
|
||||
export const PROPOSALS_QUERY = gql`
|
||||
${PROPOSAL_FRAGMENT}
|
||||
@@ -30,7 +31,18 @@ export const ProposalsContainer = () => {
|
||||
errorPolicy: 'ignore',
|
||||
});
|
||||
|
||||
const proposals = useMemo(() => getNotRejectedProposals(data), [data]);
|
||||
const proposals = compact(data?.proposalsConnection?.edges)
|
||||
.map((e) => e.node)
|
||||
.filter((p) => p.state !== ProposalState.STATE_REJECTED);
|
||||
const orderedProposals = orderBy(
|
||||
proposals,
|
||||
[
|
||||
(p) => new Date(p.terms.enactmentDatetime || 0).getTime(), // has to be defaulted to 0 because new Date(null).getTime() -> NaN which is first when ordered.
|
||||
(p) => new Date(p.terms.closingDatetime).getTime(),
|
||||
(p) => p.id,
|
||||
],
|
||||
['desc', 'desc', 'desc']
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
@@ -48,5 +60,5 @@ export const ProposalsContainer = () => {
|
||||
);
|
||||
}
|
||||
|
||||
return <ProposalsList proposals={proposals} />;
|
||||
return <ProposalsList proposals={orderedProposals} />;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import compact from 'lodash/compact';
|
||||
import orderBy from 'lodash/orderBy';
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
||||
import { useMemo } from 'react';
|
||||
@@ -5,15 +7,26 @@ import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { SplashLoader } from '../../../components/splash-loader';
|
||||
import { RejectedProposalsList } from '../components/proposals-list';
|
||||
import { getRejectedProposals } from '@vegaprotocol/governance';
|
||||
import { PROPOSALS_QUERY } from '../proposals';
|
||||
import type { Proposals } from '../proposals/__generated__/Proposals';
|
||||
import { ProposalState } from '@vegaprotocol/types';
|
||||
|
||||
export const RejectedProposalsContainer = () => {
|
||||
const { t } = useTranslation();
|
||||
const { data, loading, error } = useQuery<Proposals>(PROPOSALS_QUERY);
|
||||
|
||||
const proposals = useMemo(() => getRejectedProposals(data), [data]);
|
||||
const proposals = compact(data?.proposalsConnection?.edges)
|
||||
.map((e) => e.node)
|
||||
.filter((p) => p.state === ProposalState.STATE_REJECTED);
|
||||
const orderedProposals = orderBy(
|
||||
proposals,
|
||||
[
|
||||
(p) => new Date(p.terms.enactmentDatetime || 0).getTime(), // has to be defaulted to 0 because new Date(null).getTime() -> NaN which is first when ordered.
|
||||
(p) => new Date(p.terms.closingDatetime).getTime(),
|
||||
(p) => p.id,
|
||||
],
|
||||
['desc', 'desc', 'desc']
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
@@ -31,5 +44,5 @@ export const RejectedProposalsContainer = () => {
|
||||
);
|
||||
}
|
||||
|
||||
return <RejectedProposalsList proposals={proposals} />;
|
||||
return <RejectedProposalsList proposals={orderedProposals} />;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
fragment AccountFields on AccountUpdate {
|
||||
type
|
||||
balance
|
||||
assetId
|
||||
marketId
|
||||
}
|
||||
|
||||
query Accounts($partyId: ID!) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
@@ -23,8 +30,7 @@ query Accounts($partyId: ID!) {
|
||||
|
||||
subscription AccountEvents($partyId: ID!) {
|
||||
accounts(partyId: $partyId) {
|
||||
type
|
||||
balance
|
||||
...AccountFields
|
||||
marketId
|
||||
assetId
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { Schema as Types } from '@vegaprotocol/types';
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type AccountFieldsFragment = { __typename?: 'AccountUpdate', type: Types.AccountType, balance: string, assetId: string, marketId?: string | null };
|
||||
|
||||
export type AccountsQueryVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
}>;
|
||||
@@ -15,9 +17,16 @@ export type AccountEventsSubscriptionVariables = Types.Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type AccountEventsSubscription = { __typename?: 'Subscription', accounts: Array<{ __typename?: 'AccountUpdate', type: Types.AccountType, balance: string, marketId?: string | null, assetId: string }> };
|
||||
|
||||
export type AccountEventsSubscription = { __typename?: 'Subscription', accounts: Array<{ __typename?: 'AccountUpdate', marketId?: string | null, assetId: string, type: Types.AccountType, balance: string }> };
|
||||
|
||||
export const AccountFieldsFragmentDoc = gql`
|
||||
fragment AccountFields on AccountUpdate {
|
||||
type
|
||||
balance
|
||||
assetId
|
||||
marketId
|
||||
}
|
||||
`;
|
||||
export const AccountsDocument = gql`
|
||||
query Accounts($partyId: ID!) {
|
||||
party(id: $partyId) {
|
||||
@@ -73,13 +82,12 @@ export type AccountsQueryResult = Apollo.QueryResult<AccountsQuery, AccountsQuer
|
||||
export const AccountEventsDocument = gql`
|
||||
subscription AccountEvents($partyId: ID!) {
|
||||
accounts(partyId: $partyId) {
|
||||
type
|
||||
balance
|
||||
...AccountFields
|
||||
marketId
|
||||
assetId
|
||||
}
|
||||
}
|
||||
`;
|
||||
${AccountFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useAccountEventsSubscription__
|
||||
|
||||
@@ -2,51 +2,90 @@ import produce from 'immer';
|
||||
import {
|
||||
AccountsDocument,
|
||||
AccountEventsDocument,
|
||||
} from './__generated__/Accounts';
|
||||
} from './__generated___/Accounts';
|
||||
import type {
|
||||
AccountFieldsFragment,
|
||||
AccountsQuery,
|
||||
AccountEventsSubscription,
|
||||
} from './__generated__/Accounts';
|
||||
AccountFieldsFragment,
|
||||
} from './__generated___/Accounts';
|
||||
import { makeDataProvider } from '@vegaprotocol/react-helpers';
|
||||
import type { AccountType } from '@vegaprotocol/types';
|
||||
|
||||
export const getId = (data: AccountFieldsFragment) =>
|
||||
interface Account {
|
||||
type: AccountType;
|
||||
balance: string;
|
||||
market: {
|
||||
id: string;
|
||||
name: string;
|
||||
} | null;
|
||||
asset: {
|
||||
symbol: string;
|
||||
decimals: number;
|
||||
};
|
||||
}
|
||||
|
||||
export const getId = (data: Account) =>
|
||||
`${data.type}-${data.asset.symbol}-${data.market?.id ?? 'null'}`;
|
||||
|
||||
const update = (
|
||||
data: AccountFieldsFragment[],
|
||||
delta: AccountFieldsFragment
|
||||
) => {
|
||||
const update = (data: Account[], delta: Account[]) => {
|
||||
return produce(data, (draft) => {
|
||||
// @ts-ignore FIXME stagnet3 update
|
||||
const id = getId(delta);
|
||||
const index = draft.findIndex((a) => getId(a) === id);
|
||||
if (index !== -1) {
|
||||
// @ts-ignore FIXME stagnet3 update
|
||||
draft[index] = delta;
|
||||
} else {
|
||||
// @ts-ignore FIXME stagnet3 update
|
||||
draft.push(delta);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const getData = (
|
||||
responseData: AccountsQuery
|
||||
): AccountFieldsFragment[] | null => {
|
||||
return responseData.party?.accounts ?? null;
|
||||
const getData = (responseData: AccountsQuery): Account[] | null => {
|
||||
if (!responseData?.party?.accounts?.length) return null;
|
||||
return responseData.party?.accounts?.map((a) => {
|
||||
return {
|
||||
type: a.type,
|
||||
balance: a.balance,
|
||||
market: a.market
|
||||
? {
|
||||
id: a.market.id,
|
||||
name: a.market.tradableInstrument.instrument.name,
|
||||
}
|
||||
: null,
|
||||
asset: {
|
||||
symbol: a.asset.symbol,
|
||||
decimals: a.asset.decimals,
|
||||
},
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const getDelta = (
|
||||
subscriptionData: AccountEventsSubscription
|
||||
): AccountFieldsFragment => subscriptionData.accounts;
|
||||
const getDelta = (subscriptionData: AccountEventsSubscription): Account[] => {
|
||||
// return subscriptionData.accounts
|
||||
|
||||
// what to do here?
|
||||
// @ts-ignore how to retrieve market data for each account?
|
||||
return subscriptionData.accounts.map((a) => ({
|
||||
type: a.type,
|
||||
balance: a.balance,
|
||||
asset: {},
|
||||
market: a.marketId ? {} : null,
|
||||
}));
|
||||
};
|
||||
|
||||
export const accountsDataProvider = makeDataProvider<
|
||||
AccountsQuery,
|
||||
AccountFieldsFragment[],
|
||||
Account[],
|
||||
AccountEventsSubscription,
|
||||
AccountFieldsFragment
|
||||
>({
|
||||
query: AccountsDocument,
|
||||
subscriptionQuery: AccountEventsDocument,
|
||||
// @ts-ignore FIXME stagnet3 update
|
||||
update,
|
||||
getData,
|
||||
// @ts-ignore FIXME stagnet3 update
|
||||
getDelta,
|
||||
});
|
||||
|
||||
@@ -9,9 +9,9 @@ import {
|
||||
Splash,
|
||||
Tooltip,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { useAssetsConnectionQuery } from './__generated__/Assets';
|
||||
import type { Schema } from '@vegaprotocol/types';
|
||||
import create from 'zustand';
|
||||
import { useAssetsConnectionQuery } from './__generated___/Assets';
|
||||
|
||||
export type AssetDetailsDialogStore = {
|
||||
isAssetDetailsDialogOpen: boolean;
|
||||
@@ -54,7 +54,7 @@ export const AssetDetailsDialog = ({
|
||||
const { data } = useAssetsConnectionQuery();
|
||||
const symbol =
|
||||
typeof assetSymbol === 'string' ? assetSymbol : assetSymbol.symbol;
|
||||
const asset = data?.assetsConnection.edges?.find(
|
||||
const asset = data?.assetsConnection?.edges?.find(
|
||||
(e) => e?.node.symbol === symbol
|
||||
);
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './__generated__/Assets';
|
||||
export * from './__generated___/Assets';
|
||||
export * from './asset-details-dialog';
|
||||
|
||||
@@ -11,7 +11,10 @@ import type {
|
||||
DepositEventSub_busEvents_event,
|
||||
DepositEventSub_busEvents_event_Deposit,
|
||||
} from './__generated__/DepositEventSub';
|
||||
import type { Deposits, DepositsVariables } from './__generated__/Deposits';
|
||||
import type {
|
||||
DepositsQuery,
|
||||
DepositsQueryVariables,
|
||||
} from './__generated__/DepositsQuery';
|
||||
|
||||
const DEPOSIT_FRAGMENT = gql`
|
||||
fragment DepositFields on Deposit {
|
||||
@@ -61,15 +64,15 @@ const DEPOSITS_BUS_EVENT_SUB = gql`
|
||||
export const useDeposits = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { data, loading, error, subscribeToMore } = useQuery<
|
||||
Deposits,
|
||||
DepositsVariables
|
||||
DepositsQuery,
|
||||
DepositsQueryVariables
|
||||
>(DEPOSITS_QUERY, {
|
||||
variables: { partyId: keypair?.pub || '' },
|
||||
skip: !keypair?.pub,
|
||||
});
|
||||
|
||||
const deposits = useMemo(() => {
|
||||
if (!data?.party?.depositsConnection.edges?.length) {
|
||||
if (!data?.party?.depositsConnection?.edges?.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -98,7 +101,7 @@ export const useDeposits = () => {
|
||||
};
|
||||
|
||||
const updateQuery: UpdateQueryFn<
|
||||
Deposits,
|
||||
DepositsQuery,
|
||||
DepositEventSubVariables,
|
||||
DepositEventSub
|
||||
> = (prev, { subscriptionData, variables }) => {
|
||||
@@ -108,7 +111,7 @@ const updateQuery: UpdateQueryFn<
|
||||
}
|
||||
|
||||
const curr =
|
||||
compact(prev.party?.depositsConnection.edges?.map((e) => e?.node)) || [];
|
||||
compact(prev.party?.depositsConnection?.edges?.map((e) => e?.node)) || [];
|
||||
const incoming = subscriptionData.data.busEvents
|
||||
.map((e) => e.event)
|
||||
.filter(isDepositEvent);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from './lib/fills-container';
|
||||
export * from './lib/__generated__/FillFields';
|
||||
export * from './lib/__generated__/Fills';
|
||||
export * from './lib/__generated__/FillsSub';
|
||||
|
||||
@@ -6,16 +6,14 @@ import {
|
||||
defaultAppend as append,
|
||||
} from '@vegaprotocol/react-helpers';
|
||||
import type { PageInfo } from '@vegaprotocol/react-helpers';
|
||||
import type { FillFields } from './__generated__/FillFields';
|
||||
import type {
|
||||
Fills,
|
||||
Fills_party_tradesConnection_edges,
|
||||
Fills_party_tradesConnection_edges_node,
|
||||
} from './__generated__/Fills';
|
||||
import type { FillsSub } from './__generated__/FillsSub';
|
||||
import type { FillsSub, FillsSub_trades } from './__generated__/FillsSub';
|
||||
|
||||
export const FILLS_QUERY = gql`
|
||||
${FILL_FRAGMENT}
|
||||
query Fills($partyId: ID!, $marketId: ID, $pagination: Pagination) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
@@ -109,7 +107,7 @@ export const FILLS_SUB = gql`
|
||||
|
||||
const update = (
|
||||
data: (Fills_party_tradesConnection_edges | null)[],
|
||||
delta: FillFields[]
|
||||
delta: FillsSub_trades[]
|
||||
) => {
|
||||
return produce(data, (draft) => {
|
||||
orderBy(delta, 'createdAt').forEach((node) => {
|
||||
@@ -134,10 +132,10 @@ const update = (
|
||||
const getData = (
|
||||
responseData: Fills
|
||||
): Fills_party_tradesConnection_edges[] | null =>
|
||||
responseData.party?.tradesConnection.edges || null;
|
||||
responseData.party?.tradesConnection?.edges || null;
|
||||
|
||||
const getPageInfo = (responseData: Fills): PageInfo | null =>
|
||||
responseData.party?.tradesConnection.pageInfo || null;
|
||||
responseData.party?.tradesConnection?.pageInfo || null;
|
||||
|
||||
const getDelta = (subscriptionData: FillsSub) => subscriptionData.trades || [];
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export const getProposals = (data?: ProposalsConnection) => {
|
||||
return proposals ? (proposals as Proposal[]) : [];
|
||||
};
|
||||
|
||||
const orderByDate = (arr: Proposal[]) =>
|
||||
export const orderByDate = (arr: Proposal[]) =>
|
||||
orderBy(
|
||||
arr,
|
||||
[
|
||||
|
||||
@@ -16,9 +16,9 @@ import {
|
||||
useState,
|
||||
useContext,
|
||||
} from 'react';
|
||||
import type { MarketDepthSubscription_marketDepthUpdate } from './__generated__/MarketDepthSubscription';
|
||||
import type { DepthChartProps } from 'pennant';
|
||||
import { parseLevel, updateLevels } from './depth-chart-utils';
|
||||
import type { MarketDepthSubscription_marketsDepthUpdate } from './__generated__/MarketDepthSubscription';
|
||||
|
||||
interface DepthChartManagerProps {
|
||||
marketId: string;
|
||||
@@ -40,7 +40,7 @@ export const DepthChartContainer = ({ marketId }: DepthChartManagerProps) => {
|
||||
|
||||
// Apply updates to the table
|
||||
const update = useCallback(
|
||||
({ delta }: { delta: MarketDepthSubscription_marketDepthUpdate }) => {
|
||||
({ delta }: { delta: MarketDepthSubscription_marketsDepthUpdate }) => {
|
||||
if (!dataRef.current) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,8 @@ import type { PageInfo } from '@vegaprotocol/react-helpers';
|
||||
import type {
|
||||
Orders,
|
||||
Orders_party_ordersConnection_edges,
|
||||
OrderSub,
|
||||
OrderFields,
|
||||
} from '../';
|
||||
} from './__generated__/Orders';
|
||||
import type { OrderSub, OrderSub_orders } from './__generated__/OrderSub';
|
||||
|
||||
export const ORDERS_QUERY = gql`
|
||||
query Orders($partyId: ID!, $pagination: Pagination) {
|
||||
@@ -81,7 +80,7 @@ export const ORDERS_SUB = gql`
|
||||
|
||||
export const update = (
|
||||
data: Orders_party_ordersConnection_edges[],
|
||||
delta: OrderFields[]
|
||||
delta: OrderSub_orders[]
|
||||
) => {
|
||||
return produce(data, (draft) => {
|
||||
// A single update can contain the same order with multiple updates, so we need to find
|
||||
@@ -112,12 +111,12 @@ export const update = (
|
||||
const getData = (
|
||||
responseData: Orders
|
||||
): Orders_party_ordersConnection_edges[] | null =>
|
||||
responseData?.party?.ordersConnection.edges || null;
|
||||
responseData?.party?.ordersConnection?.edges || null;
|
||||
|
||||
const getDelta = (subscriptionData: OrderSub) => subscriptionData.orders || [];
|
||||
|
||||
const getPageInfo = (responseData: Orders): PageInfo | null =>
|
||||
responseData.party?.ordersConnection.pageInfo || null;
|
||||
responseData.party?.ordersConnection?.pageInfo || null;
|
||||
|
||||
export const ordersDataProvider = makeDataProvider({
|
||||
query: ORDERS_QUERY,
|
||||
|
||||
@@ -128,7 +128,7 @@ export const updateQuery: UpdateQueryFn<
|
||||
return prev;
|
||||
}
|
||||
|
||||
const curr = prev.party?.withdrawalsConnection.edges || [];
|
||||
const curr = prev.party?.withdrawalsConnection?.edges || [];
|
||||
const incoming = subscriptionData.data.busEvents
|
||||
.map((e) => {
|
||||
return {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import compact from 'lodash/compact';
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { getEnabledAssets, t } from '@vegaprotocol/react-helpers';
|
||||
import { t } from '@vegaprotocol/react-helpers';
|
||||
import { useMemo } from 'react';
|
||||
import type { WithdrawalArgs } from './use-create-withdraw';
|
||||
import { WithdrawManager } from './withdraw-manager';
|
||||
import type { WithdrawFormQuery } from './__generated__/WithdrawFormQuery';
|
||||
import { AssetStatus } from '@vegaprotocol/types';
|
||||
|
||||
export const ASSET_FRAGMENT = gql`
|
||||
fragment AssetFields on Asset {
|
||||
@@ -65,11 +67,13 @@ export const WithdrawFormContainer = ({
|
||||
);
|
||||
|
||||
const assets = useMemo(() => {
|
||||
if (!data?.assetsConnection.edges) {
|
||||
if (!data?.assetsConnection?.edges) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return getEnabledAssets(data);
|
||||
return compact(data.assetsConnection.edges)
|
||||
.map((e) => e.node)
|
||||
.filter((a) => a.status === AssetStatus.STATUS_ENABLED);
|
||||
}, [data]);
|
||||
|
||||
if (loading || !data) {
|
||||
|
||||
Reference in New Issue
Block a user