From 6fe0157efc2fcfdf61882c27cac967de50e1bda6 Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Wed, 7 Aug 2024 16:25:53 +0200 Subject: [PATCH] fix signer when anon mode is off --- src/components/post-form/post-form.tsx | 14 +++++++++----- src/hooks/use-publish-reply.ts | 11 +++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/components/post-form/post-form.tsx b/src/components/post-form/post-form.tsx index a7206323..45baafd1 100644 --- a/src/components/post-form/post-form.tsx +++ b/src/components/post-form/post-form.tsx @@ -28,7 +28,7 @@ import useAnonMode from '../../hooks/use-anon-mode'; type SubmitState = { author: any | undefined; - signer: any | undefined; + signer?: any | undefined; subplebbitAddress: string | undefined; title: string | undefined; content: string | undefined; @@ -61,9 +61,8 @@ const useSubmitStore = create((set) => ({ if (link !== undefined) nextState.link = link || undefined; if (spoiler !== undefined) nextState.spoiler = spoiler || undefined; - nextState.publishCommentOptions = { + const publishCommentOptions: PublishCommentOptions = { author: nextState.author, - signer: nextState.signer, subplebbitAddress: nextState.subplebbitAddress, title: nextState.title, content: nextState.content, @@ -73,10 +72,15 @@ const useSubmitStore = create((set) => ({ onChallengeVerification: alertChallengeVerificationFailed, onError: (error: Error) => { console.error(error); - let errorMessage = error.message; - alert(errorMessage); + alert(error.message); }, }; + + if (nextState.signer) { + publishCommentOptions.signer = nextState.signer; + } + + nextState.publishCommentOptions = publishCommentOptions; return nextState; }), resetSubmitStore: () => diff --git a/src/hooks/use-publish-reply.ts b/src/hooks/use-publish-reply.ts index d8cf2d04..d2d90321 100644 --- a/src/hooks/use-publish-reply.ts +++ b/src/hooks/use-publish-reply.ts @@ -3,6 +3,7 @@ import { ChallengeVerification, Comment, PublishCommentOptions, usePublishCommen import { create } from 'zustand'; import { alertChallengeVerificationFailed } from '../lib/utils/challenge-utils'; import useChallengesStore from '../stores/use-challenges-store'; +import useAnonMode from './use-anon-mode'; type SetReplyStoreData = { subplebbitAddress: string; @@ -10,7 +11,7 @@ type SetReplyStoreData = { author: any | undefined; content: string | undefined; link: string | undefined; - signer: any | undefined; + signer?: any | undefined; spoiler: boolean | undefined; }; @@ -41,7 +42,7 @@ const useReplyStore = create((set) => ({ subplebbitAddress, parentCid, author, - signer, + ...(data.signer ? { signer: data.signer } : {}), content, link, spoiler, @@ -86,6 +87,8 @@ const useReply = ({ cid, subplebbitAddress }: { cid: string; subplebbitAddress: publishCommentOptions: state.publishCommentOptions[parentCid], })); + const { anonMode } = useAnonMode(); + const setReplyStore = useReplyStore((state) => state.setReplyStore); const resetReplyStore = useReplyStore((state) => state.resetReplyStore); @@ -95,14 +98,14 @@ const useReply = ({ cid, subplebbitAddress }: { cid: string; subplebbitAddress: subplebbitAddress, parentCid, author, - signer, content, link, spoiler, + ...(anonMode ? { signer } : {}), ...options, }); }, - [subplebbitAddress, parentCid, author, signer, content, link, spoiler, setReplyStore], + [subplebbitAddress, parentCid, author, signer, content, link, spoiler, setReplyStore, anonMode], ); const resetPublishReplyOptions = useCallback(() => resetReplyStore(parentCid), [parentCid, resetReplyStore]);