diff --git a/src/components/reply-modal/reply-modal.tsx b/src/components/reply-modal/reply-modal.tsx index 1078774b..a68a154d 100644 --- a/src/components/reply-modal/reply-modal.tsx +++ b/src/components/reply-modal/reply-modal.tsx @@ -47,34 +47,29 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s const comment = useComment({ commentCid: postCid }); const address = comment?.author?.address; - const hasCalledAnonAddressRef = useRef(false); - const getAnonAddressForReply = useCallback(async () => { - if (anonMode && !hasCalledAnonAddressRef.current) { - hasCalledAnonAddressRef.current = true; - const existingSigner = await getExistingSigner(address); - if (existingSigner) { + const existingSigner = await getExistingSigner(address); + if (existingSigner) { + setPublishReplyOptions({ + signer: existingSigner, + author: { + address: existingSigner.address, + displayName: displayName || undefined, + }, + }); + } else { + const newSigner = await getNewSigner(); + if (newSigner) { setPublishReplyOptions({ - signer: existingSigner, + signer: newSigner, author: { - address: existingSigner.address, + address: newSigner.address, displayName: displayName || undefined, }, }); - } else { - const newSigner = await getNewSigner(); - if (newSigner) { - setPublishReplyOptions({ - signer: newSigner, - author: { - address: newSigner.address, - displayName: displayName || undefined, - }, - }); - } } } - }, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, anonMode, displayName]); + }, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, displayName]); const [error, setError] = useState(null); @@ -98,9 +93,25 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s useEffect(() => { if (anonMode) { + setPublishReplyOptions({ + signer: undefined, + author: { + address: undefined, + displayName: displayName || undefined, + }, + }); getAnonAddressForReply(); + } else { + setPublishReplyOptions({ + signer: undefined, + author: { + ...account?.author, + displayName: displayName || account?.author?.displayName, + }, + }); } - }, [anonMode, getAnonAddressForReply]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [anonMode]); useEffect(() => { if (typeof replyIndex === 'number') { diff --git a/src/hooks/use-publish-reply.ts b/src/hooks/use-publish-reply.ts index ed1fda60..2a04bb5e 100644 --- a/src/hooks/use-publish-reply.ts +++ b/src/hooks/use-publish-reply.ts @@ -30,15 +30,17 @@ const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; sub spoiler, }; - const authorOptions = { - displayName: author?.displayName, - address: anonMode ? signer?.address : account?.author?.address, - }; - - baseOptions.author = authorOptions; - if (anonMode) { + baseOptions.author = { + address: signer?.address, + displayName: author?.displayName, + }; baseOptions.signer = signer; + } else { + baseOptions.author = { + ...account?.author, + displayName: author?.displayName || account?.author?.displayName, + }; } return baseOptions;