feat(governance): replace proposal and vote busEvents with subscriptions (#2862)

This commit is contained in:
Sam Keen 2023-02-08 09:42:20 +00:00 committed by GitHub
parent 47e4861fdb
commit da551f9d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 86 deletions

View File

@ -15,7 +15,7 @@ export const ProposalFormTransactionDialog = ({
finalizedProposal, finalizedProposal,
TransactionDialog, TransactionDialog,
}: ProposalFormTransactionDialogProps) => { }: ProposalFormTransactionDialogProps) => {
// Render a custom complete UI if the proposal was rejected other wise // Render a custom complete UI if the proposal was rejected otherwise
// pass undefined so that the default vega transaction dialog UI gets used // pass undefined so that the default vega transaction dialog UI gets used
const completeContent = finalizedProposal?.rejectionReason ? ( const completeContent = finalizedProposal?.rejectionReason ? (
<p>{finalizedProposal.rejectionReason}</p> <p>{finalizedProposal.rejectionReason}</p>

View File

@ -90,22 +90,15 @@ describe('Raw proposal form', () => {
}, },
result: { result: {
data: { data: {
busEvents: [ proposals: {
{ __typename: 'Proposal',
__typename: 'BusEvent', id: '2fca514cebf9f465ae31ecb4c5721e3a6f5f260425ded887ca50ba15b81a5d50',
type: Schema.BusEventType.Proposal, reference: 'proposal-reference',
event: { state: Schema.ProposalState.STATE_OPEN,
__typename: 'Proposal', rejectionReason:
id: '2fca514cebf9f465ae31ecb4c5721e3a6f5f260425ded887ca50ba15b81a5d50', Schema.ProposalRejectionReason.PROPOSAL_ERROR_CLOSE_TIME_TOO_LATE,
reference: 'proposal-reference', errorDetails: 'error-details',
state: Schema.ProposalState.STATE_OPEN, },
rejectionReason:
Schema.ProposalRejectionReason
.PROPOSAL_ERROR_CLOSE_TIME_TOO_LATE,
errorDetails: 'error-details',
},
},
],
}, },
}, },
delay: 300, delay: 300,

View File

@ -7,13 +7,8 @@ fragment ProposalEventFields on Proposal {
} }
subscription ProposalEvent($partyId: ID!) { subscription ProposalEvent($partyId: ID!) {
busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) { proposals(partyId: $partyId) {
type ...ProposalEventFields
event {
... on Proposal {
...ProposalEventFields
}
}
} }
} }

View File

@ -10,7 +10,7 @@ export type ProposalEventSubscriptionVariables = Types.Exact<{
}>; }>;
export type ProposalEventSubscription = { __typename?: 'Subscription', busEvents?: Array<{ __typename?: 'BusEvent', type: Types.BusEventType, event: { __typename?: 'AccountEvent' } | { __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', proposals: { __typename?: 'Proposal', id?: string | null, reference: string, state: Types.ProposalState, rejectionReason?: Types.ProposalRejectionReason | null, errorDetails?: string | null } };
export type UpdateNetworkParameterFieldsFragment = { __typename?: 'Proposal', id?: string | null, state: Types.ProposalState, datetime: any, terms: { __typename?: 'ProposalTerms', enactmentDatetime?: any | null, change: { __typename?: 'NewAsset' } | { __typename?: 'NewFreeform' } | { __typename?: 'NewMarket' } | { __typename?: 'UpdateAsset' } | { __typename?: 'UpdateMarket' } | { __typename?: 'UpdateNetworkParameter', networkParameter: { __typename?: 'NetworkParameter', key: string, value: string } } } }; export type UpdateNetworkParameterFieldsFragment = { __typename?: 'Proposal', id?: string | null, state: Types.ProposalState, datetime: any, terms: { __typename?: 'ProposalTerms', enactmentDatetime?: any | null, change: { __typename?: 'NewAsset' } | { __typename?: 'NewFreeform' } | { __typename?: 'NewMarket' } | { __typename?: 'UpdateAsset' } | { __typename?: 'UpdateMarket' } | { __typename?: 'UpdateNetworkParameter', networkParameter: { __typename?: 'NetworkParameter', key: string, value: string } } } };
@ -55,13 +55,8 @@ export const UpdateNetworkParameterFieldsFragmentDoc = gql`
`; `;
export const ProposalEventDocument = gql` export const ProposalEventDocument = gql`
subscription ProposalEvent($partyId: ID!) { subscription ProposalEvent($partyId: ID!) {
busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) { proposals(partyId: $partyId) {
type ...ProposalEventFields
event {
... on Proposal {
...ProposalEventFields
}
}
} }
} }
${ProposalEventFieldsFragmentDoc}`; ${ProposalEventFieldsFragmentDoc}`;

View File

@ -28,24 +28,15 @@ export const useProposalEvent = (transaction: VegaTxState) => {
variables: { partyId }, variables: { partyId },
}) })
.subscribe(({ data }) => { .subscribe(({ data }) => {
if (!data?.busEvents?.length) { if (!data?.proposals) {
return; return;
} }
// No types available for the subscription result // typo in 'proposals' - this should be singular
const matchingProposalEvent = data.busEvents.find((e) => { const proposal = data.proposals;
if (e.event.__typename !== 'Proposal') {
return false;
}
return e.event.id === id; if (proposal.id === id) {
}); callback(proposal);
if (
matchingProposalEvent &&
matchingProposalEvent.event.__typename === 'Proposal'
) {
callback(matchingProposalEvent.event);
subRef.current?.unsubscribe(); subRef.current?.unsubscribe();
} }
}); });

View File

@ -1,18 +1,13 @@
fragment VoteEventFields on Vote { fragment VoteEventFields on ProposalVote {
proposalId proposalId
value vote {
datetime value
datetime
}
} }
subscription VoteEvent($partyId: ID!) { subscription VoteEvent($partyId: ID!) {
busEvents(partyId: $partyId, batchSize: 0, types: [Vote]) { votes(partyId: $partyId) {
type ...VoteEventFields
event {
... on Vote {
proposalId
value
datetime
}
}
} }
} }

View File

@ -3,36 +3,31 @@ import * 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 VoteEventFieldsFragment = { __typename?: 'Vote', proposalId: string, value: Types.VoteValue, datetime: any }; export type VoteEventFieldsFragment = { __typename?: 'ProposalVote', proposalId: string, vote: { __typename?: 'Vote', value: Types.VoteValue, datetime: any } };
export type VoteEventSubscriptionVariables = Types.Exact<{ export type VoteEventSubscriptionVariables = Types.Exact<{
partyId: Types.Scalars['ID']; partyId: Types.Scalars['ID'];
}>; }>;
export type VoteEventSubscription = { __typename?: 'Subscription', busEvents?: Array<{ __typename?: 'BusEvent', type: Types.BusEventType, event: { __typename?: 'AccountEvent' } | { __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' } | { __typename?: 'RiskFactor' } | { __typename?: 'SettleDistressed' } | { __typename?: 'SettlePosition' } | { __typename?: 'TimeUpdate' } | { __typename?: 'Trade' } | { __typename?: 'TransactionResult' } | { __typename?: 'TransferResponses' } | { __typename?: 'Vote', proposalId: string, value: Types.VoteValue, datetime: any } | { __typename?: 'Withdrawal' } }> | null }; export type VoteEventSubscription = { __typename?: 'Subscription', votes: { __typename?: 'ProposalVote', proposalId: string, vote: { __typename?: 'Vote', value: Types.VoteValue, datetime: any } } };
export const VoteEventFieldsFragmentDoc = gql` export const VoteEventFieldsFragmentDoc = gql`
fragment VoteEventFields on Vote { fragment VoteEventFields on ProposalVote {
proposalId proposalId
value vote {
datetime value
datetime
}
} }
`; `;
export const VoteEventDocument = gql` export const VoteEventDocument = gql`
subscription VoteEvent($partyId: ID!) { subscription VoteEvent($partyId: ID!) {
busEvents(partyId: $partyId, batchSize: 0, types: [Vote]) { votes(partyId: $partyId) {
type ...VoteEventFields
event {
... on Vote {
proposalId
value
datetime
}
}
} }
} }
`; ${VoteEventFieldsFragmentDoc}`;
/** /**
* __useVoteEventSubscription__ * __useVoteEventSubscription__

View File

@ -25,23 +25,14 @@ export const useVoteEvent = (transaction: VegaTxState) => {
variables: { partyId }, variables: { partyId },
}) })
.subscribe(({ data }) => { .subscribe(({ data }) => {
if (!data?.busEvents?.length) { if (!data?.votes) {
return; return;
} }
const matchingVoteEvent = data.busEvents.find((e) => { const vote = data.votes;
if (e.event.__typename !== 'Vote') {
return false;
}
return e.event.proposalId === proposalId; if (vote.proposalId === proposalId) {
}); callback(vote);
if (
matchingVoteEvent &&
matchingVoteEvent.event.__typename === 'Vote'
) {
callback(matchingVoteEvent.event);
subRef.current?.unsubscribe(); subRef.current?.unsubscribe();
} }
}); });