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

30 lines
795 B
JavaScript
Raw Normal View History

2023-06-16 13:48:40 +02:00
import { useEffect } from "react";
2023-06-26 21:55:26 +02:00
import { useAccount } from "@plebbit/plebbit-react-hooks";
2023-06-16 15:28:03 +02:00
import useAnonModeStore from "./stores/useAnonModeStore";
2023-06-16 13:48:40 +02:00
const useAnonMode = (threadCid, execute) => {
2023-06-26 22:07:32 +02:00
const account = useAccount();
2023-06-16 15:28:03 +02:00
const { anonymousMode } = useAnonModeStore();
2023-06-16 13:48:40 +02:00
2023-06-26 21:55:26 +02:00
useEffect(() => {
const handleAnonMode = async () => {
let storedSigners = JSON.parse(localStorage.getItem('storedSigners')) || {};
2023-06-16 13:48:40 +02:00
2023-06-26 21:55:26 +02:00
if (!anonymousMode) {
if (execute && storedSigners[threadCid]) {
const signerPrivateKey = storedSigners[threadCid];
2023-06-26 22:07:32 +02:00
if (account) {
await account.plebbit.createSigner({privateKey: signerPrivateKey});
}
2023-06-16 13:48:40 +02:00
}
}
2023-06-26 21:55:26 +02:00
}
handleAnonMode();
}, [threadCid, execute, account, anonymousMode]);
2023-06-16 13:48:40 +02:00
return;
}
2023-06-26 21:55:26 +02:00
2023-06-16 13:48:40 +02:00
export default useAnonMode;