Skip to content

Commit 835bd85

Browse files
committed
fix(#2571): add support for searching by cip-129 identifiers
1 parent 88908ec commit 835bd85

File tree

10 files changed

+145
-38
lines changed

10 files changed

+145
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ changes.
2626

2727
-
2828

29-
## [v2.0.2](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.2) 2024-12-20
29+
## [v2.0.2](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.2) 2024-12-23
3030

3131
### Added
3232

@@ -37,6 +37,7 @@ changes.
3737
- Move matomo initalization out of the react code
3838
- Fix some non-ipfs related errors while fetching the DRep images [Issue 2546](https://github.com/IntersectMBO/govtool/issues/2546)
3939
- Remaining mobile responsiveness issue [Issue 2493](https://github.com/IntersectMBO/govtool/issues/2493)
40+
- Fix searching by CIP-129 identifiers [Issue 2571](https://github.com/IntersectMBO/govtool/issues/2571)
4041

4142
### Changed
4243

govtool/backend/sql/list-dreps.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SELECT
2626
encode(va.data_hash, 'hex'),
2727
dr_deposit.deposit,
2828
DRepDistr.amount,
29-
(DRepActivity.epoch_no - Max(coalesce(block.epoch_no, block_first_register.epoch_no))) <= DRepActivity.drep_activity AS active,
29+
(DRepActivity.epoch_no - Max(coalesce(block.epoch_no, block_first_register.epoch_no))) <= DRepActivity.drep_activity AS active,
3030
encode(dr_voting_anchor.tx_hash, 'hex') AS tx_hash,
3131
newestRegister.time AS last_register_time,
3232
COALESCE(latestDeposit.deposit, 0),

govtool/frontend/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const GovernanceActionNewCommitteeDetailsTabContent = ({
2121
.filter((member) => member.newExpirationEpoch === undefined)
2222
.map((member) => ({
2323
cip129Identifier: encodeCIP129Identifier({
24-
txID: member.hash,
24+
txID: (member.hasScript ? "02" : "13") + member.hash,
2525
bech32Prefix: member.hasScript ? "cc_hot" : "cc_cold",
2626
}),
2727
expirationEpoch: member.expirationEpoch,
@@ -31,7 +31,7 @@ export const GovernanceActionNewCommitteeDetailsTabContent = ({
3131
.filter((member) => member.newExpirationEpoch !== undefined)
3232
.map((member) => ({
3333
cip129Identifier: encodeCIP129Identifier({
34-
txID: member.hash,
34+
txID: (member.hasScript ? "02" : "13") + member.hash,
3535
bech32Prefix: member.hasScript ? "cc_hot" : "cc_cold",
3636
}),
3737
expirationEpoch: member.expirationEpoch,

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

Lines changed: 82 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Card } from "@molecules";
1010
import {
1111
correctDRepDirectoryFormat,
1212
ellipsizeText,
13+
encodeCIP129Identifier,
1314
getMetadataDataMissingStatusTranslation,
1415
} from "@utils";
1516

@@ -24,7 +25,16 @@ type DRepCardProps = {
2425
};
2526

2627
export const DRepCard = ({
27-
dRep: { status, type, view, votingPower, givenName, metadataStatus, image },
28+
dRep: {
29+
status,
30+
type,
31+
view,
32+
votingPower,
33+
givenName,
34+
metadataStatus,
35+
image,
36+
drepId,
37+
},
2838
isConnected,
2939
isDelegationLoading,
3040
isInProgress,
@@ -48,6 +58,11 @@ export const DRepCard = ({
4858
},
4959
});
5060

61+
const cip129Identifier = encodeCIP129Identifier({
62+
txID: `22${drepId}`,
63+
bech32Prefix: "drep",
64+
});
65+
5166
return (
5267
<Card
5368
{...(isMe && {
@@ -122,35 +137,76 @@ export const DRepCard = ({
122137
? getMetadataDataMissingStatusTranslation(metadataStatus)
123138
: ellipsizeText(givenName ?? "", 25)}
124139
</Typography>
125-
<ButtonBase
126-
data-testid={`${view}-copy-id-button`}
127-
onClick={(e) => {
128-
navigator.clipboard.writeText(view);
129-
addSuccessAlert(t("alerts.copiedToClipboard"));
130-
e.stopPropagation();
131-
}}
140+
<Box
132141
sx={{
133-
gap: 1,
134-
width: "250px",
135-
maxWidth: {
136-
xxs: "200px",
137-
xs: "100%",
138-
},
139-
"&:hover": {
140-
opacity: 0.6,
141-
transition: "opacity 0.3s",
142-
},
142+
display: "flex",
143+
flexDirection: "column",
143144
}}
144145
>
145-
<Typography
146-
color="primary"
147-
variant="body2"
148-
sx={ellipsisStyles}
146+
<ButtonBase
147+
data-testid={`${view}-copy-id-button`}
148+
onClick={(e) => {
149+
navigator.clipboard.writeText(view);
150+
addSuccessAlert(t("alerts.copiedToClipboard"));
151+
e.stopPropagation();
152+
}}
153+
sx={{
154+
gap: 1,
155+
width: "250px",
156+
maxWidth: {
157+
xxs: "200px",
158+
xs: "100%",
159+
},
160+
"&:hover": {
161+
opacity: 0.6,
162+
transition: "opacity 0.3s",
163+
},
164+
}}
149165
>
150-
{view}
151-
</Typography>
152-
<img alt="" src={ICONS.copyBlueIcon} />
153-
</ButtonBase>
166+
<Typography
167+
color="primary"
168+
variant="body2"
169+
sx={ellipsisStyles}
170+
>
171+
{view}
172+
</Typography>
173+
<img alt="" src={ICONS.copyBlueIcon} />
174+
</ButtonBase>
175+
<ButtonBase
176+
data-testid={`${cip129Identifier}-copy-id-button`}
177+
onClick={(e) => {
178+
navigator.clipboard.writeText(cip129Identifier);
179+
addSuccessAlert(t("alerts.copiedToClipboard"));
180+
e.stopPropagation();
181+
}}
182+
sx={{
183+
gap: 1,
184+
width: "250px",
185+
maxWidth: {
186+
xxs: "200px",
187+
xs: "100%",
188+
},
189+
"&:hover": {
190+
opacity: 0.6,
191+
transition: "opacity 0.3s",
192+
},
193+
display: "flex",
194+
flexDirection: "row",
195+
}}
196+
>
197+
<Typography variant="body2" sx={ellipsisStyles}>
198+
(CIP-129){" "}
199+
<Typography
200+
color="primary"
201+
variant="body2"
202+
component="span"
203+
>
204+
{cip129Identifier}
205+
</Typography>
206+
</Typography>
207+
<img alt="" src={ICONS.copyBlueIcon} />
208+
</ButtonBase>
209+
</Box>
154210
</Box>
155211
</Box>
156212

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { ICONS, PATHS } from "@consts";
66
import { useCardano, useModal } from "@context";
77
import { useDelegateTodRep, useScreenDimension, useTranslation } from "@hooks";
88
import { Card, DataMissingInfoBox } from "@molecules";
9-
import { correctAdaFormat, testIdFromLabel } from "@utils";
9+
import {
10+
correctAdaFormat,
11+
encodeCIP129Identifier,
12+
testIdFromLabel,
13+
} from "@utils";
1014
import { DRepData } from "@/models";
1115
import { DRepDetailsCardHeader } from "./DRepDetailsCardHeader";
1216

@@ -41,6 +45,7 @@ export const DRepDetailsCard = ({
4145
status,
4246
url,
4347
view,
48+
drepId,
4449
votingPower,
4550
} = dRepData;
4651

@@ -109,6 +114,18 @@ export const DRepDetailsCard = ({
109114
<DRepDetailsInfoItem label={t("drepId")} dataTestId="drep-id">
110115
<CopyableText value={view} dataTestId="copy-drep-id-button" />
111116
</DRepDetailsInfoItem>
117+
<DRepDetailsInfoItem
118+
label={t("cip129DrepId")}
119+
dataTestId="cip-129-drep-id"
120+
>
121+
<CopyableText
122+
value={encodeCIP129Identifier({
123+
txID: `22${drepId}`,
124+
bech32Prefix: "drep",
125+
})}
126+
dataTestId="copy-cip-129-drep-id-button"
127+
/>
128+
</DRepDetailsInfoItem>
112129
<DRepDetailsInfoItem label={t("status")} dataTestId="drep-status">
113130
<StatusPill status={status} />
114131
</DRepDetailsInfoItem>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@
747747
"copiedLink": "Copied link",
748748
"delegate": "Delegate",
749749
"drepId": "DRep ID",
750+
"cip129DrepId": "(CIP-129) DRep ID",
750751
"email": "Email",
751752
"feedback": "Feedback",
752753
"filter": "Filter",

govtool/frontend/src/services/requests/getDRepList.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
DrepDataDTO,
99
} from "@models";
1010
import { API } from "../API";
11-
import { mapDtoToDrep } from "@/utils";
11+
import {
12+
decodeCIP129Identifier,
13+
encodeCIP129Identifier,
14+
mapDtoToDrep,
15+
} from "@/utils";
1216

1317
export type GetDRepListArguments = {
1418
filters?: string[];
@@ -34,6 +38,22 @@ export const getDRepList = async ({
3438
const { words } = bech32.decode(rawSearchPhrase);
3539
return bech32.encode("drep", words);
3640
}
41+
if (rawSearchPhrase.startsWith("drep")) {
42+
const decodedIdentifier = decodeCIP129Identifier(rawSearchPhrase);
43+
if (decodedIdentifier) {
44+
const isCIP129Identifier = decodedIdentifier.txID.startsWith("22");
45+
if (isCIP129Identifier) {
46+
return encodeCIP129Identifier({
47+
txID: decodedIdentifier.txID.slice(2),
48+
bech32Prefix: "drep",
49+
});
50+
}
51+
return encodeCIP129Identifier({
52+
txID: decodedIdentifier.txID,
53+
bech32Prefix: "drep",
54+
});
55+
}
56+
}
3757
return rawSearchPhrase;
3858
})();
3959

govtool/frontend/src/services/requests/getProposals.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { Infinite, ProposalData, ProposalDataDTO } from "@models";
22

33
import { API } from "../API";
4-
import { mapDtoToProposal } from "@/utils";
4+
import {
5+
decodeCIP129Identifier,
6+
getFullGovActionId,
7+
mapDtoToProposal,
8+
} from "@/utils";
59

610
export type GetProposalsArguments = {
711
dRepID?: string;
@@ -18,9 +22,17 @@ export const getProposals = async ({
1822
page = 0,
1923
// It allows fetch proposals and if we have 7 items, display 6 cards and "view all" button
2024
pageSize = 7,
21-
searchPhrase = "",
25+
searchPhrase: rawSearchPhrase = "",
2226
sorting = "",
2327
}: GetProposalsArguments): Promise<Infinite<ProposalData>> => {
28+
const searchPhrase = (() => {
29+
if (rawSearchPhrase.startsWith("gov_action")) {
30+
const { txID } = decodeCIP129Identifier(rawSearchPhrase);
31+
return getFullGovActionId(txID, 0);
32+
}
33+
34+
return rawSearchPhrase;
35+
})();
2436
const response = await API.get<Infinite<ProposalDataDTO>>("/proposal/list", {
2537
params: {
2638
page,

govtool/metadata-validation/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)