diff --git a/apps/token/src/routes/governance/components/propose/proposal-form-transaction-dialog.tsx b/apps/token/src/routes/governance/components/propose/proposal-form-transaction-dialog.tsx index a3ae3df6a..5d9e02c83 100644 --- a/apps/token/src/routes/governance/components/propose/proposal-form-transaction-dialog.tsx +++ b/apps/token/src/routes/governance/components/propose/proposal-form-transaction-dialog.tsx @@ -3,11 +3,11 @@ import { getProposalDialogIntent, getProposalDialogTitle, } from '@vegaprotocol/governance'; -import type { ProposalEvent_busEvents_event_Proposal } from '@vegaprotocol/governance'; +import type { ProposalEventFieldsFragment } from '@vegaprotocol/governance'; import type { DialogProps } from '@vegaprotocol/wallet'; interface ProposalFormTransactionDialogProps { - finalizedProposal: ProposalEvent_busEvents_event_Proposal | null; + finalizedProposal: ProposalEventFieldsFragment | null; TransactionDialog: (props: DialogProps) => JSX.Element; } diff --git a/apps/token/src/routes/governance/propose/raw/proposal-raw.spec.tsx b/apps/token/src/routes/governance/propose/raw/proposal-raw.spec.tsx index 038c5e7af..b779c3161 100644 --- a/apps/token/src/routes/governance/propose/raw/proposal-raw.spec.tsx +++ b/apps/token/src/routes/governance/propose/raw/proposal-raw.spec.tsx @@ -11,14 +11,14 @@ import { ProposalState, } from '@vegaprotocol/types'; import { ProposeRaw } from './propose-raw'; -import { PROPOSAL_EVENT_SUB } from '@vegaprotocol/governance'; -import type { ProposalEvent } from '@vegaprotocol/governance'; +import { ProposalEventDocument } from '@vegaprotocol/governance'; +import type { ProposalEventSubscription } from '@vegaprotocol/governance'; describe('Raw proposal form', () => { const pubKey = '0x123'; - const mockProposalEvent: MockedResponse = { + const mockProposalEvent: MockedResponse = { request: { - query: PROPOSAL_EVENT_SUB, + query: ProposalEventDocument, variables: { partyId: pubKey, }, diff --git a/libs/governance/src/lib/proposals-hooks/Proposal.graphql b/libs/governance/src/lib/proposals-hooks/Proposal.graphql index 82c11ee53..4034f7863 100644 --- a/libs/governance/src/lib/proposals-hooks/Proposal.graphql +++ b/libs/governance/src/lib/proposals-hooks/Proposal.graphql @@ -1,13 +1,17 @@ +fragment ProposalEventFields on Proposal { + id + reference + state + rejectionReason + errorDetails +} + subscription ProposalEvent($partyId: ID!) { busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) { type event { ... on Proposal { - id - reference - state - rejectionReason - errorDetails + ...ProposalEventFields } } } diff --git a/libs/governance/src/lib/proposals-hooks/__generated___/Proposal.ts b/libs/governance/src/lib/proposals-hooks/__generated__/Proposal.ts similarity index 86% rename from libs/governance/src/lib/proposals-hooks/__generated___/Proposal.ts rename to libs/governance/src/lib/proposals-hooks/__generated__/Proposal.ts index 015487e49..0c2e42922 100644 --- a/libs/governance/src/lib/proposals-hooks/__generated___/Proposal.ts +++ b/libs/governance/src/lib/proposals-hooks/__generated__/Proposal.ts @@ -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 ProposalEventFieldsFragment = { __typename?: 'Proposal', id?: string | null, reference: string, state: Types.ProposalState, rejectionReason?: Types.ProposalRejectionReason | null, errorDetails?: string | null }; + export type ProposalEventSubscriptionVariables = Types.Exact<{ partyId: Types.Scalars['ID']; }>; @@ -10,23 +12,27 @@ export type ProposalEventSubscriptionVariables = Types.Exact<{ export type ProposalEventSubscription = { __typename?: 'Subscription', busEvents?: Array<{ __typename?: 'BusEvent', type: Types.BusEventType, event: { __typename?: 'Account' } | { __typename?: 'Asset' } | { __typename?: 'AuctionEvent' } | { __typename?: 'Deposit' } | { __typename?: 'LiquidityProvision' } | { __typename?: 'LossSocialization' } | { __typename?: 'MarginLevels' } | { __typename?: 'Market' } | { __typename?: 'MarketData' } | { __typename?: 'MarketEvent' } | { __typename?: 'MarketTick' } | { __typename?: 'NodeSignature' } | { __typename?: 'OracleSpec' } | { __typename?: 'Order' } | { __typename?: 'Party' } | { __typename?: 'PositionResolution' } | { __typename?: 'Proposal', id?: string | null, reference: string, state: Types.ProposalState, rejectionReason?: Types.ProposalRejectionReason | null, errorDetails?: string | null } | { __typename?: 'RiskFactor' } | { __typename?: 'SettleDistressed' } | { __typename?: 'SettlePosition' } | { __typename?: 'TimeUpdate' } | { __typename?: 'Trade' } | { __typename?: 'TransactionResult' } | { __typename?: 'TransferResponses' } | { __typename?: 'Vote' } | { __typename?: 'Withdrawal' } }> | null }; - +export const ProposalEventFieldsFragmentDoc = gql` + fragment ProposalEventFields on Proposal { + id + reference + state + rejectionReason + errorDetails +} + `; export const ProposalEventDocument = gql` subscription ProposalEvent($partyId: ID!) { busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) { type event { ... on Proposal { - id - reference - state - rejectionReason - errorDetails + ...ProposalEventFields } } } } - `; + ${ProposalEventFieldsFragmentDoc}`; /** * __useProposalEventSubscription__ diff --git a/libs/governance/src/lib/proposals-hooks/__generated__/ProposalEvent.ts b/libs/governance/src/lib/proposals-hooks/__generated__/ProposalEvent.ts deleted file mode 100644 index d5ae586db..000000000 --- a/libs/governance/src/lib/proposals-hooks/__generated__/ProposalEvent.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -import { BusEventType, ProposalState, ProposalRejectionReason } from "@vegaprotocol/types"; - -// ==================================================== -// GraphQL subscription operation: ProposalEvent -// ==================================================== - -export interface ProposalEvent_busEvents_event_TimeUpdate { - __typename: "TimeUpdate" | "MarketEvent" | "TransferResponses" | "PositionResolution" | "Order" | "Trade" | "Account" | "Party" | "MarginLevels" | "Vote" | "MarketData" | "NodeSignature" | "LossSocialization" | "SettlePosition" | "Market" | "Asset" | "MarketTick" | "SettleDistressed" | "AuctionEvent" | "RiskFactor" | "Deposit" | "Withdrawal" | "OracleSpec" | "LiquidityProvision" | "TransactionResult"; -} - -export interface ProposalEvent_busEvents_event_Proposal { - __typename: "Proposal"; - /** - * Proposal ID that is filled by Vega once proposal reaches the network - */ - id: string | null; - /** - * A UUID reference to aid tracking proposals on Vega - */ - reference: string; - /** - * State of the proposal - */ - state: ProposalState; - /** - * Why the proposal was rejected by the core - */ - rejectionReason: ProposalRejectionReason | null; - /** - * Error details of the rejectionReason - */ - errorDetails: string | null; -} - -export type ProposalEvent_busEvents_event = ProposalEvent_busEvents_event_TimeUpdate | ProposalEvent_busEvents_event_Proposal; - -export interface ProposalEvent_busEvents { - __typename: "BusEvent"; - /** - * The type of event - */ - type: BusEventType; - /** - * The payload - the wrapped event - */ - event: ProposalEvent_busEvents_event; -} - -export interface ProposalEvent { - /** - * Subscribe to event data from the event bus - */ - busEvents: ProposalEvent_busEvents[] | null; -} - -export interface ProposalEventVariables { - partyId: string; -} diff --git a/libs/governance/src/lib/proposals-hooks/index.ts b/libs/governance/src/lib/proposals-hooks/index.ts index b7bdf98e1..18bfb7e9e 100644 --- a/libs/governance/src/lib/proposals-hooks/index.ts +++ b/libs/governance/src/lib/proposals-hooks/index.ts @@ -1,3 +1,3 @@ -export * from './__generated__/ProposalEvent'; +export * from './__generated__/Proposal'; export * from './use-proposal-event'; export * from './use-proposal-submit'; diff --git a/libs/governance/src/lib/proposals-hooks/use-proposal-event.ts b/libs/governance/src/lib/proposals-hooks/use-proposal-event.ts index 978c20889..4c2f5051f 100644 --- a/libs/governance/src/lib/proposals-hooks/use-proposal-event.ts +++ b/libs/governance/src/lib/proposals-hooks/use-proposal-event.ts @@ -1,30 +1,14 @@ -import { useApolloClient, gql } from '@apollo/client'; +import { useApolloClient } from '@apollo/client'; import { useCallback, useEffect, useRef } from 'react'; +import { ProposalEventDocument } from './__generated__/Proposal'; import type { - ProposalEvent, - ProposalEventVariables, - ProposalEvent_busEvents_event_Proposal, -} from './__generated__/ProposalEvent'; + ProposalEventSubscriptionVariables, + ProposalEventSubscription, + ProposalEventFieldsFragment, +} from './__generated__/Proposal'; import type { Subscription } from 'zen-observable-ts'; import type { VegaTxState } from '@vegaprotocol/wallet'; -export const PROPOSAL_EVENT_SUB = gql` - subscription ProposalEvent($partyId: ID!) { - busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) { - type - event { - ... on Proposal { - id - reference - state - rejectionReason - errorDetails - } - } - } - } -`; - export const useProposalEvent = (transaction: VegaTxState) => { const client = useApolloClient(); const subRef = useRef(null); @@ -33,11 +17,14 @@ export const useProposalEvent = (transaction: VegaTxState) => { ( id: string, partyId: string, - callback: (proposal: ProposalEvent_busEvents_event_Proposal) => void + callback: (proposal: ProposalEventFieldsFragment) => void ) => { subRef.current = client - .subscribe({ - query: PROPOSAL_EVENT_SUB, + .subscribe< + ProposalEventSubscription, + ProposalEventSubscriptionVariables + >({ + query: ProposalEventDocument, variables: { partyId }, }) .subscribe(({ data }) => { diff --git a/libs/governance/src/lib/proposals-hooks/use-proposal-submit.ts b/libs/governance/src/lib/proposals-hooks/use-proposal-submit.ts index 53b2a8c88..75ef7d579 100644 --- a/libs/governance/src/lib/proposals-hooks/use-proposal-submit.ts +++ b/libs/governance/src/lib/proposals-hooks/use-proposal-submit.ts @@ -7,7 +7,7 @@ import { } from '@vegaprotocol/wallet'; import { useProposalEvent } from './use-proposal-event'; import type { ProposalSubmission } from '@vegaprotocol/wallet'; -import type { ProposalEvent_busEvents_event_Proposal } from './__generated__/ProposalEvent'; +import type { ProposalEventFieldsFragment } from './__generated__/Proposal'; export const useProposalSubmit = () => { const { pubKey } = useVegaWallet(); @@ -16,7 +16,7 @@ export const useProposalSubmit = () => { const waitForProposalEvent = useProposalEvent(transaction); const [finalizedProposal, setFinalizedProposal] = - useState(null); + useState(null); const submit = useCallback( async (proposal: ProposalSubmission) => { diff --git a/libs/governance/src/lib/proposals-queries/proposals-queries.ts b/libs/governance/src/lib/proposals-queries/proposals-queries.ts index 9e66b33bd..232b4df5c 100644 --- a/libs/governance/src/lib/proposals-queries/proposals-queries.ts +++ b/libs/governance/src/lib/proposals-queries/proposals-queries.ts @@ -2,12 +2,12 @@ import compact from 'lodash/compact'; import filter from 'lodash/filter'; import flow from 'lodash/flow'; import orderBy from 'lodash/orderBy'; -import { ProposalState } from '@vegaprotocol/types'; +import { Schema } from '@vegaprotocol/types'; type Proposal = { __typename: 'Proposal'; id: string | null; - state: ProposalState; + state: Schema.ProposalState; terms: { enactmentDatetime: string | null; closingDatetime: string; @@ -46,7 +46,7 @@ export const getNotRejectedProposals = (data?: ProposalsConnection) => { return flow([ compact, (arr: Proposal[]) => - filter(arr, ({ state }) => state !== ProposalState.STATE_REJECTED), + filter(arr, ({ state }) => state !== Schema.ProposalState.STATE_REJECTED), orderByDate, ])(proposals); }; @@ -56,7 +56,7 @@ export const getRejectedProposals = (data?: ProposalsConnection) => { return flow([ compact, (arr: Proposal[]) => - filter(arr, ({ state }) => state === ProposalState.STATE_REJECTED), + filter(arr, ({ state }) => state === Schema.ProposalState.STATE_REJECTED), orderByDate, ])(proposals); }; diff --git a/libs/types/apollo.config.js b/libs/types/apollo.config.js index 033f22390..db4161a92 100644 --- a/libs/types/apollo.config.js +++ b/libs/types/apollo.config.js @@ -21,6 +21,7 @@ module.exports = { '../../libs/deposits/**', '../../libs/environment/**', '../../libs/fills/**', + '../../libs/governance/**', ], }, };