From b255311e304773f0b97f09c36442de1f4491596c Mon Sep 17 00:00:00 2001 From: plebbitor Date: Tue, 11 Apr 2023 18:12:11 +0200 Subject: [PATCH] fix onChallengeVerification --- src/components/views/Board.jsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 633a8e04..e80cc66e 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -92,17 +92,20 @@ const Board = () => { }; + const onChallengeVerificationRef = useRef(); + const onChallengeVerification = (challengeVerification) => { if (challengeVerification.challengeSuccess === true) { setSuccessMessage('challenge success', {publishedCid: challengeVerification.publication.cid}); - setSelectedThread(challengeVerification.publication.cid); navigate(`/p/${selectedAddress}/c/${challengeVerification.publication.cid}`); } else if (challengeVerification.challengeSuccess === false) { setErrorMessage('challenge failed', {reason: challengeVerification.reason, errors: challengeVerification.errors}); setErrorMessage("Error: You seem to have mistyped the CAPTCHA. Please try again."); } - } + }; + + onChallengeVerificationRef.current = onChallengeVerification; const onChallenge = async (challenges, comment) => { @@ -133,12 +136,20 @@ const Board = () => { const [publishCommentOptions, setPublishCommentOptions] = useState({ subplebbitAddress: selectedAddress, onChallenge, - onChallengeVerification, + onChallengeVerification: onChallengeVerificationRef.current, onError: (error) => { setErrorMessage(error); }, }); + useEffect(() => { + setPublishCommentOptions((prevPublishCommentOptions) => ({ + ...prevPublishCommentOptions, + subplebbitAddress: selectedAddress, + onChallengeVerification: onChallengeVerificationRef.current, + })); + }, [selectedAddress]); + const handleSubmit = async (event) => { event.preventDefault();