Skip to content

Commit b46c6e2

Browse files
committed
feat(#2745): add script hash to new constitution governance action
1 parent c4eb77b commit b46c6e2

File tree

7 files changed

+56
-32
lines changed

7 files changed

+56
-32
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
- Add exception handler on stake key voting power query execution [Issue 2757](https://github.com/IntersectMBO/govtool/issues/2757)
16+
- Add script hash to new consitution governance action [Issue 2745](https://github.com/IntersectMBO/govtool/issues/2745)
1617

1718
### Fixed
1819

govtool/backend/sql/list-proposals.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ SELECT
175175

176176
WHEN gov_action_proposal.type::text = 'NewConstitution' THEN
177177
json_build_object(
178-
'anchor', gov_action_proposal.description->'contents'->1->'anchor'
178+
'anchor', gov_action_proposal.description->'contents'->1->'anchor',
179+
'script', gov_action_proposal.description->'contents'->1->'script'
179180
)
180181
WHEN gov_action_proposal.type::text = 'NewCommittee' THEN
181182
(

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type DataMissingHeaderProps = {
1616
titleStyle?: SxProps;
1717
isDRep?: boolean;
1818
image?: string | null;
19+
shareLink?: string;
1920
};
2021

2122
export const DataMissingHeader = ({
@@ -24,6 +25,7 @@ export const DataMissingHeader = ({
2425
titleStyle,
2526
isDRep,
2627
image,
28+
shareLink,
2729
}: DataMissingHeaderProps) => {
2830
const base64Image = getBase64ImageDetails(image ?? "");
2931
const { screenWidth } = useScreenDimension();
@@ -81,7 +83,9 @@ export const DataMissingHeader = ({
8183
title}
8284
</Typography>
8385
</Box>
84-
{screenWidth >= 1020 && <Share link={window.location.href} />}
86+
{screenWidth >= 1020 && (
87+
<Share link={shareLink || window.location.href} />
88+
)}
8589
</Box>
8690
);
8791
};
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
import { Box } from "@mui/material";
22

33
import { NewConstitutionAnchor, ProposalData } from "@/models";
4-
import { useScreenDimension } from "@/hooks";
4+
import { useScreenDimension, useTranslation } from "@/hooks";
55

66
import { GovernanceActionCardElement } from "./GovernanceActionCardElement";
77

88
export const GovernanceActionNewConstitutionDetailsTabContent = ({
99
details,
1010
}: Pick<ProposalData, "details">) => {
1111
const { screenWidth } = useScreenDimension();
12+
const { t } = useTranslation();
1213
return (
1314
<Box>
1415
<GovernanceActionCardElement
1516
isLinkButton
16-
label="New constitution link"
17+
label={t("govActions.newConstitution.url")}
1718
text={(details?.anchor as NewConstitutionAnchor)?.url as string}
1819
dataTestId="new-constitution-url"
1920
textVariant={screenWidth > 1600 ? "longText" : "oneLine"}
2021
/>
2122
<GovernanceActionCardElement
2223
isCopyButton
23-
label="New constitution hash"
24+
label={t("govActions.newConstitution.hash")}
2425
text={(details?.anchor as NewConstitutionAnchor)?.dataHash as string}
2526
dataTestId="new-constitution-data-hash"
2627
textVariant={screenWidth > 1600 ? "longText" : "oneLine"}
2728
/>
29+
<GovernanceActionCardElement
30+
isCopyButton
31+
label={t("govActions.newConstitution.scriptHash")}
32+
text={details?.script as string}
33+
dataTestId="new-constitution-script-hash"
34+
textVariant={screenWidth > 1600 ? "longText" : "oneLine"}
35+
/>
2836
</Box>
2937
);
3038
};

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import { useScreenDimension } from "@hooks";
55
import {
66
GovernanceActionCardStatePill,
77
GovernanceActionDetailsCardVotes,
8-
Share,
98
} from "@molecules";
109
import { GovernanceActionDetailsCardData } from "@organisms";
1110
import { MetadataValidationStatus, ProposalData, ProposalVote } from "@models";
12-
import { useLocation } from "react-router-dom";
1311

1412
type GovernanceActionDetailsCardProps = {
1513
isDashboard?: boolean;
@@ -32,13 +30,6 @@ export const GovernanceActionDetailsCard = ({
3230
const { screenWidth, isMobile } = useScreenDimension();
3331

3432
const isOneColumn = (isDashboard && screenWidth < 1036) ?? isMobile;
35-
const { pathname, hash } = useLocation();
36-
37-
const govActionLinkToShare = `${window.location.protocol}//${
38-
window.location.hostname
39-
}${window.location.port ? `:${window.location.port}` : ""}${pathname}${
40-
hash ?? ""
41-
}`;
4233

4334
return (
4435
<Box
@@ -82,9 +73,6 @@ export const GovernanceActionDetailsCard = ({
8273
isInProgress={isInProgress}
8374
proposal={proposal}
8475
/>
85-
<Box position="absolute" right={40} top={40}>
86-
<Share link={govActionLinkToShare} />
87-
</Box>
8876
</Box>
8977
);
9078
};

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useMemo, useState } from "react";
22
import { Box, Tabs, Tab, styled } from "@mui/material";
3+
import { useLocation } from "react-router-dom";
34

45
import { CopyButton, ExternalModalButton, Typography } from "@atoms";
56
import {
@@ -95,6 +96,7 @@ export const GovernanceActionDetailsCardData = ({
9596
const { t } = useTranslation();
9697
const { screenWidth } = useScreenDimension();
9798
const { isMobile } = useScreenDimension();
99+
const { pathname, hash } = useLocation();
98100

99101
const mappedArraysToObjectsProtocolParams = useMemo(
100102
() =>
@@ -147,6 +149,12 @@ export const GovernanceActionDetailsCardData = ({
147149
? getFullGovActionId(prevGovActionTxHash, prevGovActionIndex)
148150
: null;
149151

152+
const govActionLinkToShare = `${window.location.protocol}//${
153+
window.location.hostname
154+
}${window.location.port ? `:${window.location.port}` : ""}${pathname}${
155+
hash ?? ""
156+
}`;
157+
150158
const tabs = useMemo(
151159
() =>
152160
[
@@ -232,7 +240,11 @@ export const GovernanceActionDetailsCardData = ({
232240
overflow: "hidden",
233241
}}
234242
>
235-
<DataMissingHeader isDataMissing={isDataMissing} title={title} />
243+
<DataMissingHeader
244+
isDataMissing={isDataMissing}
245+
title={title}
246+
shareLink={govActionLinkToShare}
247+
/>
236248
<DataMissingInfoBox
237249
isDataMissing={isDataMissing}
238250
isInProgress={isInProgress}
@@ -319,20 +331,25 @@ export const GovernanceActionDetailsCardData = ({
319331
amount={withdrawal.amount}
320332
/>
321333
))}
322-
<GovernanceActionCardElement
323-
label={t("govActions.anchorURL")}
324-
text={url}
325-
textVariant="longText"
326-
dataTestId="anchor-url"
327-
isLinkButton
328-
/>
329-
<GovernanceActionCardElement
330-
label={t("govActions.anchorHash")}
331-
text={metadataHash}
332-
textVariant="longText"
333-
dataTestId="anchor-hash"
334-
isCopyButton
335-
/>
334+
{/* NewConstitution metadata hash and url is visible in details tab */}
335+
{type !== GovernanceActionType.NewConstitution && (
336+
<>
337+
<GovernanceActionCardElement
338+
label={t("govActions.anchorURL")}
339+
text={url}
340+
textVariant="longText"
341+
dataTestId="anchor-url"
342+
isLinkButton
343+
/>
344+
<GovernanceActionCardElement
345+
label={t("govActions.anchorHash")}
346+
text={metadataHash}
347+
textVariant="longText"
348+
dataTestId="anchor-hash"
349+
isCopyButton
350+
/>
351+
</>
352+
)}
336353

337354
<GovernanceActionDetailsCardLinks links={references} />
338355
</Box>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@
382382
"proposedVersion": "Proposed version",
383383
"previousGAId": "Previous Governance Action ID"
384384
},
385+
"newConstitution": {
386+
"url": "New constitution link",
387+
"hash": "New constitution hash",
388+
"scriptHash": "New constitution script hash"
389+
},
385390
"motivation": "Motivation",
386391
"myVote": "My Vote:",
387392
"noResultsForTheSearch": "No results for the search.",

0 commit comments

Comments
 (0)