Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FrameConnector returns "This is the OpenAttestation default renderer" #74

Open
tmarcus68 opened this issue Nov 15, 2021 · 1 comment
Open
Assignees

Comments

@tmarcus68
Copy link

I have created a renderer and hosted it, the renderer is working on opencerts.io.

Now I am trying to use to show the rendered any certificate on my own FE.

The code I use is as follows.

DecentralisedRenderer.js

import React, { useRef, useCallback, useState } from "react";

import { FrameConnector, renderDocument } from "@govtechsg/decentralized-renderer-react-components";

const DecentralisedRenderer = (props) => {
  const toFrame = useRef();
  const SCROLLBAR_WIDTH = 20;
  const [height, setHeight] = useState(0);

  const onConnected = useCallback(
    (frame) => {
      toFrame.current = frame;
      if (toFrame.current) {
        toFrame.current(renderDocument({ document: JSON.parse(props.certificate) }));
      }
    },
    [props.certificate]
  );

  const dispatch = (action) => {
    console.log(action);
    if (action.type === "UPDATE_HEIGHT") {
      setHeight(action.payload + SCROLLBAR_WIDTH);
    }
  };

  return (
    <FrameConnector
      style={{ height: '${height}px`, width: "95%" }}
      source={props.source}
      onConnected={onConnected}
      dispatch={dispatch}
    />
  );
};

export default DecentralisedRenderer;

The component is then called via <DecentralisedRenderer certificate={document} source={renderer} /> with the document being the raw string of the .opencert file selected and source being the renderer URL.

The iframe shows "This is the OpenAttestation default renderer" instead of my custom renderer.

The console.log for "UPDATE_TEMPLATES" is as follows.
{type: 'UPDATE_TEMPLATES', payload: Array(1), meta: undefined} meta: undefined payload: Array(1) 0: {id: 'default-template', label: 'Default', type: 'custom-template'} length: 1 [[Prototype]]: Array(0) type: "UPDATE_TEMPLATES" [[Prototype]]: Object

How can I set my custom template and renderer any certificate on my site? FE is running on react js.

@HJunyuan
Copy link
Member

Hi @tmarcus68,

It seems like you have missed out on the dispatch handler for updateTemplate (UPDATE_TEMPLATE).

Please refer to the following example application:

if (isActionOf(updateTemplates, action)) {
setTemplates(action.payload);
setSelectedTemplate(action.payload[0].id);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants