fix(create): throw on mark with no counterpart

This commit is contained in:
enes 2024-08-27 17:58:07 +02:00
parent 3a03e3c7e8
commit 624afae851

View File

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