Files
5chan/src/hooks/useAnonModeRef.js
T

28 lines
856 B
JavaScript
Raw Normal View History

2023-06-17 21:55:20 +02:00
import { useEffect } from "react";
2023-06-27 10:35:21 +02:00
import { useAccount } from "@plebbit/plebbit-react-hooks";
2023-06-17 21:55:20 +02:00
import useAnonModeStore from "./stores/useAnonModeStore";
const useAnonModeRef = (threadCidRef, execute) => {
2023-06-26 22:07:32 +02:00
const account = useAccount();
2023-06-17 21:55:20 +02:00
const { anonymousMode } = useAnonModeStore();
useEffect(() => {
const handleAnonMode = async () => {
2023-06-26 21:55:26 +02:00
let storedSigners = JSON.parse(localStorage.getItem('storedSigners')) || {};
2023-06-17 21:55:20 +02:00
2023-06-27 10:35:21 +02:00
if (!anonymousMode) {
if (execute && storedSigners[threadCidRef]) {
const signerPrivateKey = storedSigners[threadCidRef];
if (account) {
await account.plebbit.createSigner({type: 'ed25519', privateKey: signerPrivateKey});
}
}
2023-06-17 21:55:20 +02:00
}
}
handleAnonMode();
2023-06-26 21:55:26 +02:00
}, [threadCidRef, execute, account, anonymousMode]);
2023-06-17 21:55:20 +02:00
return;
}
export default useAnonModeRef;