fix(create): throw on mark with no counterpart

This commit is contained in:
enes 2024-08-27 17:58:07 +02:00
parent e854dca2e1
commit 2ea9afb3a3

View File

@ -514,6 +514,9 @@ export const CreatePage = () => {
return (
file.pages?.flatMap((page, index) => {
return page.drawnFields.map((drawnField) => {
if (!drawnField.counterpart) {
throw new Error('Missing counterpart')
}
return {
type: drawnField.type,
location: {
@ -670,6 +673,7 @@ export const CreatePage = () => {
}
const generateCreateSignature = async (
markConfig: Mark[],
fileHashes: {
[key: string]: string
},
@ -677,7 +681,6 @@ export const CreatePage = () => {
) => {
const signers = users.filter((user) => user.role === UserRole.signer)
const viewers = users.filter((user) => user.role === UserRole.viewer)
const markConfig = createMarks(fileHashes)
const content: CreateSignatureEventContent = {
signers: signers.map((signer) => hexToNpub(signer.pubkey)),
@ -721,6 +724,7 @@ export const CreatePage = () => {
}
const handleCreate = async () => {
try {
if (!validateInputs()) return
setIsLoading(true)
@ -748,6 +752,8 @@ export const CreatePage = () => {
encryptionKey
)
const markConfig = createMarks(fileHashes)
setLoadingSpinnerDesc('Uploading files.zip to file storage')
const fileUrl = await uploadFile(encryptedArrayBuffer)
if (!fileUrl) {
@ -756,7 +762,11 @@ export const CreatePage = () => {
}
setLoadingSpinnerDesc('Generating create signature')
const createSignature = await generateCreateSignature(fileHashes, fileUrl)
const createSignature = await generateCreateSignature(
markConfig,
fileHashes,
fileUrl
)
if (!createSignature) {
setIsLoading(false)
return
@ -810,8 +820,14 @@ export const CreatePage = () => {
zip.file(`files/${file.name}`, file)
})
const markConfig = createMarks(fileHashes)
setLoadingSpinnerDesc('Generating create signature')
const createSignature = await generateCreateSignature(fileHashes, '')
const createSignature = await generateCreateSignature(
markConfig,
fileHashes,
''
)
if (!createSignature) {
setIsLoading(false)
return
@ -847,6 +863,14 @@ export const CreatePage = () => {
await handleOfflineFlow(encryptedArrayBuffer, encryptionKey)
}
} catch (error) {
if (error instanceof Error) {
toast.error(error.message)
}
console.error(error)
} finally {
setIsLoading(false)
}
}
const onDrawFieldsChange = (sigitFiles: SigitFile[]) => {