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

29 lines
861 B
JavaScript
Raw Normal View History

2023-09-16 21:40:23 +02:00
import { useEffect } from 'react';
import { useAccount } from '@plebbit/plebbit-react-hooks';
import useAnonModeStore from './stores/useAnonModeStore';
2023-06-17 21:55:20 +02:00
const useAnonModeRef = (threadCidRef, execute) => {
2023-09-23 10:30:48 +02:00
const account = useAccount();
const { anonymousMode } = useAnonModeStore();
2023-06-17 21:55:20 +02:00
2023-09-23 10:30:48 +02:00
useEffect(() => {
const handleAnonMode = async () => {
let storedSigners = JSON.parse(localStorage.getItem('storedSigners')) || {};
2023-06-17 21:55:20 +02:00
2023-09-23 10:30:48 +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
2023-09-23 10:30:48 +02:00
handleAnonMode();
}, [threadCidRef, execute, account, anonymousMode]);
2023-06-17 21:55:20 +02:00
2023-09-23 10:30:48 +02:00
return;
2023-09-16 21:40:23 +02:00
};
export default useAnonModeRef;