Files
5chan/src/hooks/useAnonMode.js
T
2023-06-26 22:07:32 +02:00

30 lines
795 B
JavaScript

import { useEffect } from "react";
import { useAccount } from "@plebbit/plebbit-react-hooks";
import useAnonModeStore from "./stores/useAnonModeStore";
const useAnonMode = (threadCid, execute) => {
const account = useAccount();
const { anonymousMode } = useAnonModeStore();
useEffect(() => {
const handleAnonMode = async () => {
let storedSigners = JSON.parse(localStorage.getItem('storedSigners')) || {};
if (!anonymousMode) {
if (execute && storedSigners[threadCid]) {
const signerPrivateKey = storedSigners[threadCid];
if (account) {
await account.plebbit.createSigner({privateKey: signerPrivateKey});
}
}
}
}
handleAnonMode();
}, [threadCid, execute, account, anonymousMode]);
return;
}
export default useAnonMode;