chore: migrate governance types (#1834)

* chore: migrate governance types

* fix: format

* fix: import
This commit is contained in:
botond 2022-10-24 12:51:48 +02:00 committed by GitHub
parent da726ea439
commit 26d277d775
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 48 additions and 113 deletions

View File

@ -3,11 +3,11 @@ import {
getProposalDialogIntent, getProposalDialogIntent,
getProposalDialogTitle, getProposalDialogTitle,
} from '@vegaprotocol/governance'; } from '@vegaprotocol/governance';
import type { ProposalEvent_busEvents_event_Proposal } from '@vegaprotocol/governance'; import type { ProposalEventFieldsFragment } from '@vegaprotocol/governance';
import type { DialogProps } from '@vegaprotocol/wallet'; import type { DialogProps } from '@vegaprotocol/wallet';
interface ProposalFormTransactionDialogProps { interface ProposalFormTransactionDialogProps {
finalizedProposal: ProposalEvent_busEvents_event_Proposal | null; finalizedProposal: ProposalEventFieldsFragment | null;
TransactionDialog: (props: DialogProps) => JSX.Element; TransactionDialog: (props: DialogProps) => JSX.Element;
} }

View File

@ -11,14 +11,14 @@ import {
ProposalState, ProposalState,
} from '@vegaprotocol/types'; } from '@vegaprotocol/types';
import { ProposeRaw } from './propose-raw'; import { ProposeRaw } from './propose-raw';
import { PROPOSAL_EVENT_SUB } from '@vegaprotocol/governance'; import { ProposalEventDocument } from '@vegaprotocol/governance';
import type { ProposalEvent } from '@vegaprotocol/governance'; import type { ProposalEventSubscription } from '@vegaprotocol/governance';
describe('Raw proposal form', () => { describe('Raw proposal form', () => {
const pubKey = '0x123'; const pubKey = '0x123';
const mockProposalEvent: MockedResponse<ProposalEvent> = { const mockProposalEvent: MockedResponse<ProposalEventSubscription> = {
request: { request: {
query: PROPOSAL_EVENT_SUB, query: ProposalEventDocument,
variables: { variables: {
partyId: pubKey, partyId: pubKey,
}, },

View File

@ -1,13 +1,17 @@
fragment ProposalEventFields on Proposal {
id
reference
state
rejectionReason
errorDetails
}
subscription ProposalEvent($partyId: ID!) { subscription ProposalEvent($partyId: ID!) {
busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) { busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) {
type type
event { event {
... on Proposal { ... on Proposal {
id ...ProposalEventFields
reference
state
rejectionReason
errorDetails
} }
} }
} }

View File

@ -3,6 +3,8 @@ import { Schema as Types } from '@vegaprotocol/types';
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
import * as Apollo from '@apollo/client'; import * as Apollo from '@apollo/client';
const defaultOptions = {} as const; 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<{ export type ProposalEventSubscriptionVariables = Types.Exact<{
partyId: Types.Scalars['ID']; 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 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` export const ProposalEventDocument = gql`
subscription ProposalEvent($partyId: ID!) { subscription ProposalEvent($partyId: ID!) {
busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) { busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) {
type type
event { event {
... on Proposal { ... on Proposal {
id ...ProposalEventFields
reference
state
rejectionReason
errorDetails
} }
} }
} }
} }
`; ${ProposalEventFieldsFragmentDoc}`;
/** /**
* __useProposalEventSubscription__ * __useProposalEventSubscription__

View File

@ -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;
}

View File

@ -1,3 +1,3 @@
export * from './__generated__/ProposalEvent'; export * from './__generated__/Proposal';
export * from './use-proposal-event'; export * from './use-proposal-event';
export * from './use-proposal-submit'; export * from './use-proposal-submit';

View File

@ -1,30 +1,14 @@
import { useApolloClient, gql } from '@apollo/client'; import { useApolloClient } from '@apollo/client';
import { useCallback, useEffect, useRef } from 'react'; import { useCallback, useEffect, useRef } from 'react';
import { ProposalEventDocument } from './__generated__/Proposal';
import type { import type {
ProposalEvent, ProposalEventSubscriptionVariables,
ProposalEventVariables, ProposalEventSubscription,
ProposalEvent_busEvents_event_Proposal, ProposalEventFieldsFragment,
} from './__generated__/ProposalEvent'; } from './__generated__/Proposal';
import type { Subscription } from 'zen-observable-ts'; import type { Subscription } from 'zen-observable-ts';
import type { VegaTxState } from '@vegaprotocol/wallet'; 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) => { export const useProposalEvent = (transaction: VegaTxState) => {
const client = useApolloClient(); const client = useApolloClient();
const subRef = useRef<Subscription | null>(null); const subRef = useRef<Subscription | null>(null);
@ -33,11 +17,14 @@ export const useProposalEvent = (transaction: VegaTxState) => {
( (
id: string, id: string,
partyId: string, partyId: string,
callback: (proposal: ProposalEvent_busEvents_event_Proposal) => void callback: (proposal: ProposalEventFieldsFragment) => void
) => { ) => {
subRef.current = client subRef.current = client
.subscribe<ProposalEvent, ProposalEventVariables>({ .subscribe<
query: PROPOSAL_EVENT_SUB, ProposalEventSubscription,
ProposalEventSubscriptionVariables
>({
query: ProposalEventDocument,
variables: { partyId }, variables: { partyId },
}) })
.subscribe(({ data }) => { .subscribe(({ data }) => {

View File

@ -7,7 +7,7 @@ import {
} from '@vegaprotocol/wallet'; } from '@vegaprotocol/wallet';
import { useProposalEvent } from './use-proposal-event'; import { useProposalEvent } from './use-proposal-event';
import type { ProposalSubmission } from '@vegaprotocol/wallet'; import type { ProposalSubmission } from '@vegaprotocol/wallet';
import type { ProposalEvent_busEvents_event_Proposal } from './__generated__/ProposalEvent'; import type { ProposalEventFieldsFragment } from './__generated__/Proposal';
export const useProposalSubmit = () => { export const useProposalSubmit = () => {
const { pubKey } = useVegaWallet(); const { pubKey } = useVegaWallet();
@ -16,7 +16,7 @@ export const useProposalSubmit = () => {
const waitForProposalEvent = useProposalEvent(transaction); const waitForProposalEvent = useProposalEvent(transaction);
const [finalizedProposal, setFinalizedProposal] = const [finalizedProposal, setFinalizedProposal] =
useState<ProposalEvent_busEvents_event_Proposal | null>(null); useState<ProposalEventFieldsFragment | null>(null);
const submit = useCallback( const submit = useCallback(
async (proposal: ProposalSubmission) => { async (proposal: ProposalSubmission) => {

View File

@ -2,12 +2,12 @@ import compact from 'lodash/compact';
import filter from 'lodash/filter'; import filter from 'lodash/filter';
import flow from 'lodash/flow'; import flow from 'lodash/flow';
import orderBy from 'lodash/orderBy'; import orderBy from 'lodash/orderBy';
import { ProposalState } from '@vegaprotocol/types'; import { Schema } from '@vegaprotocol/types';
type Proposal = { type Proposal = {
__typename: 'Proposal'; __typename: 'Proposal';
id: string | null; id: string | null;
state: ProposalState; state: Schema.ProposalState;
terms: { terms: {
enactmentDatetime: string | null; enactmentDatetime: string | null;
closingDatetime: string; closingDatetime: string;
@ -46,7 +46,7 @@ export const getNotRejectedProposals = (data?: ProposalsConnection) => {
return flow([ return flow([
compact, compact,
(arr: Proposal[]) => (arr: Proposal[]) =>
filter(arr, ({ state }) => state !== ProposalState.STATE_REJECTED), filter(arr, ({ state }) => state !== Schema.ProposalState.STATE_REJECTED),
orderByDate, orderByDate,
])(proposals); ])(proposals);
}; };
@ -56,7 +56,7 @@ export const getRejectedProposals = (data?: ProposalsConnection) => {
return flow([ return flow([
compact, compact,
(arr: Proposal[]) => (arr: Proposal[]) =>
filter(arr, ({ state }) => state === ProposalState.STATE_REJECTED), filter(arr, ({ state }) => state === Schema.ProposalState.STATE_REJECTED),
orderByDate, orderByDate,
])(proposals); ])(proposals);
}; };

View File

@ -21,6 +21,7 @@ module.exports = {
'../../libs/deposits/**', '../../libs/deposits/**',
'../../libs/environment/**', '../../libs/environment/**',
'../../libs/fills/**', '../../libs/fills/**',
'../../libs/governance/**',
], ],
}, },
}; };