diff --git a/packages/dapp/src/app/[locale]/app/(public)/share-presentation/[id]/FormattedView.tsx b/packages/dapp/src/app/[locale]/app/(public)/share-presentation/[id]/FormattedView.tsx index 296e99985..3a917d5aa 100644 --- a/packages/dapp/src/app/[locale]/app/(public)/share-presentation/[id]/FormattedView.tsx +++ b/packages/dapp/src/app/[locale]/app/(public)/share-presentation/[id]/FormattedView.tsx @@ -13,52 +13,29 @@ import type { } from '@veramo/core'; import { useTranslations } from 'next-intl'; import { usePathname, useRouter } from 'next/navigation'; -import { useEffect, useMemo, useState } from 'react'; +import { useMemo, useState } from 'react'; import { VerificationInfoModal } from '@/components/VerificationInfoModal'; import { copyToClipboard } from '@/utils/string'; import CredentialPanel from './CredentialPanel'; import { formatDid } from '@/utils/format'; -import { - type VerificationResult, - VerificationService, -} from '@blockchain-lab-um/extended-verification'; -import { isError } from '@blockchain-lab-um/masca-connector'; -import { useToastStore } from '@/stores'; - -const verifyPresentation = async (presentation: VerifiablePresentation) => { - await VerificationService.init(); - - const verifiedResult = await VerificationService.verify(presentation); - - if (isError(verifiedResult)) { - console.error('Failed to verify presentation'); - setTimeout(() => { - useToastStore.setState({ - open: true, - title: 'Failed to verify presentation', - type: 'error', - loading: false, - link: null, - }); - }, 200); - return { verified: false } as VerificationResult; - } - - return verifiedResult.data; -}; +import type { VerificationResult } from '@blockchain-lab-um/extended-verification'; +import type { Result } from '@blockchain-lab-um/masca-connector'; export const FormattedView = async ({ credential, presentation, page, total, + verificationResult, }: { credential: VerifiableCredential; presentation: VerifiablePresentation; page: string; total: number; + verificationResult: Result; }) => { + console.log('FormattedView'); const t = useTranslations('FormattedView'); const router = useRouter(); @@ -69,29 +46,11 @@ export const FormattedView = async ({ const [verificationInfoModalOpen, setVerificationInfoModalOpen] = useState(false); - const [verificationResult, setVerificationResult] = - useState(null); - const isValid = useMemo(() => { if (!expirationDate) return true; return Date.parse(expirationDate) > Date.now(); }, [expirationDate]); - useEffect(() => { - verifyPresentation(presentation) - .then((result) => setVerificationResult(result)) - .catch((error) => { - console.error(error); - useToastStore.setState({ - open: true, - title: t('verify-failed'), - type: 'error', - loading: false, - link: null, - }); - }); - }, [presentation]); - return ( <>
diff --git a/packages/dapp/src/app/[locale]/app/(public)/share-presentation/[id]/page.tsx b/packages/dapp/src/app/[locale]/app/(public)/share-presentation/[id]/page.tsx index 8173fbafe..c3f21e7d5 100644 --- a/packages/dapp/src/app/[locale]/app/(public)/share-presentation/[id]/page.tsx +++ b/packages/dapp/src/app/[locale]/app/(public)/share-presentation/[id]/page.tsx @@ -7,9 +7,16 @@ import { convertTypes } from '@/utils/string'; import { FormattedView } from './FormattedView'; import { usePresentation, useUpdatePresentationViews } from '@/hooks'; import { NormalViewButton } from './NormalViewButton'; +import { VerificationService } from '@blockchain-lab-um/extended-verification'; +import type { VerifiablePresentation } from '@veramo/core'; export const revalidate = 0; +const verifyPresentation = async (presentation: VerifiablePresentation) => { + await VerificationService.init(); + return VerificationService.verify(presentation); +}; + export default async function Page({ params: { id }, searchParams, @@ -28,6 +35,8 @@ export default async function Page({ await useUpdatePresentationViews(id); + const verificationResult = await verifyPresentation(data.presentation); + const { presentation } = data; const credentials = presentation.verifiableCredential @@ -45,6 +54,7 @@ export default async function Page({ presentation={presentation} page={page} total={credentials.length ?? 1} + verificationResult={verificationResult} /> )} {view === 'Json' && (