fix onChallengeVerification

This commit is contained in:
plebbitor
2023-04-11 18:12:11 +02:00
parent 47aa173e5e
commit b255311e30
+14 -3
View File
@@ -92,17 +92,20 @@ const Board = () => {
}; };
const onChallengeVerificationRef = useRef();
const onChallengeVerification = (challengeVerification) => { const onChallengeVerification = (challengeVerification) => {
if (challengeVerification.challengeSuccess === true) { if (challengeVerification.challengeSuccess === true) {
setSuccessMessage('challenge success', {publishedCid: challengeVerification.publication.cid}); setSuccessMessage('challenge success', {publishedCid: challengeVerification.publication.cid});
setSelectedThread(challengeVerification.publication.cid);
navigate(`/p/${selectedAddress}/c/${challengeVerification.publication.cid}`); navigate(`/p/${selectedAddress}/c/${challengeVerification.publication.cid}`);
} }
else if (challengeVerification.challengeSuccess === false) { else if (challengeVerification.challengeSuccess === false) {
setErrorMessage('challenge failed', {reason: challengeVerification.reason, errors: challengeVerification.errors}); setErrorMessage('challenge failed', {reason: challengeVerification.reason, errors: challengeVerification.errors});
setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again."); setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again.");
} }
} };
onChallengeVerificationRef.current = onChallengeVerification;
const onChallenge = async (challenges, comment) => { const onChallenge = async (challenges, comment) => {
@@ -133,12 +136,20 @@ const Board = () => {
const [publishCommentOptions, setPublishCommentOptions] = useState({ const [publishCommentOptions, setPublishCommentOptions] = useState({
subplebbitAddress: selectedAddress, subplebbitAddress: selectedAddress,
onChallenge, onChallenge,
onChallengeVerification, onChallengeVerification: onChallengeVerificationRef.current,
onError: (error) => { onError: (error) => {
setErrorMessage(error); setErrorMessage(error);
}, },
}); });
useEffect(() => {
setPublishCommentOptions((prevPublishCommentOptions) => ({
...prevPublishCommentOptions,
subplebbitAddress: selectedAddress,
onChallengeVerification: onChallengeVerificationRef.current,
}));
}, [selectedAddress]);
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();