import { Box, Tooltip } from "rimble-ui"; import { Info } from "@rimble/icons"; import { JsonSchemaNode } from "vc-schema-tools"; import { hexEllipsis } from "../../../utils/helpers"; import { CredentialTDLeft, CredentialTDRight, CredentialTR } from "./CredentialComponents"; import { colors } from "../../../themes/colors"; export interface CredentialPropertyProps { keyName: string /** "key" prop name is reserved by React */; value: any; nestedLevel?: number; parentKey?: string; schema?: JsonSchemaNode; } export const CredentialProperty: React.FunctionComponent = (props) => { const { schema, keyName, value } = props; const nestedLevel = props.nestedLevel || 0; const parentKey = props.parentKey || ""; const keyDisplay = schema?.title || keyName; const keyDescription = schema?.description; let valueDisplay = ""; let valueTooltip = ""; if (value === "boolean" || Array.isArray(value)) { valueDisplay = JSON.stringify(value); } else if (typeof value === "string" && value.indexOf("0x") !== -1) { valueDisplay = hexEllipsis(value); valueTooltip = value; } else if (value && typeof value !== "object") { valueDisplay = value; } return ( <> {keyDisplay} {keyDescription && ( )} {valueTooltip ? ( {valueDisplay} ) : ( valueDisplay )} {value && typeof value === "object" && !Array.isArray(value) && Object.entries(value).map(([nestedKey, nestedValue]) => ( ))} ); };