Skip to content

Commit

Permalink
fix: resolve rerender issue
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 committed Apr 24, 2024
1 parent 411a30d commit eb639ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<VerificationResult>;
}) => {
console.log('FormattedView');
const t = useTranslations('FormattedView');

const router = useRouter();
Expand All @@ -69,29 +46,11 @@ export const FormattedView = async ({
const [verificationInfoModalOpen, setVerificationInfoModalOpen] =
useState(false);

const [verificationResult, setVerificationResult] =
useState<VerificationResult | null>(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 (
<>
<div className="dark:bg-navy-blue-800 relative h-full w-full rounded-3xl bg-white shadow-lg">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -45,6 +54,7 @@ export default async function Page({
presentation={presentation}
page={page}
total={credentials.length ?? 1}
verificationResult={verificationResult}
/>
)}
{view === 'Json' && (
Expand Down

0 comments on commit eb639ea

Please sign in to comment.