From a89b2815ee75f656f461c8f64a5e1d9b438b5176 Mon Sep 17 00:00:00 2001 From: botond <105208209+notbot00@users.noreply.github.com> Date: Thu, 19 May 2022 12:12:13 +0100 Subject: [PATCH] Fix/Use the rationale field on Proposals (#406) * remove freeform from proposal query and replace it with the rationale field * fix: regenerate types and fix proposal names getter Co-authored-by: Botond --- .../src/lib/type-policies/proposal.spec.tsx | 88 ++++++++++++++----- apps/token/src/lib/type-policies/proposal.ts | 8 +- .../__generated__/ProposalFields.ts | 49 +++++++---- .../components/proposal/proposal.tsx | 2 +- .../proposals-list/proposals-list.tsx | 2 +- .../routes/governance/proposal-fragment.ts | 10 +-- .../proposal/__generated__/Proposal.ts | 49 +++++++---- .../proposals/__generated__/Proposals.ts | 49 +++++++---- .../test-helpers/generate-proposals.ts | 6 ++ .../rewards/home/__generated__/Rewards.ts | 2 +- 10 files changed, 179 insertions(+), 86 deletions(-) diff --git a/apps/token/src/lib/type-policies/proposal.spec.tsx b/apps/token/src/lib/type-policies/proposal.spec.tsx index 252e53cc9..4d391e1d2 100644 --- a/apps/token/src/lib/type-policies/proposal.spec.tsx +++ b/apps/token/src/lib/type-policies/proposal.spec.tsx @@ -1,25 +1,40 @@ +import { generateProposal } from '../../routes/governance/test-helpers/generate-proposals'; import { getProposalName } from './proposal'; +const proposal = generateProposal(); + it('New market', () => { const name = getProposalName({ - __typename: 'NewMarket', - decimalPlaces: 1, - instrument: { - __typename: 'InstrumentConfiguration', - name: 'Some market', + ...proposal, + terms: { + ...proposal.terms, + change: { + __typename: 'NewMarket', + decimalPlaces: 1, + instrument: { + __typename: 'InstrumentConfiguration', + name: 'Some market', + }, + metadata: [], + }, }, - metadata: [], }); expect(name).toEqual('New Market: Some market'); }); it('New asset', () => { const name = getProposalName({ - __typename: 'NewAsset', - symbol: 'FAKE', - source: { - __typename: 'ERC20', - contractAddress: '0x0', + ...proposal, + terms: { + ...proposal.terms, + change: { + __typename: 'NewAsset', + symbol: 'FAKE', + source: { + __typename: 'ERC20', + contractAddress: '0x0', + }, + }, }, }); expect(name).toEqual('New Asset: FAKE'); @@ -27,19 +42,31 @@ it('New asset', () => { it('Update market', () => { const name = getProposalName({ - __typename: 'UpdateMarket', - marketId: 'MarketId', + ...proposal, + terms: { + ...proposal.terms, + change: { + __typename: 'UpdateMarket', + marketId: 'MarketId', + }, + }, }); expect(name).toEqual('Update Market: MarketId'); }); it('Update network', () => { const name = getProposalName({ - __typename: 'UpdateNetworkParameter', - networkParameter: { - __typename: 'NetworkParameter', - key: 'key', - value: 'value', + ...proposal, + terms: { + ...proposal.terms, + change: { + __typename: 'UpdateNetworkParameter', + networkParameter: { + __typename: 'NetworkParameter', + key: 'key', + value: 'value', + }, + }, }, }); expect(name).toEqual('Update Network: key'); @@ -47,18 +74,31 @@ it('Update network', () => { it('Freeform network', () => { const name = getProposalName({ - __typename: 'NewFreeform', - hash: '0x0', - url: 'Earl', - description: 'Something else', + ...proposal, + rationale: { + ...proposal.rationale, + hash: '0x0', + }, + terms: { + ...proposal.terms, + change: { + __typename: 'NewFreeform', + }, + }, }); expect(name).toEqual('Freeform: 0x0'); }); it("Renders unknown proposal if it's a different proposal type", () => { const name = getProposalName({ - // @ts-ignore unknown proposal - __typename: 'Foo', + ...proposal, + terms: { + ...proposal.terms, + change: { + // @ts-ignore unknown proposal + __typename: 'Foo', + }, + }, }); expect(name).toEqual('Unknown Proposal'); }); diff --git a/apps/token/src/lib/type-policies/proposal.ts b/apps/token/src/lib/type-policies/proposal.ts index fedc63037..ef9be3db8 100644 --- a/apps/token/src/lib/type-policies/proposal.ts +++ b/apps/token/src/lib/type-policies/proposal.ts @@ -1,6 +1,8 @@ -import type { Proposals_proposals_terms_change } from '../../routes/governance/proposals/__generated__/Proposals'; +import type { Proposals_proposals } from '../../routes/governance/proposals/__generated__/Proposals'; + +export function getProposalName(proposal: Proposals_proposals) { + const { change } = proposal.terms; -export function getProposalName(change: Proposals_proposals_terms_change) { if (change.__typename === 'NewAsset') { return `New Asset: ${change.symbol}`; } else if (change.__typename === 'NewMarket') { @@ -10,7 +12,7 @@ export function getProposalName(change: Proposals_proposals_terms_change) { } else if (change.__typename === 'UpdateNetworkParameter') { return `Update Network: ${change.networkParameter.key}`; } else if (change.__typename === 'NewFreeform') { - return `Freeform: ${change.hash}`; + return `Freeform: ${proposal.rationale.hash}`; } return 'Unknown Proposal'; diff --git a/apps/token/src/routes/governance/__generated__/ProposalFields.ts b/apps/token/src/routes/governance/__generated__/ProposalFields.ts index 67a7651b5..43b7aca14 100644 --- a/apps/token/src/routes/governance/__generated__/ProposalFields.ts +++ b/apps/token/src/routes/governance/__generated__/ProposalFields.ts @@ -9,6 +9,29 @@ import { ProposalState, ProposalRejectionReason, VoteValue } from "@vegaprotocol // GraphQL fragment: ProposalFields // ==================================================== +export interface ProposalFields_rationale { + __typename: "ProposalRationale"; + /** + * Link to a text file describing the proposal in depth. + * Optional except for FreeFrom proposal where it's mandatory. + * If set, the `url` property must be set. + */ + url: string | null; + /** + * Description to show a short title / something in case the link goes offline. + * This is to be between 0 and 1024 unicode characters. + * This is mandatory for all proposal. + */ + description: string; + /** + * Cryptographically secure hash (SHA3-512) of the text pointed by the `url` property + * so that viewers can check that the text hasn't been changed over time. + * Optional except for FreeFrom proposal where it's mandatory. + * If set, the `url` property must be set. + */ + hash: string | null; +} + export interface ProposalFields_party { __typename: "Party"; /** @@ -17,6 +40,10 @@ export interface ProposalFields_party { id: string; } +export interface ProposalFields_terms_change_NewFreeform { + __typename: "NewFreeform"; +} + export interface ProposalFields_terms_change_NewMarket_instrument { __typename: "InstrumentConfiguration"; /** @@ -93,23 +120,7 @@ export interface ProposalFields_terms_change_UpdateNetworkParameter { networkParameter: ProposalFields_terms_change_UpdateNetworkParameter_networkParameter; } -export interface ProposalFields_terms_change_NewFreeform { - __typename: "NewFreeform"; - /** - * The URL containing content that describes the proposal - */ - url: string; - /** - * A short description of what is being proposed - */ - description: string; - /** - * The hash on the content of the URL - */ - hash: string; -} - -export type ProposalFields_terms_change = ProposalFields_terms_change_NewMarket | ProposalFields_terms_change_UpdateMarket | ProposalFields_terms_change_NewAsset | ProposalFields_terms_change_UpdateNetworkParameter | ProposalFields_terms_change_NewFreeform; +export type ProposalFields_terms_change = ProposalFields_terms_change_NewFreeform | ProposalFields_terms_change_NewMarket | ProposalFields_terms_change_UpdateMarket | ProposalFields_terms_change_NewAsset | ProposalFields_terms_change_UpdateNetworkParameter; export interface ProposalFields_terms { __typename: "ProposalTerms"; @@ -271,6 +282,10 @@ export interface ProposalFields { * Error details of the rejectionReason */ errorDetails: string | null; + /** + * Rationale behind the proposal + */ + rationale: ProposalFields_rationale; /** * Party that prepared the proposal */ diff --git a/apps/token/src/routes/governance/components/proposal/proposal.tsx b/apps/token/src/routes/governance/components/proposal/proposal.tsx index 077f4728c..63d6da0f0 100644 --- a/apps/token/src/routes/governance/components/proposal/proposal.tsx +++ b/apps/token/src/routes/governance/components/proposal/proposal.tsx @@ -19,7 +19,7 @@ export const Proposal = ({ proposal, terms }: ProposalProps) => { return ( <> - + diff --git a/apps/token/src/routes/governance/components/proposals-list/proposals-list.tsx b/apps/token/src/routes/governance/components/proposals-list/proposals-list.tsx index 00c9b7ad1..a279a2da8 100644 --- a/apps/token/src/routes/governance/components/proposals-list/proposals-list.tsx +++ b/apps/token/src/routes/governance/components/proposals-list/proposals-list.tsx @@ -26,7 +26,7 @@ export const ProposalsList = ({ proposals }: ProposalsListProps) => { return (
  • -
    {getProposalName(proposal.terms.change)}
    +
    {getProposalName(proposal)}
    diff --git a/apps/token/src/routes/governance/proposal-fragment.ts b/apps/token/src/routes/governance/proposal-fragment.ts index 0a5eb29da..885e8f4a5 100644 --- a/apps/token/src/routes/governance/proposal-fragment.ts +++ b/apps/token/src/routes/governance/proposal-fragment.ts @@ -8,6 +8,11 @@ export const PROPOSALS_FRAGMENT = gql` datetime rejectionReason errorDetails + rationale { + url + description + hash + } party { id } @@ -43,11 +48,6 @@ export const PROPOSALS_FRAGMENT = gql` value } } - ... on NewFreeform { - url - description - hash - } } } votes { diff --git a/apps/token/src/routes/governance/proposal/__generated__/Proposal.ts b/apps/token/src/routes/governance/proposal/__generated__/Proposal.ts index baaf01d9c..1e0b92e0b 100644 --- a/apps/token/src/routes/governance/proposal/__generated__/Proposal.ts +++ b/apps/token/src/routes/governance/proposal/__generated__/Proposal.ts @@ -9,6 +9,29 @@ import { ProposalState, ProposalRejectionReason, VoteValue } from "@vegaprotocol // GraphQL query operation: Proposal // ==================================================== +export interface Proposal_proposal_rationale { + __typename: "ProposalRationale"; + /** + * Link to a text file describing the proposal in depth. + * Optional except for FreeFrom proposal where it's mandatory. + * If set, the `url` property must be set. + */ + url: string | null; + /** + * Description to show a short title / something in case the link goes offline. + * This is to be between 0 and 1024 unicode characters. + * This is mandatory for all proposal. + */ + description: string; + /** + * Cryptographically secure hash (SHA3-512) of the text pointed by the `url` property + * so that viewers can check that the text hasn't been changed over time. + * Optional except for FreeFrom proposal where it's mandatory. + * If set, the `url` property must be set. + */ + hash: string | null; +} + export interface Proposal_proposal_party { __typename: "Party"; /** @@ -17,6 +40,10 @@ export interface Proposal_proposal_party { id: string; } +export interface Proposal_proposal_terms_change_NewFreeform { + __typename: "NewFreeform"; +} + export interface Proposal_proposal_terms_change_NewMarket_instrument { __typename: "InstrumentConfiguration"; /** @@ -93,23 +120,7 @@ export interface Proposal_proposal_terms_change_UpdateNetworkParameter { networkParameter: Proposal_proposal_terms_change_UpdateNetworkParameter_networkParameter; } -export interface Proposal_proposal_terms_change_NewFreeform { - __typename: "NewFreeform"; - /** - * The URL containing content that describes the proposal - */ - url: string; - /** - * A short description of what is being proposed - */ - description: string; - /** - * The hash on the content of the URL - */ - hash: string; -} - -export type Proposal_proposal_terms_change = Proposal_proposal_terms_change_NewMarket | Proposal_proposal_terms_change_UpdateMarket | Proposal_proposal_terms_change_NewAsset | Proposal_proposal_terms_change_UpdateNetworkParameter | Proposal_proposal_terms_change_NewFreeform; +export type Proposal_proposal_terms_change = Proposal_proposal_terms_change_NewFreeform | Proposal_proposal_terms_change_NewMarket | Proposal_proposal_terms_change_UpdateMarket | Proposal_proposal_terms_change_NewAsset | Proposal_proposal_terms_change_UpdateNetworkParameter; export interface Proposal_proposal_terms { __typename: "ProposalTerms"; @@ -271,6 +282,10 @@ export interface Proposal_proposal { * Error details of the rejectionReason */ errorDetails: string | null; + /** + * Rationale behind the proposal + */ + rationale: Proposal_proposal_rationale; /** * Party that prepared the proposal */ diff --git a/apps/token/src/routes/governance/proposals/__generated__/Proposals.ts b/apps/token/src/routes/governance/proposals/__generated__/Proposals.ts index e67532257..6e88f9d3e 100644 --- a/apps/token/src/routes/governance/proposals/__generated__/Proposals.ts +++ b/apps/token/src/routes/governance/proposals/__generated__/Proposals.ts @@ -9,6 +9,29 @@ import { ProposalState, ProposalRejectionReason, VoteValue } from "@vegaprotocol // GraphQL query operation: Proposals // ==================================================== +export interface Proposals_proposals_rationale { + __typename: "ProposalRationale"; + /** + * Link to a text file describing the proposal in depth. + * Optional except for FreeFrom proposal where it's mandatory. + * If set, the `url` property must be set. + */ + url: string | null; + /** + * Description to show a short title / something in case the link goes offline. + * This is to be between 0 and 1024 unicode characters. + * This is mandatory for all proposal. + */ + description: string; + /** + * Cryptographically secure hash (SHA3-512) of the text pointed by the `url` property + * so that viewers can check that the text hasn't been changed over time. + * Optional except for FreeFrom proposal where it's mandatory. + * If set, the `url` property must be set. + */ + hash: string | null; +} + export interface Proposals_proposals_party { __typename: "Party"; /** @@ -17,6 +40,10 @@ export interface Proposals_proposals_party { id: string; } +export interface Proposals_proposals_terms_change_NewFreeform { + __typename: "NewFreeform"; +} + export interface Proposals_proposals_terms_change_NewMarket_instrument { __typename: "InstrumentConfiguration"; /** @@ -93,23 +120,7 @@ export interface Proposals_proposals_terms_change_UpdateNetworkParameter { networkParameter: Proposals_proposals_terms_change_UpdateNetworkParameter_networkParameter; } -export interface Proposals_proposals_terms_change_NewFreeform { - __typename: "NewFreeform"; - /** - * The URL containing content that describes the proposal - */ - url: string; - /** - * A short description of what is being proposed - */ - description: string; - /** - * The hash on the content of the URL - */ - hash: string; -} - -export type Proposals_proposals_terms_change = Proposals_proposals_terms_change_NewMarket | Proposals_proposals_terms_change_UpdateMarket | Proposals_proposals_terms_change_NewAsset | Proposals_proposals_terms_change_UpdateNetworkParameter | Proposals_proposals_terms_change_NewFreeform; +export type Proposals_proposals_terms_change = Proposals_proposals_terms_change_NewFreeform | Proposals_proposals_terms_change_NewMarket | Proposals_proposals_terms_change_UpdateMarket | Proposals_proposals_terms_change_NewAsset | Proposals_proposals_terms_change_UpdateNetworkParameter; export interface Proposals_proposals_terms { __typename: "ProposalTerms"; @@ -271,6 +282,10 @@ export interface Proposals_proposals { * Error details of the rejectionReason */ errorDetails: string | null; + /** + * Rationale behind the proposal + */ + rationale: Proposals_proposals_rationale; /** * Party that prepared the proposal */ diff --git a/apps/token/src/routes/governance/test-helpers/generate-proposals.ts b/apps/token/src/routes/governance/test-helpers/generate-proposals.ts index d6d4a4f11..1dd27d9ed 100644 --- a/apps/token/src/routes/governance/test-helpers/generate-proposals.ts +++ b/apps/token/src/routes/governance/test-helpers/generate-proposals.ts @@ -24,6 +24,12 @@ export function generateProposal( __typename: 'Party', id: faker.datatype.uuid(), }, + rationale: { + __typename: 'ProposalRationale', + hash: faker.datatype.uuid(), + url: faker.internet.url(), + description: faker.lorem.words(), + }, terms: { __typename: 'ProposalTerms', closingDatetime: diff --git a/apps/token/src/routes/rewards/home/__generated__/Rewards.ts b/apps/token/src/routes/rewards/home/__generated__/Rewards.ts index 873fad413..0619f3bf8 100644 --- a/apps/token/src/routes/rewards/home/__generated__/Rewards.ts +++ b/apps/token/src/routes/rewards/home/__generated__/Rewards.ts @@ -46,7 +46,7 @@ export interface Rewards_party_rewardDetails_rewards_epoch { export interface Rewards_party_rewardDetails_rewards { __typename: "Reward"; /** - * The asset for which this reward is associated + * The asset this reward is paid in */ asset: Rewards_party_rewardDetails_rewards_asset; /**