import { useEffect, useState } from "react"; import { VC } from "vc-schema-tools"; // import { usePalette } from "react-palette"; // import { readableColor } from "polished"; import { truncateDid } from "../../../utils"; import { Box, Flex, Text } from "rimble-ui"; import { DomainImage, LockUnverified, LockVerified } from "../../elements"; import { H4 } from "../../layouts"; import { baseColors, colors, fonts } from "../../../themes"; import { validateVc } from "vc-schema-tools"; import { SchemaDataResponse } from "../Schemas/types"; export interface CredentialHeaderProps { issuer: string; issuerDomain?: string; vc: VC; vcSchema?: SchemaDataResponse; vcType: string; } export const CredentialHeader: React.FunctionComponent = (props) => { const { issuer, issuerDomain, vc, vcSchema, vcType } = props; const [isValid, setIsValid] = useState(); // TODO add org profile data /*let logoUrl = "https://www.google.com/s2/favicons?sz=64&domain=" + issuerDomain; const googleProxyURL = "https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&refresh=2592000&url="; logoUrl = googleProxyURL + encodeURIComponent(logoUrl); const { data, loading, error } = usePalette(logoUrl); const backgroundColor = loading ? "transparent" : error ? colors.primary.base : data.vibrant; const textColor = loading ? "transparent" : error ? baseColors.white : readableColor(data.vibrant);*/ const backgroundColor = colors.primary.base; const textColor = baseColors.white; useEffect(() => { return void (async function validate() { try { const { valid } = await validateVc(vc); if (valid) { setIsValid(true); } else { setIsValid(false); } } catch (error) { console.error("error verifying vc: ", error); setIsValid(false); } })(); }, [vc]); return ( {issuerDomain ? ( {issuerDomain} ) : ( {truncateDid(issuer)} )} {isValid ? : } {vcSchema?.icon && ( {vcSchema.icon} )}

{vcSchema?.name || vc.credentialSubject.title || vcType}

{vc.credentialSubject.id && ( Subject: {truncateDid(vc.credentialSubject.id)} )}
); };