diff --git a/web/src/components/playing/BatterViewMobile.tsx b/web/src/components/playing/BatterViewMobile.tsx index 751138ce..f627c5d1 100644 --- a/web/src/components/playing/BatterViewMobile.tsx +++ b/web/src/components/playing/BatterViewMobile.tsx @@ -1,4 +1,4 @@ -import { useContext } from "react"; +import { useContext, useEffect, useState } from "react"; import { useMutation, useQueryClient } from "react-query"; import { useGameContext } from "../../contexts/GameContext"; @@ -13,6 +13,8 @@ import PlayerView from "./PlayerView"; const FullcountABI = FullcountABIImported as unknown as AbiItem[]; const BatterViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) => { + const [isCommitted, setIsCommitted] = useState(false); + const [isRevealed, setIsRevealed] = useState(false); const web3ctx = useContext(Web3Context); const { contractAddress } = useGameContext(); const gameContract = new web3ctx.web3.eth.Contract(FullcountABI) as any; @@ -36,6 +38,7 @@ const BatterViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) = }, { onSuccess: () => { + setIsCommitted(true); queryClient.refetchQueries("sessions"); queryClient.refetchQueries("session"); }, @@ -75,6 +78,7 @@ const BatterViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) = }, { onSuccess: () => { + setIsRevealed(true); queryClient.invalidateQueries("sessions"); queryClient.refetchQueries("session"); }, @@ -83,6 +87,14 @@ const BatterViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) = }, }, ); + useEffect(() => { + if (sessionStatus.didBatterReveal) { + setIsRevealed(true); + } + if (sessionStatus.didBatterCommit) { + setIsCommitted(true); + } + }, [sessionStatus]); return ( ); }; diff --git a/web/src/components/playing/PitcherViewMobile.tsx b/web/src/components/playing/PitcherViewMobile.tsx index 1916ef88..b52d514b 100644 --- a/web/src/components/playing/PitcherViewMobile.tsx +++ b/web/src/components/playing/PitcherViewMobile.tsx @@ -1,4 +1,4 @@ -import { useContext } from "react"; +import { useContext, useEffect, useState } from "react"; import { useMutation, useQueryClient } from "react-query"; import Web3Context from "../../contexts/Web3Context/context"; @@ -13,6 +13,8 @@ import PlayerView from "./PlayerView"; const FullcountABI = FullcountABIImported as unknown as AbiItem[]; const PitcherViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) => { + const [isCommitted, setIsCommitted] = useState(false); + const [isRevealed, setIsRevealed] = useState(false); const web3ctx = useContext(Web3Context); const { contractAddress } = useGameContext(); const gameContract = new web3ctx.web3.eth.Contract(FullcountABI) as any; @@ -36,6 +38,7 @@ const PitcherViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) }, { onSuccess: () => { + setIsCommitted(true); queryClient.refetchQueries("sessions"); queryClient.refetchQueries("session"); // setIsCommitted(true); @@ -77,7 +80,7 @@ const PitcherViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) }, { onSuccess: () => { - // setIsRevealed(true); + setIsRevealed(true); queryClient.invalidateQueries("sessions"); queryClient.refetchQueries("session"); }, @@ -87,12 +90,23 @@ const PitcherViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) }, ); + useEffect(() => { + if (sessionStatus.didPitcherReveal) { + setIsRevealed(true); + } + if (sessionStatus.didPitcherCommit) { + setIsCommitted(true); + } + }, [sessionStatus]); + return ( ); }; diff --git a/web/src/components/playing/PlayerView.tsx b/web/src/components/playing/PlayerView.tsx index b35e1588..11efbc28 100644 --- a/web/src/components/playing/PlayerView.tsx +++ b/web/src/components/playing/PlayerView.tsx @@ -19,15 +19,17 @@ const PlayerView = ({ isPitcher, commitMutation, revealMutation, + isCommitted, + isRevealed, }: { sessionStatus: SessionStatus; isPitcher: boolean; commitMutation: any; revealMutation: any; + isCommitted: boolean; + isRevealed: boolean; }) => { const [actionChoice, setActionChoice] = useState(0); - const [isCommitted, setIsCommitted] = useState(false); - const [isRevealed, setIsRevealed] = useState(false); const [gridIndex, setGridIndex] = useState(-1); const [showTooltip, setShowTooltip] = useState(false); const { contractAddress, selectedToken } = useGameContext(); @@ -91,36 +93,6 @@ const PlayerView = ({ commitMutation.mutate({ sign }); }; - useEffect(() => { - if ( - (isPitcher && sessionStatus.didPitcherCommit) || - (!isPitcher && sessionStatus.didBatterCommit) - ) { - setIsCommitted(true); - } - }, [isPitcher, sessionStatus.didBatterCommit, sessionStatus.didPitcherCommit]); - - useEffect(() => { - if (commitMutation.isSuccess) { - setIsCommitted(true); - } - }, [commitMutation.isSuccess]); - - useEffect(() => { - if ( - (isPitcher && sessionStatus.didPitcherReveal) || - (!isPitcher && sessionStatus.didBatterReveal) - ) { - setIsCommitted(true); - } - }, [isPitcher, sessionStatus.didBatterReveal, sessionStatus.didPitcherReveal]); - - useEffect(() => { - if (revealMutation.isSuccess) { - setIsRevealed(true); - } - }, [revealMutation.isSuccess]); - useEffect(() => { const localStorageKey = `fullcount.xyz-${contractAddress}-${sessionStatus.sessionID}-${selectedToken?.id}`; const reveal = getLocalStorageItem(localStorageKey);