Skip to content

Commit 34ebe49

Browse files
authored
Merge pull request #3787 from IntersectMBO/3745-display-authors-for-live-voting-governance-actions
(feat#3745): display authors for Live Voting Governance Actions
2 parents 83e3956 + 8188beb commit 34ebe49

File tree

10 files changed

+114
-11
lines changed

10 files changed

+114
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ changes.
1313
### Added
1414

1515
- Preserve maintenance ending banner state on the wallet connection change [Issue 3681](https://github.com/IntersectMBO/govtool/issues/3681)
16+
- Add authors for Live Voting Governance Actions [Issue 3745](https://github.com/IntersectMBO/govtool/issues/3745)
1617

1718
### Fixed
1819

govtool/backend/sql/list-proposals.sql

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,18 @@ SELECT
303303
COALESCE(cv.ccNoVotes, 0) cc_no_votes,
304304
COALESCE(cv.ccAbstainVotes, 0) cc_abstain_votes,
305305
prev_gov_action.index as prev_gov_action_index,
306-
encode(prev_gov_action_tx.hash, 'hex') as prev_gov_action_tx_hash
306+
encode(prev_gov_action_tx.hash, 'hex') as prev_gov_action_tx_hash,
307+
COALESCE(
308+
json_agg(
309+
json_build_object(
310+
'name', off_chain_vote_author.name,
311+
'witness_algorithm', off_chain_vote_author.witness_algorithm,
312+
'public_key', off_chain_vote_author.public_key,
313+
'signature', off_chain_vote_author.signature
314+
)
315+
) FILTER (WHERE off_chain_vote_author.id IS NOT NULL),
316+
'[]'
317+
) authors
307318
FROM
308319
gov_action_proposal
309320
JOIN ActiveProposals ON gov_action_proposal.id = ActiveProposals.id
@@ -314,6 +325,7 @@ FROM
314325
LEFT JOIN block AS creator_block ON creator_block.id = creator_tx.block_id
315326
LEFT JOIN voting_anchor ON voting_anchor.id = gov_action_proposal.voting_anchor_id
316327
LEFT JOIN off_chain_vote_data ON off_chain_vote_data.voting_anchor_id = voting_anchor.id
328+
lEFT JOIN off_chain_vote_author ON off_chain_vote_author.off_chain_vote_data_id = off_chain_vote_data.id
317329
LEFT JOIN off_chain_vote_gov_action_data ON off_chain_vote_gov_action_data.off_chain_vote_data_id = off_chain_vote_data.id
318330
LEFT JOIN param_proposal AS proposal_params ON gov_action_proposal.param_proposal = proposal_params.id
319331
LEFT JOIN cost_model AS cost_model ON proposal_params.cost_model_id = cost_model.id

govtool/backend/src/VVA/API.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ proposalToResponse timeZone Types.Proposal {..} =
244244
proposalResponseCcNoVotes = proposalCcNoVotes,
245245
proposalResponseCcAbstainVotes = proposalCcAbstainVotes,
246246
proposalResponsePrevGovActionIndex = proposalPrevGovActionIndex,
247-
proposalResponsePrevGovActionTxHash = HexText <$> proposalPrevGovActionTxHash
247+
proposalResponsePrevGovActionTxHash = HexText <$> proposalPrevGovActionTxHash,
248+
proposalResponseAuthors = ProposalAuthors <$> proposalAuthors
248249
}
249250

250251
voteToResponse :: Types.Vote -> VoteParams

govtool/backend/src/VVA/API/Types.hs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,39 @@ data ProposalResponse
401401
, proposalResponseCcAbstainVotes :: Integer
402402
, proposalResponsePrevGovActionIndex :: Maybe Integer
403403
, proposalResponsePrevGovActionTxHash :: Maybe HexText
404+
, proposalResponseAuthors :: Maybe ProposalAuthors
404405
}
405406
deriving (Generic, Show)
406407

408+
newtype ProposalAuthors = ProposalAuthors { getProposalAuthors :: Value }
409+
deriving newtype (Show)
410+
411+
instance FromJSON ProposalAuthors where
412+
parseJSON v@(Array _) = pure $ ProposalAuthors v
413+
parseJSON _ = fail "ProposalAuthors must be a JSON array"
414+
415+
instance ToJSON ProposalAuthors where
416+
toJSON (ProposalAuthors v) = v
417+
418+
instance ToSchema ProposalAuthors where
419+
declareNamedSchema _ = pure $ NamedSchema (Just "ProposalAuthors") $ mempty
420+
& type_ ?~ OpenApiArray
421+
& description ?~ "A JSON array of proposal authors"
422+
& example ?~ toJSON
423+
[ object
424+
[ "name" .= ("Alice" :: Text)
425+
, "witness_algorithm" .= ("algo" :: Text)
426+
, "public_key" .= ("key" :: Text)
427+
, "signature" .= ("sig" :: Text)
428+
]
429+
, object
430+
[ "name" .= ("Bob" :: Text)
431+
, "witness_algorithm" .= ("algo2" :: Text)
432+
, "public_key" .= ("key2" :: Text)
433+
, "signature" .= ("sig2" :: Text)
434+
]
435+
]
436+
407437
deriveJSON (jsonOptions "proposalResponse") ''ProposalResponse
408438

409439
exampleProposalResponse :: Text

govtool/backend/src/VVA/Types.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ data Proposal
208208
, proposalCcAbstainVotes :: Integer
209209
, proposalPrevGovActionIndex :: Maybe Integer
210210
, proposalPrevGovActionTxHash :: Maybe Text
211+
, proposalAuthors :: Maybe Value
211212
}
212213
deriving (Show)
213214

@@ -241,6 +242,7 @@ instance FromRow Proposal where
241242
<*> (floor @Scientific <$> field) -- proposalCcAbstainVotes
242243
<*> field -- prevGovActionIndex
243244
<*> field -- prevGovActionTxHash
245+
<*> field -- proposalAuthors
244246

245247
data TransactionStatus = TransactionStatus
246248
{ transactionConfirmed :: Bool

govtool/frontend/src/components/molecules/GovernanceActionCardElement.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useModal } from "@/context";
1515

1616
type BaseProps = {
1717
label: string;
18-
text?: string | number;
18+
text?: React.ReactNode;
1919
dataTestId?: string;
2020
isSliderCard?: boolean;
2121
tooltipProps?: Omit<TooltipProps, "children">;
@@ -108,7 +108,7 @@ export const GovernanceActionCardElement = ({
108108
...(isSemiTransparent && { opacity: 0.75 }),
109109
}}
110110
>
111-
{isMarkdown ? removeMarkdown(text) : text}
111+
{typeof text === "string" && isMarkdown ? removeMarkdown(text) : text}
112112
</Typography>
113113
);
114114

govtool/frontend/src/components/organisms/GovernanceActionDetailsCardData.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { useMemo, useState } from "react";
1+
import { useMemo, useState, Fragment } from "react";
22
import { Box, Tabs, Tab, styled, Skeleton } from "@mui/material";
33
import { useLocation } from "react-router-dom";
44

5-
import { CopyButton, ExternalModalButton, Typography } from "@atoms";
5+
import { CopyButton, ExternalModalButton, Tooltip, Typography } from "@atoms";
66
import {
77
GovernanceActionCardElement,
88
GovernanceActionDetailsCardLinks,
@@ -76,6 +76,7 @@ export const GovernanceActionDetailsCardData = ({
7676
isValidating,
7777
proposal: {
7878
abstract,
79+
authors,
7980
createdDate,
8081
createdEpochNo,
8182
details,
@@ -365,6 +366,35 @@ export const GovernanceActionDetailsCardData = ({
365366
/>
366367
</>
367368
)}
369+
<GovernanceActionCardElement
370+
label={t("govActions.authors.title")}
371+
text={
372+
(authors ?? []).length <= 0
373+
? t("govActions.authors.noDataAvailable")
374+
: (authors ?? []).map((author, idx, arr) => (
375+
<Fragment key={author.publicKey}>
376+
<Tooltip
377+
heading={`${t("govActions.authors.witnessAlgorithm")}: ${
378+
author.witnessAlgorithm
379+
}`}
380+
paragraphOne={`${t("govActions.authors.publicKey")}: ${
381+
author.publicKey
382+
}`}
383+
paragraphTwo={`${t("govActions.authors.signature")}: ${
384+
author.signature
385+
}`}
386+
placement="bottom-end"
387+
arrow
388+
>
389+
<span>{author.name}</span>
390+
</Tooltip>
391+
{idx < arr.length - 1 && <span>,&nbsp;</span>}
392+
</Fragment>
393+
))
394+
}
395+
textVariant="longText"
396+
dataTestId="authors"
397+
/>
368398

369399
<GovernanceActionDetailsCardLinks links={references} />
370400
</Box>

govtool/frontend/src/i18n/locales/en.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,13 @@
421421
"amount": "Amount:",
422422
"anchorURL": "Metadata anchor link",
423423
"anchorHash": "Metadata anchor hash",
424+
"authors": {
425+
"noDataAvailable": "No data available",
426+
"title": "Authors",
427+
"publicKey": "Public Key",
428+
"signature": "Signature",
429+
"witnessAlgorithm": "Witness Algorithm"
430+
},
424431
"backToGovActions": "Back to Governance Actions",
425432
"castVote": "<0>You voted {{vote}} on this proposal</0>\non {{date}} (Epoch {{epoch}})",
426433
"castVoteDeadline": "You can change your vote up to {{date}} (Epoch {{epoch}})",

govtool/frontend/src/models/api.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ export type ProposalData = {
234234
references?: Reference[];
235235
title?: string;
236236
protocolParams: EpochParams | null;
237+
authors?: {
238+
name?: string;
239+
witnessAlgorithm?: string;
240+
publicKey?: string;
241+
signature?: string;
242+
}[];
237243
} & SubmittedVotesData;
238244

239245
export type NewConstitutionAnchor = {
@@ -270,8 +276,8 @@ type DRepVotingPower = {
270276
export type DRepVotingPowerListResponse = DRepVotingPower[];
271277

272278
export type Account = {
273-
id: number,
274-
view: string,
275-
isRegistered: boolean,
276-
isScriptBased: boolean
277-
}
279+
id: number;
280+
view: string;
281+
isRegistered: boolean;
282+
isScriptBased: boolean;
283+
};

govtool/frontend/src/stories/GovernanceActionDetailsCard.stories.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ const commonArgs = {
6464
label: "Example label",
6565
},
6666
],
67+
authors: [
68+
{
69+
name: "Alice Cardana",
70+
witnessAlgorithm: "Ed25519",
71+
publicKey: "ed25519_pk1qwertyuiopasdfghjklzxcvbnm1234567890abcdef",
72+
signature: "ed25519_sig1abcdef1234567890qwertyuiopasdfghjklzxcvbnm",
73+
},
74+
{
75+
name: "Bob Stakepool",
76+
witnessAlgorithm: "Ed25519",
77+
publicKey: "ed25519_pk1asdfghjklqwertyuiopzxcvbnm0987654321abcdf",
78+
signature: "ed25519_sig1zxcvbnm0987654321asdfghjklqwertyuiop",
79+
},
80+
],
6781
} satisfies ProposalData,
6882
};
6983

0 commit comments

Comments
 (0)