Skip to content

Commit 74eef2b

Browse files
committed
feat: add support for CIP129 in governance actions
1 parent 3c4585e commit 74eef2b

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ export const DashboardGovernanceActionDetails = () => {
9999

100100
useEffect(() => {
101101
const isProposalNotFound =
102-
(error as AxiosError)?.response?.data ===
103-
`Proposal with id: ${fullProposalId} not found`;
104-
if (isProposalNotFound && fullProposalId) {
102+
error instanceof AxiosError &&
103+
error.response?.data.match(/Proposal with id: .* not found/);
104+
if (isProposalNotFound && fullProposalId) {
105105
navigate(
106106
OUTCOMES_PATHS.governanceActionOutcomes.replace(":id", fullProposalId),
107107
);

govtool/frontend/src/pages/GovernanceActionDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export const GovernanceActionDetails = () => {
9494

9595
useEffect(() => {
9696
const isProposalNotFound =
97-
(error as AxiosError)?.response?.data ===
98-
`Proposal with id: ${fullProposalId} not found`;
97+
error instanceof AxiosError &&
98+
error.response?.data.match(/Proposal with id: .* not found/);
9999
if (isProposalNotFound && fullProposalId) {
100100
navigate(
101101
OUTCOMES_PATHS.governanceActionOutcomes.replace(":id", fullProposalId),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ export const getProposal = async (
77
proposalId: string,
88
drepId?: string,
99
): Promise<VotedProposal> => {
10-
const isCIP129Identifier = proposalId.includes("gov_action");
10+
const isCIP129Identifier = proposalId.startsWith("gov_action");
1111
if (isCIP129Identifier) {
12-
const { txID } = decodeCIP129Identifier(proposalId);
13-
proposalId = txID;
12+
const { txID, index } = decodeCIP129Identifier(proposalId);
13+
proposalId = `${txID}#${parseInt(index, 16)}`;
1414
}
1515

1616
const encodedHash = encodeURIComponent(proposalId);

govtool/frontend/src/utils/getGovActionId.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ export const getShortenedGovActionId = (
99
const firstPart = txHash.slice(0, 4);
1010
const lastPart = txHash.slice(-4);
1111

12-
return `${firstPart}...${lastPart}#${index}`;
12+
return txHash.startsWith("gov_action")
13+
? `${firstPart}...${lastPart}`
14+
: `${firstPart}...${lastPart}#${index}`;
1315
};
1416

1517
export const getFullGovActionId = (txHash: string, index: number | string) =>
16-
`${txHash}#${index}`;
18+
(txHash.startsWith("gov_action") ? txHash : `${txHash}#${index}`);

govtool/frontend/src/utils/tests/getGovActionId.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ describe("getShortenedGovActionId", () => {
2828
const result = getShortenedGovActionId(txHash, index);
2929
expect(result).toBe("#1");
3030
});
31+
32+
it("should handle a hash starting with 'gov_action' correctly", () => {
33+
const txHash = "gov_action_1234567890abcdef";
34+
const index = 7;
35+
const result = getShortenedGovActionId(txHash, index);
36+
expect(result).toBe("gov_...cdef");
37+
});
3138
});
3239

3340
describe("getFullGovActionId", () => {
@@ -37,4 +44,11 @@ describe("getFullGovActionId", () => {
3744
const result = getFullGovActionId(txHash, index);
3845
expect(result).toBe("1234567890abcdef1234567890abcdef#10");
3946
});
47+
48+
it("should return the full id without index if txHash starts with 'gov_action'", () => {
49+
const txHash = "gov_action_1234567890abcdef";
50+
const index = 5;
51+
const result = getFullGovActionId(txHash, index);
52+
expect(result).toBe("gov_action_1234567890abcdef");
53+
});
4054
});

0 commit comments

Comments
 (0)