diff --git a/src/components/renderer/SvgRenderer.tsx b/src/components/renderer/SvgRenderer.tsx index 79c934e..1ee4a61 100644 --- a/src/components/renderer/SvgRenderer.tsx +++ b/src/components/renderer/SvgRenderer.tsx @@ -82,6 +82,12 @@ const fetchSvg = async (svgInDoc: string, abortController: AbortController) => { return res; }; +const renderSvg = (template: string, document: any) => { + if (template.length === 0) return ""; + const compiledTemplate = handlebars.compile(template); + return document.credentialSubject ? compiledTemplate(document.credentialSubject) : compiledTemplate(document); +}; + // As specified in - https://w3c-ccg.github.io/vc-render-method/#svgrenderingtemplate2023 export const SVG_RENDERER_TYPE = "SvgRenderingTemplate2023"; @@ -114,7 +120,7 @@ const SvgRenderer = React.forwardRef( const handleValidSvgTemplate = (rawSvgTemplate: string) => { setToDisplay({ status: "OK", - svgDataUri: `data:image/svg+xml,${encodeURIComponent(renderTemplate(rawSvgTemplate, document))}`, + svgDataUri: `data:image/svg+xml,${encodeURIComponent(renderSvg(rawSvgTemplate, document))}`, }); }; @@ -170,12 +176,6 @@ const SvgRenderer = React.forwardRef( /* eslint-disable-next-line react-hooks/exhaustive-deps */ }, [document]); - const renderTemplate = (template: string, document: any) => { - if (template.length === 0) return ""; - const compiledTemplate = handlebars.compile(template); - return document.credentialSubject ? compiledTemplate(document.credentialSubject) : compiledTemplate(document); - }; - switch (toDisplay.status) { case "DEFAULT": return null} />;