Skip to content

Commit 9bce34e

Browse files
committed
fix(#2509): fix nested @value in metadatas
1 parent a2fa857 commit 9bce34e

File tree

10 files changed

+20
-44
lines changed

10 files changed

+20
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ changes.
2020
- Fix link and description validation [Issue 2403](https://github.com/IntersectMBO/govtool/issues/2403)
2121
- Revert to drep_distr for providing active voting power
2222
- Add rewards amount in the ada holder voting power
23+
- Fix nested @value in jsonld metadatas [Issue 2509](https://github.com/IntersectMBO/govtool/issues/2509)
2324

2425
### Changed
2526

govtool/frontend/src/consts/governanceAction/fields.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export const GOVERNANCE_ACTION_FIELDS: GovernanceActionFields = {
126126
} as const;
127127

128128
export const GOVERNANCE_ACTION_CONTEXT = {
129+
"@language": "en-us",
129130
CIP100:
130131
"https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#",
131132
CIP108:

govtool/frontend/src/context/featureFlag.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const FeatureFlagProvider = ({ children }: PropsWithChildren) => {
127127
() => ({
128128
isProposalDiscussionForumEnabled:
129129
import.meta.env.VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED === "true" ||
130+
import.meta.env.VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED === true ||
130131
false,
131132
isVotingOnGovernanceActionEnabled,
132133
areDRepVoteTotalsDisplayed,

govtool/frontend/src/context/governanceAction.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { NodeObject } from "jsonld";
1010
import { blake2bHex } from "blakejs";
1111
import * as Sentry from "@sentry/react";
1212

13-
import { CIP_108, GOVERNANCE_ACTION_CONTEXT } from "@/consts";
13+
import { GOVERNANCE_ACTION_CONTEXT } from "@/consts";
1414
import { generateJsonld, generateMetadataBody } from "@/utils";
1515

1616
type GovActionMetadata = {
@@ -53,7 +53,6 @@ const GovernanceActionProvider = ({ children }: PropsWithChildren) => {
5353
const metadataBody = generateMetadataBody({
5454
data: govActionMetadata,
5555
acceptedKeys: ["title", "abstract", "motivation", "rationale"],
56-
standardReference: CIP_108,
5756
});
5857

5958
const jsonLD = await generateJsonld(

govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { useTranslation } from "react-i18next";
77
import { NodeObject } from "jsonld";
88

99
import {
10-
CIP_108,
1110
GOVERNANCE_ACTION_CONTEXT,
1211
PATHS,
1312
storageInformationErrorModals,
@@ -104,7 +103,6 @@ export const useCreateGovernanceActionForm = (
104103
const body = generateMetadataBody({
105104
data: getValues(),
106105
acceptedKeys: ["title", "motivation", "abstract", "rationale"],
107-
standardReference: CIP_108,
108106
});
109107

110108
const jsonld = await generateJsonld(body, GOVERNANCE_ACTION_CONTEXT);

govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import { blake2bHex } from "blakejs";
66
import * as Sentry from "@sentry/react";
77
import { NodeObject } from "jsonld";
88

9-
import {
10-
CIP_119,
11-
DREP_CONTEXT,
12-
PATHS,
13-
storageInformationErrorModals,
14-
} from "@consts";
9+
import { DREP_CONTEXT, PATHS, storageInformationErrorModals } from "@consts";
1510
import { useCardano, useModal, useAppContext } from "@context";
1611
import { downloadJson, generateJsonld, generateMetadataBody } from "@utils";
1712
import { MetadataValidationStatus } from "@models";
@@ -92,13 +87,11 @@ export const useEditDRepInfoForm = (
9287
"motivations",
9388
"qualifications",
9489
"paymentAddress",
95-
"references",
9690
"doNotList",
9791
],
98-
standardReference: CIP_119,
9992
});
10093

101-
const jsonld = await generateJsonld(body, DREP_CONTEXT, CIP_119);
94+
const jsonld = await generateJsonld(body, DREP_CONTEXT);
10295

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

govtool/frontend/src/hooks/forms/useRegisterAsdRepForm.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ import * as Sentry from "@sentry/react";
77
import { NodeObject } from "jsonld";
88
import { CertificatesBuilder } from "@emurgo/cardano-serialization-lib-asmjs";
99

10-
import {
11-
CIP_119,
12-
DREP_CONTEXT,
13-
PATHS,
14-
storageInformationErrorModals,
15-
} from "@consts";
10+
import { DREP_CONTEXT, PATHS, storageInformationErrorModals } from "@consts";
1611
import { useCardano, useModal, useAppContext } from "@context";
1712
import { MetadataValidationStatus } from "@models";
1813
import {
@@ -108,12 +103,11 @@ export const useRegisterAsdRepForm = (
108103
"motivations",
109104
"qualifications",
110105
"paymentAddress",
111-
"references",
112106
"doNotList",
113107
],
114-
standardReference: CIP_119,
115108
});
116-
const jsonld = await generateJsonld(body, DREP_CONTEXT, CIP_119);
109+
110+
const jsonld = await generateJsonld(body, DREP_CONTEXT);
117111

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

govtool/frontend/src/hooks/forms/useVoteContextForm.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { NodeObject } from "jsonld";
66

77
import { downloadJson, generateJsonld, generateMetadataBody } from "@utils";
88
import { MetadataValidationStatus } from "@models";
9-
import { CIP_100, CIP_100_CONTEXT } from "@/consts";
9+
import { CIP_100_CONTEXT } from "@/consts";
1010

1111
import { useValidateMutation } from "../mutations";
1212

@@ -43,9 +43,8 @@ export const useVoteContextForm = (
4343
comment: voteContextText,
4444
},
4545
acceptedKeys: ["comment"],
46-
standardReference: CIP_100,
4746
});
48-
const jsonld = await generateJsonld(body, CIP_100_CONTEXT, CIP_100);
47+
const jsonld = await generateJsonld(body, CIP_100_CONTEXT);
4948

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

govtool/frontend/src/utils/generateJsonld.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as jsonld from "jsonld";
22

3-
import { CIP_100, CIP_108 } from "@/consts";
4-
53
/**
64
* Generates a JSON-LD document by compacting the given body and context.
75
*
@@ -17,12 +15,11 @@ export const generateJsonld = async <
1715
>(
1816
body: T,
1917
context: C,
20-
bodyCip: string = CIP_108,
2118
) => {
2219
const doc = {
23-
[`${bodyCip}body`]: body,
24-
[`${CIP_100}hashAlgorithm`]: "blake2b-256",
25-
[`${CIP_100}authors`]: [],
20+
"@context": context,
21+
hashAlgorithm: "blake2b-256",
22+
body,
2623
};
2724

2825
const json = await jsonld.compact(doc, context);

govtool/frontend/src/utils/generateMetadataBody.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import { CIP_100, CIP_108, CIP_119 } from "@/consts";
2-
3-
type StandardReference = typeof CIP_100 | typeof CIP_108 | typeof CIP_119;
4-
51
type MetadataConfig = {
62
data: Record<string, unknown>;
73
acceptedKeys: string[];
8-
standardReference: StandardReference;
94
};
105

116
/**
@@ -18,27 +13,25 @@ type MetadataConfig = {
1813
export const generateMetadataBody = ({
1914
data,
2015
acceptedKeys,
21-
standardReference,
2216
}: MetadataConfig) => {
2317
const filteredData = Object.entries(data)
24-
.filter(([key]) => acceptedKeys.includes(key))
25-
.map(([key, value]) => [standardReference + key, value]);
18+
.filter(([key, value]) => value && acceptedKeys.includes(key))
19+
.map(([key, value]) => [key, value]);
2620

2721
const references = data?.references
2822
? // uri should not be optional. It is just not yet supported on govtool
2923
(data.references as Array<Partial<Reference>>)
3024
.filter((link) => link.uri)
3125
.map((link) => ({
3226
"@type": link["@type"] ?? "Other",
33-
[`${CIP_100}reference-label`]: link.label || "Label",
34-
[`${CIP_100}reference-uri`]: link.uri,
27+
label: link.label || "Label",
28+
uri: link.uri,
3529
}))
3630
: undefined;
3731

3832
const body = Object.fromEntries(filteredData);
39-
40-
if (references) {
41-
body[`${standardReference}references`] = references;
33+
if (references?.length) {
34+
body.references = references;
4235
}
4336

4437
return body;

0 commit comments

Comments
 (0)