diff --git a/docs/GOVERNANCE_ACTION_SUBMISSION.md b/docs/GOVERNANCE_ACTION_SUBMISSION.md index 1f41a31fd..2262d5ddd 100644 --- a/docs/GOVERNANCE_ACTION_SUBMISSION.md +++ b/docs/GOVERNANCE_ACTION_SUBMISSION.md @@ -144,3 +144,46 @@ await buildSignSubmitConwayCertTx({ ### Step 6: Verify the Governance Action `buildSignSubmitConwayCertTx` logs the transaction CBOR making it able to be tracked on the transactions tools such as cexplorer. + +## Additional steps for using the GovTool metadata validation on the imported Pillar component + +```tsx +enum MetadataValidationStatus { + URL_NOT_FOUND = "URL_NOT_FOUND", + INVALID_JSONLD = "INVALID_JSONLD", + INVALID_HASH = "INVALID_HASH", + INCORRECT_FORMAT = "INCORRECT_FORMAT", +} +// Using the props passed to the component +type Props = { + validateMetadata: ({ + url, + hash, + standard, + }: { + url: string; + hash: string; + standard: "CIP108"; + }) => Promise<{ + metadata?: any; + status?: MetadataValidationStatus; + valid: boolean; + }>; +}; + +import React, { Suspense } from "react"; + +const SomeImportedPillar: React.FC = React.lazy( + () => import("path/to/SomeImportedPillar") +); + +const SomeWrapperComponent = () => { + const { validateMetadata } = useValidateMutation(); + + return ( + I am lazy loading...}> + + + ); +}; +``` diff --git a/govtool/frontend/src/components/organisms/PDFWrapper.tsx b/govtool/frontend/src/components/organisms/PDFWrapper.tsx index 5571c632d..310bc889d 100644 --- a/govtool/frontend/src/components/organisms/PDFWrapper.tsx +++ b/govtool/frontend/src/components/organisms/PDFWrapper.tsx @@ -1,11 +1,15 @@ -import React, { Suspense } from "react"; +import React, { ComponentProps, Suspense } from "react"; import { Box, CircularProgress } from "@mui/material"; import "@intersect.mbo/pdf-ui/style"; import { useCardano, useGovernanceActions } from "@/context"; +import { useValidateMutation } from "@/hooks/mutations"; -const PDF = React.lazy(() => import("@intersect.mbo/pdf-ui/cjs")); +const ProposalDiscussion = React.lazy( + () => import("@intersect.mbo/pdf-ui/cjs"), +); export const PDFWrapper = () => { + const { validateMetadata } = useValidateMutation(); const { walletApi, ...context } = useCardano(); const { createGovernanceActionJsonLD, createHash } = useGovernanceActions(); @@ -33,7 +37,7 @@ export const PDFWrapper = () => { } > - { createHash, }} pathname={window.location.pathname} + validateMetadata={ + validateMetadata as ComponentProps< + typeof ProposalDiscussion + >["validateMetadata"] + } /> diff --git a/govtool/frontend/src/types/@intersect.mbo.d.ts b/govtool/frontend/src/types/@intersect.mbo.d.ts index 3c9ca7e21..df61e1eae 100644 --- a/govtool/frontend/src/types/@intersect.mbo.d.ts +++ b/govtool/frontend/src/types/@intersect.mbo.d.ts @@ -1,10 +1,32 @@ -type PDFProps = { +enum MetadataValidationStatus { + URL_NOT_FOUND = "URL_NOT_FOUND", + INVALID_JSONLD = "INVALID_JSONLD", + INVALID_HASH = "INVALID_HASH", + INCORRECT_FORMAT = "INCORRECT_FORMAT", +} + +type ProposalDiscussionProps = { // eslint-disable-next-line @typescript-eslint/no-explicit-any walletAPI: any; pathname: string; locale?: string; + validateMetadata: ({ + url, + hash, + standard, + }: { + url: string; + hash: string; + standard: "CIP108"; + }) => Promise< + // eslint-disable-next-line @typescript-eslint/no-explicit-any + | { status?: MetadataValidationStatus; metadata?: any; valid: boolean } + | undefined + >; }; declare module "@intersect.mbo/pdf-ui/cjs" { - export default function PDF(props: PDFProps): JSX.Element; + export default function ProposalDiscussion( + props: ProposalDiscussionProps, + ): JSX.Element; }