From ec305c417bcca6d70a24cdae14c1b99be40b0064 Mon Sep 17 00:00:00 2001 From: Eugene Date: Tue, 27 Aug 2024 16:17:34 +0300 Subject: [PATCH] fix: signing order --- src/components/PDFView/PdfMarking.tsx | 6 +- src/pages/sign/index.tsx | 168 +++++++++++++------------- src/utils/sign.ts | 14 ++- 3 files changed, 100 insertions(+), 88 deletions(-) diff --git a/src/components/PDFView/PdfMarking.tsx b/src/components/PDFView/PdfMarking.tsx index 9fff924..be37fe7 100644 --- a/src/components/PDFView/PdfMarking.tsx +++ b/src/components/PDFView/PdfMarking.tsx @@ -24,7 +24,7 @@ interface PdfMarkingProps { meta: Meta | null otherUserMarks: Mark[] setCurrentUserMarks: (currentUserMarks: CurrentUserMark[]) => void - setIsReadyToSign: (isReadyToSign: boolean) => void + setIsMarksCompleted: (isMarksCompleted: boolean) => void setUpdatedMarks: (markToUpdate: Mark) => void } @@ -38,7 +38,7 @@ const PdfMarking = (props: PdfMarkingProps) => { const { files, currentUserMarks, - setIsReadyToSign, + setIsMarksCompleted, setCurrentUserMarks, setUpdatedMarks, handleDownload, @@ -102,7 +102,7 @@ const PdfMarking = (props: PdfMarkingProps) => { ) setCurrentUserMarks(updatedCurrentUserMarks) setSelectedMark(null) - setIsReadyToSign(true) + setIsMarksCompleted(true) setUpdatedMarks(updatedMark.mark) } diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index b8cfe5c..c7abf66 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -41,7 +41,7 @@ import styles from './style.module.scss' import { PdfFile } from '../../types/drawing.ts' import { convertToPdfFile } from '../../utils/pdf.ts' import { CurrentUserMark, Mark } from '../../types/mark.ts' -import { getLastSignersSig } from '../../utils/sign.ts' +import { getLastSignersSig, isFullySigned } from '../../utils/sign.ts' import { filterMarksByPubkey, getCurrentUserMarks, @@ -110,13 +110,13 @@ export const SignPage = () => { const [currentUserMarks, setCurrentUserMarks] = useState( [] ) - const [isReadyToSign, setIsReadyToSign] = useState(false) + const [isMarksCompleted, setIsMarksCompleted] = useState(false) const [otherUserMarks, setOtherUserMarks] = useState([]) useEffect(() => { if (signers.length > 0) { // check if all signers have signed then its fully signed - if (signers.every((signer) => signedBy.includes(signer))) { + if (isFullySigned(signers, signedBy)) { setSignedStatus(SignedStatus.Fully_Signed) } else { for (const signer of signers) { @@ -214,7 +214,7 @@ export const SignPage = () => { const otherUserMarks = findOtherUserMarks(signedMarks, usersPubkey!) setOtherUserMarks(otherUserMarks) setCurrentUserMarks(currentUserMarks) - setIsReadyToSign(isCurrentUserMarksComplete(currentUserMarks)) + setIsMarksCompleted(isCurrentUserMarksComplete(currentUserMarks)) } setSignedBy(Object.keys(meta.docSignatures) as `npub1${string}`[]) @@ -882,90 +882,90 @@ export const SignPage = () => { return } - if (isReadyToSign) { + if (!isMarksCompleted && signedStatus === SignedStatus.User_Is_Next_Signer) { return ( - <> - - {displayInput && ( - <> - - Select sigit file - - - - setSelectedFile(value)} - /> - - - {selectedFile && ( - - - - )} - - )} - - {submittedBy && Object.entries(files).length > 0 && meta && ( - <> - - - {signedStatus === SignedStatus.Fully_Signed && ( - - - - )} - - {signedStatus === SignedStatus.User_Is_Next_Signer && ( - - - - )} - - {isSignerOrCreator && ( - - - - )} - - )} - - + ) } return ( - + <> + + {displayInput && ( + <> + + Select sigit file + + + + setSelectedFile(value)} + /> + + + {selectedFile && ( + + + + )} + + )} + + {submittedBy && Object.entries(files).length > 0 && meta && ( + <> + + + {signedStatus === SignedStatus.Fully_Signed && ( + + + + )} + + {signedStatus === SignedStatus.User_Is_Next_Signer && ( + + + + )} + + {isSignerOrCreator && ( + + + + )} + + )} + + ) } diff --git a/src/utils/sign.ts b/src/utils/sign.ts index 3369c54..ff67e44 100644 --- a/src/utils/sign.ts +++ b/src/utils/sign.ts @@ -31,4 +31,16 @@ const getLastSignersSig = ( } } -export { getLastSignersSig } +/** + * Checks if all signers have signed the sigit + * @param signers - an array of npubs of all signers from the Sigit + * @param signedBy - an array of npubs that have signed it already + */ +const isFullySigned = ( + signers: `npub1${string}`[], + signedBy: `npub1${string}`[] +): boolean => { + return signers.every((signer) => signedBy.includes(signer)) +} + +export { getLastSignersSig, isFullySigned } -- 2.34.1