fix(reply modal): changing anon mode before publishing reply didn't work

This commit is contained in:
Tom (plebeius.eth)
2025-01-29 13:09:38 +01:00
parent 48a8046486
commit 2a20716212
2 changed files with 41 additions and 28 deletions
+18 -7
View File
@@ -47,11 +47,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
const comment = useComment({ commentCid: postCid }); const comment = useComment({ commentCid: postCid });
const address = comment?.author?.address; const address = comment?.author?.address;
const hasCalledAnonAddressRef = useRef(false);
const getAnonAddressForReply = useCallback(async () => { const getAnonAddressForReply = useCallback(async () => {
if (anonMode && !hasCalledAnonAddressRef.current) {
hasCalledAnonAddressRef.current = true;
const existingSigner = await getExistingSigner(address); const existingSigner = await getExistingSigner(address);
if (existingSigner) { if (existingSigner) {
setPublishReplyOptions({ setPublishReplyOptions({
@@ -73,8 +69,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
}); });
} }
} }
} }, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, displayName]);
}, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, anonMode, displayName]);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
@@ -98,9 +93,25 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
useEffect(() => { useEffect(() => {
if (anonMode) { if (anonMode) {
setPublishReplyOptions({
signer: undefined,
author: {
address: undefined,
displayName: displayName || undefined,
},
});
getAnonAddressForReply(); 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(() => { useEffect(() => {
if (typeof replyIndex === 'number') { if (typeof replyIndex === 'number') {
+9 -7
View File
@@ -30,15 +30,17 @@ const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; sub
spoiler, spoiler,
}; };
const authorOptions = {
displayName: author?.displayName,
address: anonMode ? signer?.address : account?.author?.address,
};
baseOptions.author = authorOptions;
if (anonMode) { if (anonMode) {
baseOptions.author = {
address: signer?.address,
displayName: author?.displayName,
};
baseOptions.signer = signer; baseOptions.signer = signer;
} else {
baseOptions.author = {
...account?.author,
displayName: author?.displayName || account?.author?.displayName,
};
} }
return baseOptions; return baseOptions;