-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,944 additions
and
73 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
packages/nextjs/components/tictactoe/CreateChallengeBox.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from "react"; | ||
import { useState } from "react"; | ||
import { Button, Card, CardBody, Heading, Stack, Text } from "@chakra-ui/react"; | ||
// import { ethers } from "ethers"; | ||
import { AddressInput, EtherInput } from "~~/components/scaffold-eth"; | ||
import { useScaffoldContractWrite } from "~~/hooks/scaffold-eth"; | ||
|
||
const CreateChallengeBox = ({}) => { | ||
const [player2Address, setPlayer2Address] = useState<string | undefined>(""); | ||
const [betAmount, setBetAmount] = useState<string>(""); | ||
|
||
const { writeAsync: createGame } = useScaffoldContractWrite({ | ||
contractName: "TicTacToe", | ||
functionName: "createGame", | ||
args: [player2Address], | ||
// value: betAmount ? betAmount.toString() : undefined, | ||
}); | ||
|
||
console.log("Bet amount: ", betAmount); | ||
|
||
return ( | ||
<Card | ||
direction={{ base: "column", sm: "row" }} | ||
maxWidth={"md"} | ||
overflow="hidden" | ||
variant="solid" | ||
textColor={"white"} | ||
marginRight={4} | ||
backgroundColor={"gray.900"} | ||
textAlign={"center"} | ||
> | ||
<Stack> | ||
<CardBody> | ||
<Heading size="xl">⭕ Play and bet on a Tic Tac Toe game! ❌</Heading> | ||
<Text fontWeight={"bold"} marginBottom={0}> | ||
⚔️ Who do you want to challenge? ⚔️ | ||
</Text> | ||
<AddressInput | ||
placeholder="Enter address for team 2" | ||
onChange={setPlayer2Address} | ||
value={player2Address ?? ""} | ||
/> | ||
<br /> | ||
<Text fontWeight={"bold"} marginBottom={0} marginTop={0}> | ||
💰 (optional) Bet ETH on the match outcome 💰 | ||
</Text> | ||
<EtherInput | ||
placeholder="Enter your bet amount in ETH or USD" | ||
onChange={newValue => { | ||
if (newValue) { | ||
setBetAmount(newValue); | ||
} else { | ||
setBetAmount(""); | ||
} | ||
}} | ||
value={betAmount} | ||
/> | ||
Your oponent will have to pay the same to accept | ||
<br /> | ||
<Text fontWeight={"bold"} mt={0} mb={0}> | ||
Winner gets all, Tie gives back the ETH | ||
</Text> | ||
<Button | ||
variant="solid" | ||
onClick={event => { | ||
event.preventDefault(); | ||
createGame(); | ||
}} | ||
backgroundColor={"red.500"} | ||
textColor={"white"} | ||
colorScheme="orange" | ||
marginTop={4} | ||
> | ||
Create challenge | ||
</Button> | ||
</CardBody> | ||
</Stack> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default CreateChallengeBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from /* , { useState } */ | ||
"react"; | ||
import { Button, Flex, Text } from "@chakra-ui/react"; | ||
|
||
// import { ethers } from "ethers"; | ||
|
||
interface TicTacToeBoardProps { | ||
gameId: number; | ||
currentPlayer: number; | ||
board: number[]; | ||
makeMove: (position: number) => void; | ||
} | ||
|
||
const TicTacToeBoard: React.FC<TicTacToeBoardProps> = ({ gameId, makeMove }) => { | ||
const renderSquare = (i: number) => ( | ||
<Button | ||
key={i} | ||
size="md" | ||
fontSize="xl" | ||
fontWeight="bold" | ||
colorScheme="teal" | ||
// disabled={board[i] !== 0 || currentPlayer !== 1} | ||
onClick={() => makeMove(i)} | ||
> | ||
{/* {board[i] === 1 ? "X" : board[i] === 2 ? "O" : ""} */} | ||
</Button> | ||
); | ||
|
||
return ( | ||
<Flex direction="column" alignItems="center" justifyContent="center" marginTop={4}> | ||
<Text fontSize="xl" fontWeight="bold" marginBottom={2}> | ||
Tic Tac Toe Game #{gameId} | ||
</Text> | ||
<Flex direction="row" flexWrap="wrap"> | ||
{[0, 1, 2, 3, 4, 5, 6, 7, 8].map(i => renderSquare(i))} | ||
</Flex> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default TicTacToeBoard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type NewGameProps = { | ||
gameId: number; | ||
player1: string; | ||
player2: string; | ||
bet: number; | ||
}; |
Oops, something went wrong.