Skip to content

Commit 5973c3b

Browse files
committed
(fix#3954): Incorrect Display of New Committee Parameters in Governance Action Details
1 parent cf55ecc commit 5973c3b

File tree

4 files changed

+97
-43
lines changed

4 files changed

+97
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ changes.
1515
### Fixed
1616

1717
- Fix disappearing proposals in the governance actions list for the same tx hashes [Issue 3918](https://github.com/IntersectMBO/govtool/issues/3918)
18+
- Fix incorrect display of new committee parameters in Governance Action details [Issue 3954](https://github.com/IntersectMBO/govtool/issues/3954)
1819

1920
### Changed
2021

govtool/backend/sql/list-proposals.sql

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ CommitteeData AS (
4242
FROM
4343
committee_member cm
4444
JOIN committee_hash ch ON cm.committee_hash_id = ch.id
45+
WHERE EXISTS (
46+
SELECT 1
47+
FROM committee_registration cr
48+
WHERE cr.cold_key_id = ch.id
49+
)
50+
AND NOT EXISTS (
51+
SELECT 1
52+
FROM committee_de_registration cdr
53+
WHERE cdr.cold_key_id = ch.id
54+
AND cdr.tx_id > (
55+
SELECT MAX(cr2.tx_id)
56+
FROM committee_registration cr2
57+
WHERE cr2.cold_key_id = ch.id
58+
)
59+
)
4560
ORDER BY
4661
ch.raw, cm.expiration_epoch DESC
4762
),
@@ -61,10 +76,31 @@ ParsedDescription AS (
6176
MembersToBeRemoved AS (
6277
SELECT
6378
id,
64-
json_agg(VALUE->>'keyHash') AS members_to_be_removed
79+
json_agg(
80+
json_build_object(
81+
'hash', COALESCE(
82+
VALUE->>'keyHash',
83+
VALUE->>'scriptHash'
84+
),
85+
'type', CASE
86+
WHEN VALUE->>'keyHash' IS NOT NULL THEN 'keyHash'
87+
WHEN VALUE->>'scriptHash' IS NOT NULL THEN 'scriptHash'
88+
ELSE 'unknown'
89+
END,
90+
'hasScript', CASE
91+
WHEN VALUE->>'scriptHash' IS NOT NULL THEN true
92+
ELSE false
93+
END
94+
)
95+
) AS members_to_be_removed
6596
FROM
6697
ParsedDescription pd,
67-
json_array_elements(members_to_be_removed::json) AS value
98+
json_array_elements(
99+
CASE
100+
WHEN pd.members_to_be_removed IS NULL THEN '[]'::json
101+
ELSE pd.members_to_be_removed::json
102+
END
103+
) AS value
68104
GROUP BY
69105
id
70106
),
@@ -73,7 +109,15 @@ ProcessedCurrentMembers AS (
73109
pd.id,
74110
json_agg(
75111
json_build_object(
76-
'hash', regexp_replace(kv.key, '^keyHash-', ''),
112+
'hash', COALESCE(
113+
regexp_replace(kv.key, '^keyHash-', ''),
114+
regexp_replace(kv.key, '^scriptHash-', '')
115+
),
116+
'type', CASE
117+
WHEN kv.key LIKE 'keyHash-%' THEN 'keyHash'
118+
WHEN kv.key LIKE 'scriptHash-%' THEN 'scriptHash'
119+
ELSE 'unknown'
120+
END,
77121
'newExpirationEpoch', kv.value::int
78122
)
79123
) AS current_members
@@ -88,9 +132,17 @@ EnrichedCurrentMembers AS (
88132
pcm.id,
89133
json_agg(
90134
json_build_object(
91-
'hash', cm.hash,
135+
'hash', CASE
136+
WHEN (member->>'hash') LIKE 'scriptHash-%' THEN
137+
regexp_replace(member->>'hash', '^scriptHash-', '')
138+
WHEN (member->>'hash') LIKE 'keyHash-%' THEN
139+
regexp_replace(member->>'hash', '^keyHash-', '')
140+
ELSE
141+
member->>'hash'
142+
END,
143+
'type', member->>'type',
92144
'expirationEpoch', cm.expiration_epoch,
93-
'hasScript', cm.has_script,
145+
'hasScript', COALESCE(cm.has_script, member->>'type' = 'scriptHash'),
94146
'newExpirationEpoch', (member->>'newExpirationEpoch')::int
95147
)
96148
) AS enriched_members
@@ -247,9 +299,9 @@ SELECT
247299
)
248300
FROM
249301
ParsedDescription pd
250-
JOIN
302+
LEFT JOIN
251303
MembersToBeRemoved mtr ON pd.id = mtr.id
252-
JOIN
304+
LEFT JOIN
253305
EnrichedCurrentMembers em ON pd.id = em.id
254306
WHERE
255307
pd.id = gov_action_proposal.id

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

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,51 @@ type CCMember = {
1212
hash: string;
1313
newExpirationEpoch?: number;
1414
};
15+
type CCMemberToBeRemoved = {
16+
hash: string;
17+
hasScript?: boolean;
18+
};
1519

16-
function isArrayOfStrings(value: unknown): value is string[] {
17-
return (
18-
Array.isArray(value) && value.every((item) => typeof item === "string")
19-
);
20-
}
20+
const getCip129Identifier = (hash: string, hasScript?: boolean) =>
21+
encodeCIP129Identifier({
22+
txID: (hasScript ? "13" : "12") + hash,
23+
bech32Prefix: "cc_cold",
24+
});
2125

2226
export const GovernanceActionNewCommitteeDetailsTabContent = ({
2327
details,
2428
}: Pick<ProposalData, "details">) => {
2529
const { t } = useTranslation();
2630
const membersToBeAdded = ((details?.members as CCMember[]) || [])
27-
.filter((member) => member.newExpirationEpoch === undefined)
31+
.filter(
32+
(member) =>
33+
member?.expirationEpoch === undefined ||
34+
member?.expirationEpoch === null,
35+
)
36+
.filter((member) => member?.hash)
2837
.map((member) => ({
29-
cip129Identifier: encodeCIP129Identifier({
30-
txID: (member.hasScript ? "02" : "13") + member.hash,
31-
bech32Prefix: member.hasScript ? "cc_hot" : "cc_cold",
32-
}),
38+
cip129Identifier: getCip129Identifier(member.hash, member.hasScript),
3339
expirationEpoch: member.expirationEpoch,
3440
}));
3541

3642
const membersToBeUpdated = ((details?.members as CCMember[]) || [])
37-
.filter((member) => member.newExpirationEpoch !== undefined)
43+
.filter(
44+
(member) => !!member?.expirationEpoch && !!member?.newExpirationEpoch,
45+
)
46+
.filter((member) => member?.hash)
3847
.map((member) => ({
39-
cip129Identifier: encodeCIP129Identifier({
40-
txID: (member.hasScript ? "02" : "13") + member.hash,
41-
bech32Prefix: member.hasScript ? "cc_hot" : "cc_cold",
42-
}),
48+
cip129Identifier: getCip129Identifier(member.hash, member.hasScript),
4349
expirationEpoch: member.expirationEpoch,
4450
newExpirationEpoch: member.newExpirationEpoch,
4551
}));
4652

47-
const membersToBeRemoved = isArrayOfStrings(details?.membersToBeRemoved)
48-
? details.membersToBeRemoved
49-
: [];
53+
const membersToBeRemoved = (
54+
(details?.membersToBeRemoved as CCMemberToBeRemoved[]) || []
55+
)
56+
.filter((member) => member?.hash && member.hash.trim() !== "")
57+
.map((member) => ({
58+
cip129Identifier: getCip129Identifier(member.hash, member.hasScript),
59+
}));
5060

5161
return (
5262
<Box>
@@ -63,7 +73,7 @@ export const GovernanceActionNewCommitteeDetailsTabContent = ({
6373
whiteSpace: "nowrap",
6474
}}
6575
>
66-
{t("govActions.membersToBeAdded")}
76+
{t("govActions.membersToBeAddedToTheCommittee")}
6777
</Typography>
6878
{membersToBeAdded.map(({ cip129Identifier }) => (
6979
<Box display="flex" flexDirection="row">
@@ -101,10 +111,10 @@ export const GovernanceActionNewCommitteeDetailsTabContent = ({
101111
whiteSpace: "nowrap",
102112
}}
103113
>
104-
{t("govActions.membersToBeRemoved")}
114+
{t("govActions.membersToBeRemovedFromTheCommittee")}
105115
</Typography>
106-
{membersToBeRemoved.map((hash) => (
107-
<Box display="flex" flexDirection="row" key={hash}>
116+
{membersToBeRemoved.map(({ cip129Identifier }) => (
117+
<Box display="flex" flexDirection="row" key={cip129Identifier}>
108118
<Typography
109119
sx={{
110120
fontSize: 16,
@@ -114,19 +124,10 @@ export const GovernanceActionNewCommitteeDetailsTabContent = ({
114124
color: "primaryBlue",
115125
}}
116126
>
117-
{encodeCIP129Identifier({
118-
txID: hash,
119-
bech32Prefix: "cc_cold",
120-
})}
127+
{cip129Identifier}
121128
</Typography>
122129
<Box ml={1}>
123-
<CopyButton
124-
text={encodeCIP129Identifier({
125-
txID: hash,
126-
bech32Prefix: "cc_cold",
127-
})}
128-
variant="blueThin"
129-
/>
130+
<CopyButton text={cip129Identifier} variant="blueThin" />
130131
</Box>
131132
</Box>
132133
))}
@@ -179,8 +180,8 @@ export const GovernanceActionNewCommitteeDetailsTabContent = ({
179180
}}
180181
>
181182
{t("govActions.changeToTermsEpochs", {
182-
epochTo: newExpirationEpoch,
183-
epochFrom: expirationEpoch,
183+
epochTo: newExpirationEpoch ?? "N/A",
184+
epochFrom: expirationEpoch ?? "N/A",
184185
})}
185186
</Typography>
186187
</>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@
479479
"membersToBeRemovedFromTheCommittee": "Members to be removed from the Committee",
480480
"membersToBeAddedToTheCommittee": "Members to be added to the Committee",
481481
"changeToTermsOfExistingMembers": "Change to terms of existing members",
482-
"changeToTermsEpochs": "To {{epochTo}} epoch {{epochFrom}} epoch",
482+
"changeToTermsEpochs": "To {{epochTo}} epoch, from {{epochFrom}} epoch",
483483
"newThresholdValue": "New threshold value",
484484
"protocolParamsDetails": {
485485
"existing": "Existing",

0 commit comments

Comments
 (0)