From 897daaa1fa57a587b5562fd9c94526dd22485b65 Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 10 Oct 2024 13:56:08 +0200 Subject: [PATCH 1/6] feat: handle root _@ users on add counterpart --- src/pages/create/index.tsx | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 90d359b..3374a08 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -246,17 +246,22 @@ export const CreatePage = () => { const input = userInput.toLowerCase() if (input.startsWith('npub')) { - const pubkey = npubToHex(input) - if (pubkey) { - addUser(pubkey) - setUserInput('') - } else { - setError('Provided npub is not valid. Please enter correct npub.') - } - return + return handleAddNpubUser(input) } if (input.includes('@')) { + return await handleAddNip05User(input) + } + + // If the user enters the domain (w/o @) assume it's the "root" and append _@ + // https://github.com/nostr-protocol/nips/blob/master/05.md#showing-just-the-domain-as-an-identifier + if (input.includes('.')) { + return await handleAddNip05User(`_@${input}`) + } + + setError('Invalid input! Make sure to provide correct npub or nip05.') + + async function handleAddNip05User(input: string) { setIsLoading(true) setLoadingSpinnerDesc('Querying for nip05') const nip05Profile = await queryNip05(input) @@ -279,7 +284,16 @@ export const CreatePage = () => { return } - setError('Invalid input! Make sure to provide correct npub or nip05.') + function handleAddNpubUser(input: string) { + const pubkey = npubToHex(input) + if (pubkey) { + addUser(pubkey) + setUserInput('') + } else { + setError('Provided npub is not valid. Please enter correct npub.') + } + return + } } const handleUserRoleChange = (role: UserRole, pubkey: string) => { From c3dacbe1114cdcc408a4dde3019a31c1570afa3e Mon Sep 17 00:00:00 2001 From: enes Date: Fri, 11 Oct 2024 15:05:28 +0200 Subject: [PATCH 2/6] fix: add mark label --- src/components/MarkFormField/index.tsx | 10 ++++------ src/utils/const.ts | 5 ----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/components/MarkFormField/index.tsx b/src/components/MarkFormField/index.tsx index 02f34cc..9a14989 100644 --- a/src/components/MarkFormField/index.tsx +++ b/src/components/MarkFormField/index.tsx @@ -1,9 +1,8 @@ import { CurrentUserMark } from '../../types/mark.ts' import styles from './style.module.scss' - -import { MARK_TYPE_TRANSLATION } from '../../utils/const.ts' import { findNextIncompleteCurrentUserMark, + getToolboxLabelByMarkType, isCurrentUserMarksComplete, isCurrentValueLast } from '../../utils' @@ -53,6 +52,7 @@ const MarkFormField = ({ : handleCurrentUserMarkChange(findNext()!) } const toggleActions = () => setDisplayActions(!displayActions) + const markLabel = getToolboxLabelByMarkType(selectedMark.mark.type) return (
@@ -78,16 +78,14 @@ const MarkFormField = ({
-

Add your signature

+

Add {markLabel}

handleFormSubmit(e)}> diff --git a/src/utils/const.ts b/src/utils/const.ts index 8e53a46..38f138e 100644 --- a/src/utils/const.ts +++ b/src/utils/const.ts @@ -1,9 +1,4 @@ -import { MarkType } from '../types/drawing.ts' - export const EMPTY: string = '' -export const MARK_TYPE_TRANSLATION: { [key: string]: string } = { - [MarkType.FULLNAME.valueOf()]: 'Full Name' -} export const ARRAY_BUFFER = 'arraybuffer' export const DEFLATE = 'DEFLATE' From 9dd190d65b18429ded79213bdfdf91a88aac0062 Mon Sep 17 00:00:00 2001 From: enes Date: Fri, 11 Oct 2024 16:16:59 +0200 Subject: [PATCH 3/6] fix: add files and marked to sign page exports Skip marked if the file contains no marks --- src/pages/sign/index.tsx | 14 ++------------ src/utils/file.ts | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index dbbcd98..55276de 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -771,14 +771,9 @@ export const SignPage = () => { 2 ) - const zip = new JSZip() - + const zip = await getZipWithFiles(meta, files) zip.file('meta.json', stringifiedMeta) - for (const [fileName, file] of Object.entries(files)) { - zip.file(`files/${fileName}`, await file.arrayBuffer()) - } - const arrayBuffer = await zip .generateAsync({ type: 'arraybuffer', @@ -807,16 +802,11 @@ export const SignPage = () => { const handleEncryptedExport = async () => { if (Object.entries(files).length === 0 || !meta) return - const zip = new JSZip() - const stringifiedMeta = JSON.stringify(meta, null, 2) + const zip = await getZipWithFiles(meta, files) zip.file('meta.json', stringifiedMeta) - for (const [fileName, file] of Object.entries(files)) { - zip.file(`files/${fileName}`, await file.arrayBuffer()) - } - const arrayBuffer = await zip .generateAsync({ type: 'arraybuffer', diff --git a/src/utils/file.ts b/src/utils/file.ts index 84b30fc..c08d5e7 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -20,7 +20,7 @@ export const getZipWithFiles = async ( for (const [fileName, file] of Object.entries(files)) { // Handle PDF Files, add marks - if (file.isPdf) { + if (file.isPdf && fileName in marksByFileNamePage) { const blob = await addMarks(file, marksByFileNamePage[fileName]) zip.file(`marked/${fileName}`, blob) } From cc382f072643918e83c399374bfe5ff77af794e4 Mon Sep 17 00:00:00 2001 From: enes Date: Fri, 11 Oct 2024 16:43:55 +0200 Subject: [PATCH 4/6] fix: show error if decrypt fails --- src/pages/sign/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index 55276de..dd31938 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -536,7 +536,11 @@ export const SignPage = () => { setIsLoading(true) const arrayBuffer = await decrypt(selectedFile) - if (!arrayBuffer) return + if (!arrayBuffer) { + setIsLoading(false) + toast.error('Error decrypting file') + return + } handleDecryptedArrayBuffer(arrayBuffer) } From 25764c7ab41708f03e4c671857be519020bee46f Mon Sep 17 00:00:00 2001 From: enes Date: Sat, 12 Oct 2024 11:52:43 +0200 Subject: [PATCH 5/6] fix: processing events Partially revert to before 23a04faad89ae3138008f4b1b9a112bf944f279b --- src/layouts/Main.tsx | 18 ++++++++++++++---- src/utils/nostr.ts | 5 ++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/layouts/Main.tsx b/src/layouts/Main.tsx index 9cdc549..0fd5526 100644 --- a/src/layouts/Main.tsx +++ b/src/layouts/Main.tsx @@ -39,6 +39,7 @@ export const MainLayout = () => { const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState(`Loading App`) const isLoggedIn = useAppSelector((state) => state.auth?.loggedIn) const authState = useAppSelector((state) => state.auth) + const usersAppData = useAppSelector((state) => state.userAppData) // Ref to track if `subscribeForSigits` has been called const hasSubscribed = useRef(false) @@ -174,12 +175,10 @@ export const MainLayout = () => { }, [dispatch]) /** - * When authState change user logged in / or app reloaded - * we set robohash avatar in the global state based on user npub - * so that avatar will be consistent across the app when kind 0 is empty + * Subscribe for the sigits */ useEffect(() => { - if (authState && isLoggedIn) { + if (authState && isLoggedIn && usersAppData) { const pubkey = authState.usersPubkey || authState.keyPair?.public if (pubkey && !hasSubscribed.current) { @@ -190,6 +189,17 @@ export const MainLayout = () => { // Mark `subscribeForSigits` as called hasSubscribed.current = true } + } + }, [authState, isLoggedIn, usersAppData]) + + /** + * When authState change user logged in / or app reloaded + * we set robohash avatar in the global state based on user npub + * so that avatar will be consistent across the app when kind 0 is empty + */ + useEffect(() => { + if (authState && isLoggedIn) { + const pubkey = authState.usersPubkey || authState.keyPair?.public if (pubkey) { dispatch(setUserRobotImage(getRoboHashPicture(pubkey))) diff --git a/src/utils/nostr.ts b/src/utils/nostr.ts index fb96186..ec8c97e 100644 --- a/src/utils/nostr.ts +++ b/src/utils/nostr.ts @@ -875,7 +875,10 @@ export const subscribeForSigits = async (pubkey: string) => { } const processReceivedEvent = async (event: Event, difficulty: number = 5) => { - const processedEvents = store.getState().userAppData?.processedGiftWraps || [] + const processedEvents = store.getState().userAppData?.processedGiftWraps + + // Abort processing if userAppData is undefined + if (!processedEvents) return if (processedEvents.includes(event.id)) return From 1d1986f0829f4c1ca183b017150ecfdbaa96a86c Mon Sep 17 00:00:00 2001 From: enes Date: Sat, 12 Oct 2024 12:05:55 +0200 Subject: [PATCH 6/6] fix: clear hasSubscribed after the logout --- src/layouts/Main.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/layouts/Main.tsx b/src/layouts/Main.tsx index 0fd5526..19ac4d9 100644 --- a/src/layouts/Main.tsx +++ b/src/layouts/Main.tsx @@ -124,6 +124,9 @@ export const MainLayout = () => { if (opts.type === 'login' || opts.type === 'signup') { dispatch(updateNostrLoginAuthMethod(opts.method)) login() + } else if (opts.type === 'logout') { + // Clear `subscribeForSigits` as called after the logout + hasSubscribed.current = false } }