Skip to content

Commit

Permalink
moving player status up
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-Mushnin committed Jan 25, 2024
1 parent 70236f6 commit 48bbff9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
16 changes: 15 additions & 1 deletion web/src/components/playing/BatterViewMobile.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand All @@ -36,6 +38,7 @@ const BatterViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) =
},
{
onSuccess: () => {
setIsCommitted(true);
queryClient.refetchQueries("sessions");
queryClient.refetchQueries("session");
},
Expand Down Expand Up @@ -75,6 +78,7 @@ const BatterViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) =
},
{
onSuccess: () => {
setIsRevealed(true);
queryClient.invalidateQueries("sessions");
queryClient.refetchQueries("session");
},
Expand All @@ -83,13 +87,23 @@ const BatterViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus }) =
},
},
);
useEffect(() => {
if (sessionStatus.didBatterReveal) {
setIsRevealed(true);
}
if (sessionStatus.didBatterCommit) {
setIsCommitted(true);
}
}, [sessionStatus]);

return (
<PlayerView
sessionStatus={sessionStatus}
isPitcher={false}
commitMutation={commitSwing}
revealMutation={revealSwing}
isCommitted={isCommitted}
isRevealed={isRevealed}
/>
);
};
Expand Down
18 changes: 16 additions & 2 deletions web/src/components/playing/PitcherViewMobile.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand All @@ -36,6 +38,7 @@ const PitcherViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus })
},
{
onSuccess: () => {
setIsCommitted(true);
queryClient.refetchQueries("sessions");
queryClient.refetchQueries("session");
// setIsCommitted(true);
Expand Down Expand Up @@ -77,7 +80,7 @@ const PitcherViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus })
},
{
onSuccess: () => {
// setIsRevealed(true);
setIsRevealed(true);
queryClient.invalidateQueries("sessions");
queryClient.refetchQueries("session");
},
Expand All @@ -87,12 +90,23 @@ const PitcherViewMobile = ({ sessionStatus }: { sessionStatus: SessionStatus })
},
);

useEffect(() => {
if (sessionStatus.didPitcherReveal) {
setIsRevealed(true);
}
if (sessionStatus.didPitcherCommit) {
setIsCommitted(true);
}
}, [sessionStatus]);

return (
<PlayerView
sessionStatus={sessionStatus}
isPitcher={true}
commitMutation={commitPitch}
revealMutation={revealPitch}
isCommitted={isCommitted}
isRevealed={isRevealed}
/>
);
};
Expand Down
36 changes: 4 additions & 32 deletions web/src/components/playing/PlayerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 48bbff9

Please sign in to comment.