From 848ce18c828d93466cb2fc9e30699d4d48374abe Mon Sep 17 00:00:00 2001 From: Phan Shi Yu Date: Sun, 12 May 2024 12:34:12 +0800 Subject: [PATCH] fix: handle case where version cannot be determined --- src/components/TheRenderer.tsx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/components/TheRenderer.tsx b/src/components/TheRenderer.tsx index 303eedf..e1b1530 100644 --- a/src/components/TheRenderer.tsx +++ b/src/components/TheRenderer.tsx @@ -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", @@ -60,8 +65,7 @@ function getVersionedDocument( } return { - version: "2.0", - document, + version: null, }; } @@ -307,6 +311,22 @@ type TheRendererProps = { }; export const TheRenderer: React.FunctionComponent = ({ document, ...rest }) => { const versionedDocument = React.useMemo(() => getVersionedDocument(document), [document]); + + if (versionedDocument.version === null) { + return ( + + 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