From 20da6124b7c0167fe850d90dea710ab0f5bf2421 Mon Sep 17 00:00:00 2001 From: Aritra Chatterjee Date: Thu, 1 Feb 2024 09:26:31 +0530 Subject: [PATCH 01/17] feat: automate card draw tx submission on turn change --- packages/webapp/src/pages/play.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/webapp/src/pages/play.tsx b/packages/webapp/src/pages/play.tsx index 216ad5ff..e71083ee 100644 --- a/packages/webapp/src/pages/play.tsx +++ b/packages/webapp/src/pages/play.tsx @@ -5,7 +5,7 @@ import { LoadingModal } from "src/components/modals/loadingModal" import { GameEndedModal } from "src/components/modals/gameEndedModal" import { Navbar } from "src/components/navbar" import * as store from "src/store/hooks" -import { CardPlacement, GameStatus, GameStep } from "src/store/types" +import { CardPlacement, FetchedGameData, GameStatus, GameStep } from "src/store/types" import { FablePage } from "src/pages/_app" import { Address } from "viem" import { readContract } from "wagmi/actions" @@ -105,14 +105,18 @@ const Play: FablePage = ({ isHydrated }) => { const cancellationHandler = useCancellationHandler(loading) const cantDrawCard = cantTakeActions || gameData.currentStep !== GameStep.DRAW - const doDrawCard = useCallback( - () => drawCard({ + + useEffect(() => { + // Automatically submit the card draw transaction when it's our turn + if(currentPlayer(gameData as FetchedGameData) === playerAddress && !cantDrawCard) { + drawCard({ gameID: gameID!, playerAddress: playerAddress!, setLoading, cancellationHandler - }), - [gameID, playerAddress, setLoading, cancellationHandler]) + }) + } + }, [cancellationHandler, cantDrawCard, gameData, gameID, playerAddress]) const cantEndTurn = cantTakeActions || !isEndingTurn(gameData.currentStep) const doEndTurn = useCallback( @@ -213,10 +217,6 @@ const Play: FablePage = ({ isHydrated }) => { {!ended && ( <> - - + } +