feat(opentimestamps): updates the flow and adds notifications
This commit is contained in:
parent
edeb22fb37
commit
2b630c94b6
@ -9,8 +9,8 @@ import {
|
||||
DocSignatureEvent,
|
||||
Meta,
|
||||
SignedEvent,
|
||||
Timestamp,
|
||||
TimestampUpgradeVerifyResponse
|
||||
OpenTimestamp,
|
||||
OpenTimestampUpgradeVerifyResponse
|
||||
} from '../../types'
|
||||
import {
|
||||
decryptArrayBuffer,
|
||||
@ -43,7 +43,7 @@ import { saveAs } from 'file-saver'
|
||||
import { Container } from '../../components/Container'
|
||||
import { useSigitMeta } from '../../hooks/useSigitMeta.tsx'
|
||||
import { StickySideColumns } from '../../layouts/StickySideColumns.tsx'
|
||||
import { UsersDetails } from '../../components/UsersDetails.tsx/index.tsx'
|
||||
import { UsersDetails } from '../../components/UsersDetails.tsx'
|
||||
import FileList from '../../components/FileList'
|
||||
import { CurrentUserFile } from '../../types/file.ts'
|
||||
import { Mark } from '../../types/mark.ts'
|
||||
@ -57,11 +57,7 @@ import {
|
||||
faFile,
|
||||
faFileDownload
|
||||
} from '@fortawesome/free-solid-svg-icons'
|
||||
import {
|
||||
upgradeAndVerifyTimestamp,
|
||||
upgradeTimestamps,
|
||||
verifyTimestamps
|
||||
} from '../../utils/opentimestamps.ts'
|
||||
import { upgradeAndVerifyTimestamp } from '../../utils/opentimestamps.ts'
|
||||
import _ from 'lodash'
|
||||
|
||||
interface PdfViewProps {
|
||||
@ -207,7 +203,7 @@ export const VerifyPage = () => {
|
||||
}>({})
|
||||
|
||||
const signTimestampEvent = async (signerContent: {
|
||||
timestamps: Timestamp[]
|
||||
timestamps: OpenTimestamp[]
|
||||
}): Promise<SignedEvent | null> => {
|
||||
return await signEventForMetaFile(
|
||||
JSON.stringify(signerContent),
|
||||
@ -224,37 +220,56 @@ 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.every((t) => !!t.verification)) {
|
||||
toast.success('All of your timestamps are fully verified on Bitcoin.')
|
||||
return
|
||||
}
|
||||
const upgradeT = async (timestamps: Timestamp[]) => {
|
||||
const upgradeT = async (timestamps: OpenTimestamp[]) => {
|
||||
try {
|
||||
setLoadingSpinnerDesc('Upgrading and verifying your timestamps.')
|
||||
const verifiedResults = await Promise.all(
|
||||
timestamps.map(upgradeAndVerifyTimestamp)
|
||||
)
|
||||
|
||||
/**
|
||||
* Checks if timestamp verification has been achieved for the first time.
|
||||
* Note that the upgrade flag is separate from verification. It is possible for a timestamp
|
||||
* to not be upgraded, but to be verified for the first time.
|
||||
* @param upgradedTimestamp
|
||||
* @param timestamps
|
||||
*/
|
||||
const isNewlyVerified = (
|
||||
upgradedTimestamp: OpenTimestampUpgradeVerifyResponse,
|
||||
timestamps: OpenTimestamp[]
|
||||
) => {
|
||||
if (!upgradedTimestamp.verified) return false
|
||||
const oldT = timestamps.find(
|
||||
(t) => t.nostrId === upgradedTimestamp.timestamp.nostrId
|
||||
)
|
||||
if (!oldT) return false
|
||||
if (!oldT.verification && upgradedTimestamp.verified) return true
|
||||
}
|
||||
|
||||
const upgradedTimestamps = verifiedResults
|
||||
.filter((t) => t.upgraded || isNewlyVerified(t, timestamps))
|
||||
.map((t) => {
|
||||
const timestamp = t.value
|
||||
const timestamp = t.timestamp
|
||||
if (t.verified) {
|
||||
timestamp.verification = t.verification
|
||||
}
|
||||
return timestamp
|
||||
})
|
||||
|
||||
const isNewlyVerified = (
|
||||
upgradedTimestamp: TimestampUpgradeVerifyResponse,
|
||||
timestamps: Timestamp[]
|
||||
) => {
|
||||
if (!upgradedTimestamp.verified) return false
|
||||
const oldT = timestamps.find(
|
||||
(t) => t.nostrId === upgradedTimestamp.value.nostrId
|
||||
)
|
||||
if (!oldT) return false
|
||||
if (!oldT.verification && upgradedTimestamp.verified) return true
|
||||
if (upgradedTimestamps.length === 0) {
|
||||
toast.success('No further timestamp upgrades found.')
|
||||
return
|
||||
}
|
||||
|
||||
setLoadingSpinnerDesc('Signing a timestamp upgrade event.')
|
||||
|
||||
const signedEvent = await signTimestampEvent({
|
||||
timestamps: upgradedTimestamps
|
||||
})
|
||||
@ -298,8 +313,15 @@ export const VerifyPage = () => {
|
||||
|
||||
await Promise.all(promises)
|
||||
|
||||
setTimestamps(finalTimestamps)
|
||||
toast.success('Timestamp updates have been sent successfully.')
|
||||
|
||||
setMeta(meta)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
toast.error(
|
||||
'There was an error upgrading or verifying your timestamps!'
|
||||
)
|
||||
}
|
||||
}
|
||||
upgradeT(timestamps)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user