diff --git a/src/pages/verify/index.tsx b/src/pages/verify/index.tsx index 921a181..1c19968 100644 --- a/src/pages/verify/index.tsx +++ b/src/pages/verify/index.tsx @@ -220,19 +220,33 @@ export const VerifyPage = () => { }, [currentFileHashes, fileHashes, files]) useEffect(() => { - console.log('timestamps: ', timestamps) - if (timestamps && timestamps.length > 0) { - console.log(timestamps.every((t) => !!t.verification)) + if ( + timestamps && + timestamps.length > 0 && + usersPubkey && + submittedBy && + parsedSignatureEvents + ) { if (timestamps.every((t) => !!t.verification)) { - toast.success('All of your timestamps are fully verified on Bitcoin.') + toast.success('All timestamps are fully verified.') return } const upgradeT = async (timestamps: OpenTimestamp[]) => { try { - setLoadingSpinnerDesc('Upgrading and verifying your timestamps.') - const verifiedResults = await Promise.all( - timestamps.map(upgradeAndVerifyTimestamp) - ) + setLoadingSpinnerDesc('Upgrading your timestamps.') + + const findCreatorTimestamp = (timestamps: OpenTimestamp[]) => { + if (usersPubkey === submittedBy) { + return timestamps[0] + } + } + + const findSignerTimestamp = (timestamps: OpenTimestamp[]) => { + const parsedEvent = parsedSignatureEvents[hexToNpub(usersPubkey)] + if (parsedEvent?.id) { + return timestamps.find((t) => t.nostrId === parsedEvent.id) + } + } /** * Checks if timestamp verification has been achieved for the first time. @@ -253,18 +267,38 @@ export const VerifyPage = () => { if (!oldT.verification && upgradedTimestamp.verified) return true } - const upgradedTimestamps = verifiedResults - .filter((t) => t.upgraded || isNewlyVerified(t, timestamps)) + const userTimestamps: OpenTimestamp[] = [] + + const creatorTimestamp = findCreatorTimestamp(timestamps) + if (creatorTimestamp) { + userTimestamps.push(creatorTimestamp) + } + + const signerTimestamp = findSignerTimestamp(timestamps) + if (signerTimestamp) { + userTimestamps.push(signerTimestamp) + } + + if (userTimestamps.every((t) => !!t.verification)) { + console.log('user timestamps are verified') + return + } + + const upgradedUserTimestamps = await Promise.all( + userTimestamps.map(upgradeAndVerifyTimestamp) + ) + + const upgradedTimestamps = upgradedUserTimestamps + .filter((t) => t.upgraded || isNewlyVerified(t, userTimestamps)) .map((t) => { - const timestamp = t.timestamp + const timestamp: OpenTimestamp = { ...t.timestamp } if (t.verified) { timestamp.verification = t.verification } return timestamp }) - if (upgradedTimestamps.length === 0) { - toast.success('No timestamp upgrades found.') + if (upgradedUserTimestamps.length > 0) { return } @@ -325,10 +359,9 @@ export const VerifyPage = () => { } upgradeT(timestamps) } - }, [timestamps]) + }, [timestamps, submittedBy, parsedSignatureEvents]) useEffect(() => { - console.log('this runs') if (metaInNavState && encryptionKey) { const processSigit = async () => { setIsLoading(true) diff --git a/src/utils/opentimestamps.ts b/src/utils/opentimestamps.ts index bda5544..c6d3b44 100644 --- a/src/utils/opentimestamps.ts +++ b/src/utils/opentimestamps.ts @@ -41,7 +41,7 @@ export const upgradeAndVerifyTimestamp = async ( * The upgraded flag indicates if an upgrade has been performed. * @param t - timestamp */ -const upgrade = async ( +export const upgrade = async ( t: OpenTimestamp ): Promise => { console.log('timestamp: ', t)