Skip to content

Commit

Permalink
fix(#1894): fix metadata hash generation
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Sep 3, 2024
1 parent d7e9fa4 commit 4e3bb67
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ export const DRepDashboardCard = ({
title: t("dashboard.cards.drep.dRepRegistration"),
}),
...(pendingTransaction.retireAsDrep && {
description: (
description: voter?.givenName ? (
<Trans
i18nKey="dashboard.cards.drep.retirementInProgressWithGivenName"
values={{
deposit: correctAdaFormat(voter?.deposit),
name: voter?.givenName,
}}
/>
) : (
<Trans
i18nKey="dashboard.cards.drep.retirementInProgress"
values={{ deposit: correctAdaFormat(voter?.deposit) }}
Expand Down
6 changes: 5 additions & 1 deletion govtool/frontend/src/context/governanceAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ const GovernanceActionProvider = ({ children }: PropsWithChildren) => {
*/
const createHash = useCallback(async (jsonLD: NodeObject) => {
try {
const jsonHash = blake2bHex(JSON.stringify(jsonLD), undefined, 32);
const jsonHash = blake2bHex(
JSON.stringify(jsonLD, null, 2),
undefined,
32,
);
return jsonHash;
} catch (error) {
Sentry.captureException(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const useCreateGovernanceActionForm = (

const jsonld = await generateJsonld(body, GOVERNANCE_ACTION_CONTEXT);

const jsonHash = blake2bHex(JSON.stringify(jsonld), undefined, 32);
const jsonHash = blake2bHex(JSON.stringify(jsonld, null, 2), undefined, 32);

// That allows to validate metadata hash
setHash(jsonHash);
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const useEditDRepInfoForm = (

const jsonld = await generateJsonld(body, DREP_CONTEXT, CIP_119);

const jsonHash = blake2bHex(JSON.stringify(jsonld), undefined, 32);
const jsonHash = blake2bHex(JSON.stringify(jsonld, null, 2), undefined, 32);

setHash(jsonHash);
setJson(jsonld);
Expand Down
3 changes: 1 addition & 2 deletions govtool/frontend/src/hooks/forms/useRegisterAsdRepForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ export const useRegisterAsdRepForm = (
],
standardReference: CIP_119,
});

const jsonld = await generateJsonld(body, DREP_CONTEXT, CIP_119);

const jsonHash = blake2bHex(JSON.stringify(jsonld), undefined, 32);
const jsonHash = blake2bHex(JSON.stringify(jsonld, null, 2), undefined, 32);

setHash(jsonHash);
setJson(jsonld);
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/hooks/forms/useVoteContextForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const useVoteContextForm = (
});
const jsonld = await generateJsonld(body, CIP_100_CONTEXT, CIP_100);

const jsonHash = blake2bHex(JSON.stringify(jsonld), undefined, 32);
const jsonHash = blake2bHex(JSON.stringify(jsonld, null, 2), undefined, 32);

// That allows to validate metadata hash
setHash(jsonHash);
Expand Down
12 changes: 7 additions & 5 deletions govtool/frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const en = {
reRegister: "Re-register as a DRep",
retire: "Retire as a DRep",
retirementInProgress:
"You are being retired as <strong>MrDRep</strong>. You will receive a refund of <strong>{{deposit}} ADA</strong> when the transaction completes.",
"You are being retired. You will receive a refund of <strong>{{deposit}} ADA</strong> when the transaction completes.",
retirementInProgressWithGivenName:
"You are being retired as <strong>{{givenName}}</strong>. You will receive a refund of <strong>{{deposit}} ADA</strong> when the transaction completes.",
viewDetails: "View your DRep details",
youAreRegistered: "You are Registered as a DRep",
yourDRepId: "Your DRep ID",
Expand Down Expand Up @@ -361,7 +363,8 @@ export const en = {
},
dRepData: {
givenName: "DRep Name",
givenNameHelpfulText: "This is the name that will be shown on your DRep profile",
givenNameHelpfulText:
"This is the name that will be shown on your DRep profile",
objectives: "Objectives",
objectivesHelpfulText:
"What you believe and what you want to achieve as a DRep.",
Expand Down Expand Up @@ -391,10 +394,9 @@ export const en = {
},
references: "References",
referenceDescription: "Description",
referenceDescriptionHelpfulText:
"Limit: 80 characters",
referenceDescriptionHelpfulText: "Limit: 80 characters",
referenceURL: "URL",
},
},
errors: {
tooLongUrl: "Url must be less than 128 bytes",
mustBeStakeAddress: "It must be reward address in bech32 format",
Expand Down

0 comments on commit 4e3bb67

Please sign in to comment.