refactor: remove broken anon mode feature

- delete the anon mode hook/store and stop wiring publish flows through alternate signers
  - strip the settings UI, avatar warning, reply indicators, and FAQ text that referenced the toggle
  - drop the anon mode translation keys via scripts/update-translations.js
This commit is contained in:
plebeius
2025-11-25 13:13:38 +01:00
parent f6cf6ec4eb
commit f037a669c0
51 changed files with 26 additions and 521 deletions
-52
View File
@@ -1,52 +0,0 @@
import { useAccount } from '@plebbit/plebbit-react-hooks';
import useAnonModeStore from '../stores/use-anon-mode-store';
import { useCallback } from 'react';
const useAnonMode = (postCid?: string) => {
const { anonMode, getThreadSigner, setThreadSigner, setAddressSigner, getAddressSigner } = useAnonModeStore((state) => ({
anonMode: state.anonMode,
getThreadSigner: state.getThreadSigner,
setThreadSigner: state.setThreadSigner,
setAddressSigner: state.setAddressSigner,
getAddressSigner: state.getAddressSigner,
}));
const account = useAccount();
const getNewSigner = useCallback(async () => {
if (anonMode) {
if (postCid) {
const existingSigner = getThreadSigner(postCid);
if (existingSigner) {
return existingSigner;
}
}
try {
const signer = await account?.plebbit.createSigner();
if (signer) {
if (postCid) {
setThreadSigner(postCid, signer);
} else {
setAddressSigner(signer);
}
}
return signer;
} catch (error) {
console.error('Failed to create anonymous signer:', error);
}
}
return null;
}, [anonMode, postCid, account, getThreadSigner, setThreadSigner, setAddressSigner]);
const getExistingSigner = useCallback(
(address: string) => {
const signer = getAddressSigner(address);
return signer;
},
[getAddressSigner],
);
return { anonMode, getNewSigner, getExistingSigner };
};
export default useAnonMode;
+2 -14
View File
@@ -1,8 +1,6 @@
import { useMemo } from 'react';
import { useAccount } from '@plebbit/plebbit-react-hooks';
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
import useAnonModeStore from '../stores/use-anon-mode-store';
import useAnonMode from './use-anon-mode';
interface AuthorPrivilegesProps {
commentAuthorAddress: string;
@@ -15,26 +13,16 @@ const useAuthorPrivileges = ({ commentAuthorAddress, subplebbitAddress, postCid
const accountAuthorAddress = account?.author?.address;
const subplebbit = useSubplebbitsStore((state) => state.subplebbits[subplebbitAddress]);
const { roles } = subplebbit || {};
const { getAddressSigner, getThreadSigner } = useAnonModeStore();
const { anonMode } = useAnonMode(postCid);
const { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole } = useMemo(() => {
const commentAuthorRole = roles?.[commentAuthorAddress]?.role;
const isCommentAuthorMod = commentAuthorRole === 'admin' || commentAuthorRole === 'owner' || commentAuthorRole === 'moderator';
const accountAuthorRole = roles?.[accountAuthorAddress]?.role;
const isAccountMod = accountAuthorRole === 'admin' || accountAuthorRole === 'owner' || accountAuthorRole === 'moderator';
let isAccountCommentAuthor = postCid && accountAuthorAddress === commentAuthorAddress;
if (!isAccountCommentAuthor && anonMode) {
const addressSigner = getAddressSigner(commentAuthorAddress);
const threadSigner = postCid ? getThreadSigner(postCid) : null;
isAccountCommentAuthor = (addressSigner && addressSigner.address === commentAuthorAddress) || (threadSigner && threadSigner.address === commentAuthorAddress);
}
const isAccountCommentAuthor = !!postCid && accountAuthorAddress === commentAuthorAddress;
return { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole };
}, [roles, commentAuthorAddress, accountAuthorAddress, anonMode, getAddressSigner, getThreadSigner, postCid]);
}, [roles, commentAuthorAddress, accountAuthorAddress, postCid]);
return { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole };
};
+6 -17
View File
@@ -1,15 +1,12 @@
import { useCallback } from 'react';
import { Comment, useAccount, usePublishComment } from '@plebbit/plebbit-react-hooks';
import useAnonMode from './use-anon-mode';
import usePublishPostStore from '../stores/use-publish-post-store';
const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) => {
const account = useAccount();
const { anonMode } = useAnonMode();
const { author, signer, title, content, link, spoiler, publishCommentOptions } = usePublishPostStore((state) => ({
const { author, title, content, link, spoiler, publishCommentOptions } = usePublishPostStore((state) => ({
author: state.author,
signer: state.signer,
title: state.title || undefined,
content: state.content || undefined,
link: state.link || undefined,
@@ -29,21 +26,13 @@ const usePublishPost = ({ subplebbitAddress }: { subplebbitAddress?: string }) =
spoiler,
};
if (anonMode) {
baseOptions.author = {
address: signer?.address,
displayName: author?.displayName,
};
baseOptions.signer = signer;
} else {
baseOptions.author = {
...account?.author,
displayName: author?.displayName || account?.author?.displayName,
};
}
baseOptions.author = {
...account?.author,
displayName: author?.displayName || account?.author?.displayName,
};
return baseOptions;
}, [anonMode, author, content, link, signer, spoiler, subplebbitAddress, title, account]);
}, [author, content, link, spoiler, subplebbitAddress, title, account]);
const setPublishPostOptions = useCallback(
(options: Partial<Comment>) => {
+6 -17
View File
@@ -1,16 +1,13 @@
import { useCallback } from 'react';
import { Comment, useAccount, usePublishComment } from '@plebbit/plebbit-react-hooks';
import useAnonMode from './use-anon-mode';
import usePublishReplyStore from '../stores/use-publish-reply-store';
const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; subplebbitAddress: string; postCid?: string }) => {
const parentCid = cid;
const account = useAccount();
const { anonMode } = useAnonMode(postCid);
const { author, signer, content, link, spoiler, publishCommentOptions } = usePublishReplyStore((state) => ({
const { author, content, link, spoiler, publishCommentOptions } = usePublishReplyStore((state) => ({
author: state.author[parentCid],
signer: state.signer[parentCid] || undefined,
content: state.content[parentCid] || undefined,
link: state.link[parentCid] || undefined,
spoiler: state.spoiler[parentCid] || false,
@@ -30,21 +27,13 @@ const usePublishReply = ({ cid, subplebbitAddress, postCid }: { cid: string; sub
spoiler,
};
if (anonMode) {
baseOptions.author = {
address: signer?.address,
displayName: author?.displayName,
};
baseOptions.signer = signer;
} else {
baseOptions.author = {
...account?.author,
displayName: author?.displayName || account?.author?.displayName,
};
}
baseOptions.author = {
...account?.author,
displayName: author?.displayName || account?.author?.displayName,
};
return baseOptions;
}, [anonMode, author, content, link, parentCid, postCid, signer, spoiler, subplebbitAddress, account]);
}, [author, content, link, parentCid, postCid, spoiler, subplebbitAddress, account]);
const setPublishReplyOptions = useCallback(
(options: Partial<Comment>) => {