Skip to content

Commit 7eda954

Browse files
committed
feat(#1600): add support for list of withdrawals in treasury gov action
1 parent ac6ba3d commit 7eda954

File tree

11 files changed

+162
-30
lines changed

11 files changed

+162
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ changes.
1717
- Add support for displaying Update committee/threshold Governance Action [Issue 1598](https://github.com/IntersectMBO/govtool/issues/1598)
1818
- Add support for displaying New Constitution and/or Guardrails Script Governance Action [Issue 1599](https://github.com/IntersectMBO/govtool/issues/1598)
1919
- Add support for ipfs in metadata validation service [Issue 1616](https://github.com/IntersectMBO/govtool/issues/1616)
20+
- Add support for displaying array of treasury withdrawals [Issue 1602](https://github.com/IntersectMBO/govtool/issues/1602)
2021

2122
### Fixed
2223

docs/GOVERNANCE_ACTION_SUBMISSION.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ interface InfoProps {
4141
interface TreasuryProps {
4242
amount: string;
4343
hash: string;
44-
receivingAddress: string;
45-
url: string;
44+
withdrawals: { receivingAddress: string; amount: string }[];
4645
}
4746

4847
type ProtocolParamsUpdate = {
@@ -184,8 +183,7 @@ const { buildTreasuryGovernanceAction } = useCardano();
184183
const govActionBuilder = await buildTreasuryGovernanceAction({
185184
hash,
186185
url,
187-
amount,
188-
receivingAddress,
186+
withdrawals: [{ amount, receivingAddress }],
189187
});
190188

191189
// Protocol Parameter Change Governance Action

govtool/backend/sql/list-proposals.sql

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,18 @@ SELECT
107107
gov_action_proposal.type::text,
108108
(
109109
case when gov_action_proposal.type = 'TreasuryWithdrawals' then
110-
json_build_object('Reward Address', stake_address.view, 'Amount', treasury_withdrawal.amount)
111-
110+
(
111+
select json_agg(
112+
jsonb_build_object(
113+
'receivingAddress', stake_address.view,
114+
'amount', treasury_withdrawal.amount
115+
)
116+
)
117+
from treasury_withdrawal
118+
left join stake_address
119+
on stake_address.id = treasury_withdrawal.stake_address_id
120+
where treasury_withdrawal.gov_action_proposal_id = gov_action_proposal.id
121+
)
112122
when gov_action_proposal.type::text = 'InfoAction' then
113123
json_build_object('data', gov_action_proposal.description)
114124

@@ -261,8 +271,6 @@ AND gov_action_proposal.expired_epoch IS NULL
261271
AND gov_action_proposal.dropped_epoch IS NULL
262272
GROUP BY
263273
(gov_action_proposal.id,
264-
stake_address.view,
265-
treasury_withdrawal.amount,
266274
creator_block.epoch_no,
267275
off_chain_vote_gov_action_data.title,
268276
off_chain_vote_gov_action_data.abstract,
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { Box } from "@mui/material";
2+
import { useTranslation } from "react-i18next";
3+
4+
import { Typography, CopyButton } from "@atoms";
5+
import { correctAdaFormat } from "@utils";
6+
7+
import { useScreenDimension } from "@/hooks";
8+
9+
type Props = {
10+
receivingAddress: string;
11+
amount: number;
12+
};
13+
14+
export const GovernanceActionCardTreasuryWithdrawalElement = ({
15+
receivingAddress,
16+
amount,
17+
}: Props) => {
18+
const { t } = useTranslation();
19+
const { isMobile } = useScreenDimension();
20+
return (
21+
<Box
22+
sx={{
23+
display: "flex",
24+
mb: "4px",
25+
flexDirection: "column",
26+
}}
27+
>
28+
<Box sx={{ display: "flex", flexDirection: isMobile ? "column" : "row" }}>
29+
<Typography
30+
data-testid="receiving-address-label"
31+
sx={{
32+
width: "160px",
33+
fontSize: 14,
34+
fontWeight: 600,
35+
lineHeight: "20px",
36+
color: "neutralGray",
37+
}}
38+
>
39+
{t("govActions.receivingAddress")}
40+
</Typography>
41+
<Box
42+
sx={{
43+
display: "flex",
44+
alignItems: "center",
45+
overflow: "hidden",
46+
flexDirection: "row",
47+
}}
48+
>
49+
<Typography
50+
data-testid="receiving-address"
51+
sx={{
52+
ml: isMobile ? 0 : 8,
53+
color: "primaryBlue",
54+
fontSize: 16,
55+
fontWeight: 400,
56+
lineHeight: "20px",
57+
whiteSpace: "nowrap",
58+
overflow: "hidden",
59+
textOverflow: "ellipsis",
60+
}}
61+
>
62+
{receivingAddress}
63+
</Typography>
64+
<Box ml={1}>
65+
<CopyButton text={receivingAddress} variant="blueThin" />
66+
</Box>
67+
</Box>
68+
</Box>
69+
<Box
70+
sx={{
71+
display: "flex",
72+
flexDirection: isMobile ? "column" : "row",
73+
mt: "6px",
74+
}}
75+
>
76+
<Typography
77+
sx={{
78+
width: "160px",
79+
fontSize: 14,
80+
fontWeight: 600,
81+
lineHeight: "20px",
82+
color: "neutralGray",
83+
}}
84+
data-testid="amount-label"
85+
>
86+
{t("govActions.amount")}
87+
</Typography>
88+
<Typography
89+
data-testid="amount"
90+
sx={{
91+
ml: isMobile ? 0 : 8,
92+
fontSize: 16,
93+
fontWeight: 400,
94+
lineHeight: "20px",
95+
}}
96+
>
97+
{correctAdaFormat(amount) ?? 0}
98+
</Typography>
99+
</Box>
100+
</Box>
101+
);
102+
};

govtool/frontend/src/components/molecules/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export * from "./GovernanceActionCardElement";
2323
export * from "./GovernanceActionCardHeader";
2424
export * from "./GovernanceActionCardMyVote";
2525
export * from "./GovernanceActionCardStatePill";
26+
export * from "./GovernanceActionCardTreasuryWithdrawalElement";
2627
export * from "./GovernanceActionDetailsCardLinks";
2728
export * from "./GovernanceActionDetailsCardOnChainData";
2829
export * from "./GovernanceActionDetailsCardVotes";

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
GovernanceActionsDatesBox,
1111
GovernanceActionDetailsDiffView,
1212
GovernanceActionNewCommitteeDetailsTabContent,
13+
GovernanceActionCardTreasuryWithdrawalElement,
1314
} from "@molecules";
1415
import { useScreenDimension, useTranslation } from "@hooks";
1516
import {
@@ -20,7 +21,6 @@ import {
2021
getFullGovActionId,
2122
mapArrayToObjectByKeys,
2223
encodeCIP129Identifier,
23-
testIdFromLabel,
2424
} from "@utils";
2525
import {
2626
MetadataValidationStatus,
@@ -297,16 +297,14 @@ export const GovernanceActionDetailsCardData = ({
297297
))}
298298
</>
299299
)}
300-
301300
{details &&
302301
type === GovernanceActionType.TreasuryWithdrawals &&
303-
Object.keys(details).length !== 0 &&
304-
Object.entries(details).map(([detailLabel, content]) => (
305-
<GovernanceActionCardElement
306-
isCopyButton={detailLabel.toLowerCase().includes("address")}
307-
label={detailLabel}
308-
text={content as string}
309-
dataTestId={testIdFromLabel(detailLabel)}
302+
Array.isArray(details) &&
303+
details.map((withdrawal) => (
304+
<GovernanceActionCardTreasuryWithdrawalElement
305+
key={withdrawal.receivingAddress}
306+
receivingAddress={withdrawal.receivingAddress}
307+
amount={withdrawal.amount}
310308
/>
311309
))}
312310
{details?.anchor && type === GovernanceActionType.NewConstitution && (

govtool/frontend/src/context/wallet.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,9 @@ type InfoProps = {
115115
};
116116

117117
type TreasuryProps = {
118-
amount: string;
119118
hash: string;
120-
receivingAddress: string;
121119
url: string;
120+
withdrawals: { receivingAddress: string; amount: string }[];
122121
};
123122

124123
type ProtocolParamsUpdate = {
@@ -1011,23 +1010,40 @@ const CardanoProvider = (props: Props) => {
10111010

10121011
// treasury action
10131012
const buildTreasuryGovernanceAction = useCallback(
1014-
async ({ amount, hash, receivingAddress, url }: TreasuryProps) => {
1013+
async ({ hash, url, withdrawals }: TreasuryProps) => {
10151014
const govActionBuilder = VotingProposalBuilder.new();
10161015
try {
1017-
const treasuryTarget = RewardAddress.from_address(
1018-
Address.from_bech32(receivingAddress),
1019-
);
1016+
const mappedWithdrawals: {
1017+
treasuryTarget: RewardAddress;
1018+
amount: BigNum;
1019+
}[] = [];
1020+
1021+
withdrawals.forEach((withdrawal) => {
1022+
const treasuryTarget = RewardAddress.from_address(
1023+
Address.from_bech32(withdrawal.receivingAddress),
1024+
);
10201025

1021-
if (!treasuryTarget) throw new Error("Can not get tresasury target");
1026+
if (!treasuryTarget)
1027+
throw new Error(
1028+
`Can not get tresasury target for address: ${withdrawal.receivingAddress}`,
1029+
);
10221030

1023-
const myWithdrawal = BigNum.from_str(amount);
1024-
const withdrawals = TreasuryWithdrawals.new();
1025-
withdrawals.insert(treasuryTarget, myWithdrawal);
1031+
const amount = BigNum.from_str(withdrawal.amount);
1032+
mappedWithdrawals.push({ treasuryTarget, amount });
1033+
});
1034+
1035+
const treasuryWithdrawals = TreasuryWithdrawals.new();
1036+
mappedWithdrawals.forEach((withdrawal) => {
1037+
treasuryWithdrawals.insert(
1038+
withdrawal.treasuryTarget,
1039+
withdrawal.amount,
1040+
);
1041+
});
10261042
const guardrailPlutusScript = PlutusScript.from_bytes_v3(
10271043
Buffer.from(guardrailScript, "hex"),
10281044
);
10291045
const treasuryAction = TreasuryWithdrawalsAction.new_with_policy_hash(
1030-
withdrawals,
1046+
treasuryWithdrawals,
10311047
guardrailPlutusScript.hash(),
10321048
);
10331049
isGuardrailScriptUsed.current = true;

govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,12 @@ export const useCreateGovernanceActionForm = (
145145

146146
const treasuryActionDetails = {
147147
...commonGovActionDetails,
148-
amount: data.amount,
149-
receivingAddress: data.receivingAddress,
148+
withdrawals: [
149+
{
150+
amount: data.amount,
151+
receivingAddress: data.receivingAddress,
152+
},
153+
],
150154
};
151155

152156
return await buildTreasuryGovernanceAction(treasuryActionDetails);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@
343343
"govActions": {
344344
"about": "About",
345345
"abstract": "Abstract",
346+
"amount": "Amount:",
346347
"backToGovActions": "Back to Governance Actions",
347348
"castVote": "<0>You voted {{vote}} on this proposal</0>\non {{date}} (Epoch {{epoch}})",
348349
"castVoteDeadline": "You can change your vote up to {{date}} (Epoch {{epoch}})",
@@ -373,6 +374,7 @@
373374
"existing": "Existing",
374375
"proposed": "Proposed"
375376
},
377+
"receivingAddress": "Receiving Address:",
376378
"hardforkDetails": {
377379
"currentVersion": "Current version",
378380
"proposedVersion": "Proposed version",

govtool/frontend/src/theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export const theme = createTheme({
137137
arcticWhite: "#FBFBFF",
138138
boxShadow1: "rgba(0, 18, 61, 0.37)",
139139
boxShadow2: "rgba(47, 98, 220, 0.2)",
140+
darkPurple: "rgba(36, 34, 50, 1)",
140141
errorRed: "#9E2323",
141142
fadedPurple: "#716E88",
142143
highlightBlue: "#C2EFF299",

0 commit comments

Comments
 (0)