feat(governance): replace proposal and vote busEvents with subscriptions (#2862)
This commit is contained in:
parent
47e4861fdb
commit
da551f9d3c
@ -15,7 +15,7 @@ export const ProposalFormTransactionDialog = ({
|
||||
finalizedProposal,
|
||||
TransactionDialog,
|
||||
}: 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
|
||||
const completeContent = finalizedProposal?.rejectionReason ? (
|
||||
<p>{finalizedProposal.rejectionReason}</p>
|
||||
|
@ -90,22 +90,15 @@ describe('Raw proposal form', () => {
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
__typename: 'BusEvent',
|
||||
type: Schema.BusEventType.Proposal,
|
||||
event: {
|
||||
__typename: 'Proposal',
|
||||
id: '2fca514cebf9f465ae31ecb4c5721e3a6f5f260425ded887ca50ba15b81a5d50',
|
||||
reference: 'proposal-reference',
|
||||
state: Schema.ProposalState.STATE_OPEN,
|
||||
rejectionReason:
|
||||
Schema.ProposalRejectionReason
|
||||
.PROPOSAL_ERROR_CLOSE_TIME_TOO_LATE,
|
||||
errorDetails: 'error-details',
|
||||
},
|
||||
},
|
||||
],
|
||||
proposals: {
|
||||
__typename: 'Proposal',
|
||||
id: '2fca514cebf9f465ae31ecb4c5721e3a6f5f260425ded887ca50ba15b81a5d50',
|
||||
reference: 'proposal-reference',
|
||||
state: Schema.ProposalState.STATE_OPEN,
|
||||
rejectionReason:
|
||||
Schema.ProposalRejectionReason.PROPOSAL_ERROR_CLOSE_TIME_TOO_LATE,
|
||||
errorDetails: 'error-details',
|
||||
},
|
||||
},
|
||||
},
|
||||
delay: 300,
|
||||
|
@ -7,13 +7,8 @@ fragment ProposalEventFields on Proposal {
|
||||
}
|
||||
|
||||
subscription ProposalEvent($partyId: ID!) {
|
||||
busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) {
|
||||
type
|
||||
event {
|
||||
... on Proposal {
|
||||
...ProposalEventFields
|
||||
}
|
||||
}
|
||||
proposals(partyId: $partyId) {
|
||||
...ProposalEventFields
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 } } } };
|
||||
|
||||
@ -55,13 +55,8 @@ export const UpdateNetworkParameterFieldsFragmentDoc = gql`
|
||||
`;
|
||||
export const ProposalEventDocument = gql`
|
||||
subscription ProposalEvent($partyId: ID!) {
|
||||
busEvents(partyId: $partyId, batchSize: 0, types: [Proposal]) {
|
||||
type
|
||||
event {
|
||||
... on Proposal {
|
||||
...ProposalEventFields
|
||||
}
|
||||
}
|
||||
proposals(partyId: $partyId) {
|
||||
...ProposalEventFields
|
||||
}
|
||||
}
|
||||
${ProposalEventFieldsFragmentDoc}`;
|
||||
|
@ -28,24 +28,15 @@ export const useProposalEvent = (transaction: VegaTxState) => {
|
||||
variables: { partyId },
|
||||
})
|
||||
.subscribe(({ data }) => {
|
||||
if (!data?.busEvents?.length) {
|
||||
if (!data?.proposals) {
|
||||
return;
|
||||
}
|
||||
|
||||
// No types available for the subscription result
|
||||
const matchingProposalEvent = data.busEvents.find((e) => {
|
||||
if (e.event.__typename !== 'Proposal') {
|
||||
return false;
|
||||
}
|
||||
// typo in 'proposals' - this should be singular
|
||||
const proposal = data.proposals;
|
||||
|
||||
return e.event.id === id;
|
||||
});
|
||||
|
||||
if (
|
||||
matchingProposalEvent &&
|
||||
matchingProposalEvent.event.__typename === 'Proposal'
|
||||
) {
|
||||
callback(matchingProposalEvent.event);
|
||||
if (proposal.id === id) {
|
||||
callback(proposal);
|
||||
subRef.current?.unsubscribe();
|
||||
}
|
||||
});
|
||||
|
@ -1,18 +1,13 @@
|
||||
fragment VoteEventFields on Vote {
|
||||
fragment VoteEventFields on ProposalVote {
|
||||
proposalId
|
||||
value
|
||||
datetime
|
||||
vote {
|
||||
value
|
||||
datetime
|
||||
}
|
||||
}
|
||||
|
||||
subscription VoteEvent($partyId: ID!) {
|
||||
busEvents(partyId: $partyId, batchSize: 0, types: [Vote]) {
|
||||
type
|
||||
event {
|
||||
... on Vote {
|
||||
proposalId
|
||||
value
|
||||
datetime
|
||||
}
|
||||
}
|
||||
votes(partyId: $partyId) {
|
||||
...VoteEventFields
|
||||
}
|
||||
}
|
||||
|
@ -3,36 +3,31 @@ import * as Types from '@vegaprotocol/types';
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
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<{
|
||||
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`
|
||||
fragment VoteEventFields on Vote {
|
||||
fragment VoteEventFields on ProposalVote {
|
||||
proposalId
|
||||
value
|
||||
datetime
|
||||
vote {
|
||||
value
|
||||
datetime
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const VoteEventDocument = gql`
|
||||
subscription VoteEvent($partyId: ID!) {
|
||||
busEvents(partyId: $partyId, batchSize: 0, types: [Vote]) {
|
||||
type
|
||||
event {
|
||||
... on Vote {
|
||||
proposalId
|
||||
value
|
||||
datetime
|
||||
}
|
||||
}
|
||||
votes(partyId: $partyId) {
|
||||
...VoteEventFields
|
||||
}
|
||||
}
|
||||
`;
|
||||
${VoteEventFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useVoteEventSubscription__
|
||||
|
@ -25,23 +25,14 @@ export const useVoteEvent = (transaction: VegaTxState) => {
|
||||
variables: { partyId },
|
||||
})
|
||||
.subscribe(({ data }) => {
|
||||
if (!data?.busEvents?.length) {
|
||||
if (!data?.votes) {
|
||||
return;
|
||||
}
|
||||
|
||||
const matchingVoteEvent = data.busEvents.find((e) => {
|
||||
if (e.event.__typename !== 'Vote') {
|
||||
return false;
|
||||
}
|
||||
const vote = data.votes;
|
||||
|
||||
return e.event.proposalId === proposalId;
|
||||
});
|
||||
|
||||
if (
|
||||
matchingVoteEvent &&
|
||||
matchingVoteEvent.event.__typename === 'Vote'
|
||||
) {
|
||||
callback(matchingVoteEvent.event);
|
||||
if (vote.proposalId === proposalId) {
|
||||
callback(vote);
|
||||
subRef.current?.unsubscribe();
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user