Skip to content

Commit

Permalink
fix: handle case where version cannot be determined
Browse files Browse the repository at this point in the history
  • Loading branch information
phanshiyu committed May 12, 2024
1 parent 2a2684a commit 848ce18
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/components/TheRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ type VersionedDocument =
};
function getVersionedDocument(
document: v2.OpenAttestationDocument | v2.WrappedDocument | v4.Document
): VersionedDocument {
): VersionedDocument | { version: null } {
if (utils.isWrappedV2Document(document)) {
return {
version: "2.0",
rawDocument: document,
document: getData(document),
};
} else if (utils.isRawV2Document(document)) {
return {
version: "2.0",
document,
};
} else if (v4.isDocument(document)) {
return {
version: "4.0",
Expand All @@ -60,8 +65,7 @@ function getVersionedDocument(
}

return {
version: "2.0",
document,
version: null,
};
}

Expand Down Expand Up @@ -307,6 +311,22 @@ type TheRendererProps = {
};
export const TheRenderer: React.FunctionComponent<TheRendererProps> = ({ document, ...rest }) => {
const versionedDocument = React.useMemo(() => getVersionedDocument(document), [document]);

if (versionedDocument.version === null) {
return (
<DefaultTemplate
title="Version of document cannot be determined"
description={
<>
The version of this document cannot be determined and hence cannot be rendered, this current display is
intended.
</>
}
document={document}
/>
);
}

const renderMethod = getRenderMethod(versionedDocument);

// TODO: can render default renderer here
Expand Down

0 comments on commit 848ce18

Please sign in to comment.