import React, { useMemo } from "react"; import { Center, IStackProps, HStack, Spinner, Text, View, VStack } from "native-base"; import { CredentialType, CredentialSubjectsByType, AsyncStorage } from "@gooddollar/web3sdk-v2"; import usePromise from "react-use-promise"; import { withTheme } from "../../../theme/hoc/withTheme"; import { truncateMiddle } from "../../../utils"; import { FormattedCertificate, formatVerifiedValues } from "../../../utils/formatVerifiedValues"; import { Title } from "../../../core/layout"; import { Image } from "../../../core/images"; import { GoodButton } from "../../../core/buttons"; import { TransText } from "../../../core/layout"; import { useGoodIdProvider } from "../context/GoodIdProvider"; import UnknownAvatarIcon from "../../../assets/images/goodid/unknown-avatar.png"; import GdVerifiedIcon from "../../../assets/images/goodid/gdverified.png"; import GdUnverifiedIcon from "../../../assets/images/goodid/gdunverified.png"; interface GoodIdCardProps extends IStackProps { account: string; isWhitelisted: boolean; certificateSubjects: CredentialSubjectsByType; avatar?: string; fullname?: string; expiryDate?: string; fontStyles?: any; } const idTypeLabels = { Age: /*i18n*/ "Age", Gender: /*i18n*/ "Gender", Location: /*i18n*/ "Location" }; const CardRowItem = withTheme({ name: "CardRowItem" })( ({ credentialLabel, credential, fontStyles, isNew, ...props }: { credentialLabel: string; credential: FormattedCertificate; isNew: boolean; fontStyles?: any; }) => { const { subHeading, subContent } = fontStyles ?? {}; const verifiedValue = useMemo(() => formatVerifiedValues(credential), [credential]); const verifiedCopy = verifiedValue === `Unverified-${credentialLabel}` ? /*i18n*/ "Unverified" : verifiedValue; return ( {isNew ? "-" : verifiedCopy}
{!isNew ? ( ) : null}
); } ); const GoodIdCard = withTheme({ name: "GoodIdCard", skipProps: "certificates" })( ({ account, isWhitelisted, certificateSubjects, avatar, fullname, expiryDate, ...props }: GoodIdCardProps) => { const { onGoToClaim } = useGoodIdProvider(); const { title, subHeading, subContent, footer } = props.fontStyles ?? {}; const truncatedAccount = truncateMiddle(account, 11); const [disputedSubjects] = usePromise(() => AsyncStorage.getItem("goodid_disputedSubjects"), []); if (disputedSubjects === undefined) return ; return ( {`GoodID`} {truncatedAccount} {isWhitelisted && (
)}
{fullname ? ( {fullname} ) : null}
{/* subjects can be empty so we use credentialtype for mapping */} {Object.keys(CredentialType) .filter((typeName): typeName is Exclude => typeName !== "Identity") .map(typeName => ( ))} {!certificateSubjects && onGoToClaim ? ( ) : null} {expiryDate ? ( ) : null}
); } ); export default GoodIdCard;