display anon mode address immediately upon publishing

This commit is contained in:
Tom (plebeius.eth)
2024-08-30 21:18:39 +02:00
parent 3bc672cbaa
commit 51e3ef8506
5 changed files with 48 additions and 13 deletions
+15 -8
View File
@@ -15,6 +15,7 @@ import styles from './reply-modal.module.css';
import { LinkTypePreviewer } from '../post-form';
import _ from 'lodash';
import useAnonMode from '../../hooks/use-anon-mode';
import useAnonModeStore from '../../stores/use-anon-mode-store';
interface ReplyModalProps {
closeModal: () => void;
@@ -40,6 +41,8 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
const address = comment?.author?.address;
const hasCalledAnonAddressRef = useRef(false);
const { setCurrentAnonSignerAddress } = useAnonModeStore();
const getAnonAddressForReply = useCallback(async () => {
if (anonMode && !hasCalledAnonAddressRef.current) {
hasCalledAnonAddressRef.current = true;
@@ -52,18 +55,22 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s
displayName: displayName || undefined,
},
});
setCurrentAnonSignerAddress(existingSigner.address);
} else {
const newSigner = await getNewSigner();
setPublishReplyOptions({
signer: newSigner,
author: {
address: newSigner.address,
displayName: displayName || undefined,
},
});
if (newSigner) {
setPublishReplyOptions({
signer: newSigner,
author: {
address: newSigner.address,
displayName: displayName || undefined,
},
});
setCurrentAnonSignerAddress(newSigner.address);
}
}
}
}, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, anonMode, displayName]);
}, [address, getExistingSigner, getNewSigner, setPublishReplyOptions, anonMode, displayName, setCurrentAnonSignerAddress]);
const onPublishReply = () => {
const currentContent = textRef.current?.value.slice(contentPrefix.length).trim() || '';