From 4e7c33c6747c48bb38915815d3ed84a50c4c9f5d Mon Sep 17 00:00:00 2001 From: linhan <15726044837@163.com> Date: Sat, 4 Feb 2023 16:24:11 +0800 Subject: [PATCH] feat: add credential card bg (#16) Co-authored-by: alpers Co-authored-by: Zhichao Zhang release-as: 0.13.0 --- packages/app-config/src/ctypes/index.ts | 17 ++++++++++------- packages/page-claims/src/CredentialCell.tsx | 18 ++++++++++++++++-- packages/react-hooks/src/useCTypeMeta.ts | 12 +++++++++++- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/packages/app-config/src/ctypes/index.ts b/packages/app-config/src/ctypes/index.ts index de85dd37..b23ab738 100644 --- a/packages/app-config/src/ctypes/index.ts +++ b/packages/app-config/src/ctypes/index.ts @@ -32,6 +32,7 @@ export const ctypeMeta: Record = { type: 'all', card: 'christmas2022/bac_card2.webp' }, + // legal-dao '0xa99186086d83f834f0bf951cb7f78cd142f147f3bd7a689086f157418944716c': { type: 'attest', card: 'legal-dao/bg2.jpeg', @@ -67,17 +68,19 @@ export const TOP_CTYPES_FOR_ATTEST: HexString[] = isRelease : []; export function getCTypeMetaForIssue(id: HexString): CTypeMeta | undefined { - const meta: CTypeMeta | undefined = ctypeMeta[id]; - - if (!meta) return undefined; + const meta: CTypeMeta | undefined = getCTypeMeta(id); - return ['all', 'issue'].includes(meta.type) ? meta : undefined; + return meta && ['all', 'issue'].includes(meta.type) ? meta : undefined; } export function getCTypeMetaForAttest(id: HexString): CTypeMeta | undefined { - const meta: CTypeMeta | undefined = ctypeMeta[id]; + const meta: CTypeMeta | undefined = getCTypeMeta(id); - if (!meta) return undefined; + return meta && ['all', 'attest'].includes(meta.type) ? meta : undefined; +} + +export function getCTypeMeta(id: HexString): CTypeMeta | undefined { + const meta: CTypeMeta | undefined = ctypeMeta[id]; - return ['all', 'attest'].includes(meta.type) ? meta : undefined; + return meta ?? undefined; } diff --git a/packages/page-claims/src/CredentialCell.tsx b/packages/page-claims/src/CredentialCell.tsx index 31325e9f..54c9430b 100644 --- a/packages/page-claims/src/CredentialCell.tsx +++ b/packages/page-claims/src/CredentialCell.tsx @@ -24,7 +24,7 @@ import { } from '@credential/react-components'; import { ellipsisMixin } from '@credential/react-components/utils'; import { DidName } from '@credential/react-dids'; -import { useToggle } from '@credential/react-hooks'; +import { useCTypeMeta, useToggle } from '@credential/react-hooks'; import { isMobile } from '@credential/react-hooks/utils/userAgent'; import DownloadButton from './button/DownloadButton'; @@ -120,6 +120,8 @@ function CredentialCell({ credential, issuer, rootHash, status, time }: Credenti const vc = useMemo(() => (isVC(credential) ? credential : null), [credential]); + const ctypeMeta = useCTypeMeta(vc?.ctype); + return ( <> @@ -143,7 +145,19 @@ function CredentialCell({ credential, issuer, rootHash, status, time }: Credenti : palette.success.main })} /> - + diff --git a/packages/react-hooks/src/useCTypeMeta.ts b/packages/react-hooks/src/useCTypeMeta.ts index 23444c21..8d57ac02 100644 --- a/packages/react-hooks/src/useCTypeMeta.ts +++ b/packages/react-hooks/src/useCTypeMeta.ts @@ -7,7 +7,11 @@ import type { CTypeMeta } from '@credential/app-config/ctypes/type'; import { useMemo } from 'react'; -import { getCTypeMetaForAttest, getCTypeMetaForIssue } from '@credential/app-config/ctypes'; +import { + getCTypeMeta, + getCTypeMetaForAttest, + getCTypeMetaForIssue +} from '@credential/app-config/ctypes'; export function useCTypeMetaForIssue(id: HexString): CTypeMeta | undefined { return useMemo(() => getCTypeMetaForIssue(id), [id]); @@ -16,3 +20,9 @@ export function useCTypeMetaForIssue(id: HexString): CTypeMeta | undefined { export function useCTypeMetaForAttest(id: HexString): CTypeMeta | undefined { return useMemo(() => getCTypeMetaForAttest(id), [id]); } + +export function useCTypeMeta(id?: HexString): CTypeMeta | undefined { + return useMemo(() => { + return id ? getCTypeMeta(id) : undefined; + }, [id]); +}