diff --git a/crypto_clash_frontend/app/clash/Button.tsx b/crypto_clash_frontend/app/clash/Button.tsx new file mode 100644 index 0000000..fe14a01 --- /dev/null +++ b/crypto_clash_frontend/app/clash/Button.tsx @@ -0,0 +1,13 @@ +import { ButtonHTMLAttributes } from "react"; + +interface ButtonProps extends ButtonHTMLAttributes { + variant?: "primary" | "secondary"; +} + +export function Button({ variant = "primary", className = "", ...props }: Readonly) { + const baseClasses = variant === "primary" + ? "rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 disabled:opacity-50 disabled:cursor-not-allowed" + : "rounded bg-white px-2 py-1 text-xs font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 dark:bg-white/10 dark:text-white dark:ring-0 dark:hover:bg-white/20"; + + return +
- + {bothPlayed}
diff --git a/crypto_clash_frontend/app/clash/Input.tsx b/crypto_clash_frontend/app/clash/Input.tsx new file mode 100644 index 0000000..35ef836 --- /dev/null +++ b/crypto_clash_frontend/app/clash/Input.tsx @@ -0,0 +1,9 @@ +import { InputHTMLAttributes } from "react"; + +interface InputProps extends InputHTMLAttributes {} + +export function Input({ className = "", ...props }: Readonly) { + const baseClasses = "rounded-md border-0 px-3 py-1.5 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 dark:bg-white/5 dark:ring-white/10 dark:focus:ring-indigo-500"; + + return ; +} diff --git a/crypto_clash_frontend/app/clash/Lobby.tsx b/crypto_clash_frontend/app/clash/Lobby.tsx index 58daba2..21b598b 100644 --- a/crypto_clash_frontend/app/clash/Lobby.tsx +++ b/crypto_clash_frontend/app/clash/Lobby.tsx @@ -1,5 +1,7 @@ import { useState } from "react"; import Web3 from "web3"; +import { Button } from "./Button"; +import { Input } from "./Input"; interface LobbyProps { account: string; @@ -168,6 +170,7 @@ export default function Lobby({ setStatus("Register tx sent: " + result); } catch (err: any) { setStatus("Register failed: " + err.message); + console.error(err); } finally { setLoading(false); } @@ -175,59 +178,59 @@ export default function Lobby({ return (

register(uint gameId) (payable)

- setRegisterGameId(e.target.value)} - className="border px-2 py-1 mr-2 rounded" + className="mr-2" /> - setRegisterBet(e.target.value)} - className="border px-2 py-1 mr-2 rounded" + className="mr-2" /> -
+
Enter amount in ETH (e.g., 0.01 for 0.01 ETH). Entering 1 means 1 full ETH.
- +
- + {betMin}
- + {activeGameIds}
- + {contractBalance}
- setGameDetailsId(e.target.value)} className="border px-2 py-1 mr-2 rounded" /> - - {gameDetails &&
{JSON.stringify(gameDetails, null, 2)}
}
+ setGameDetailsId(e.target.value)} className="mr-2" /> + + {gameDetails &&
{JSON.stringify(gameDetails, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)}
}

- + {myActiveGameId}
- setPastGameIndex(e.target.value)} className="border px-2 py-1 mr-2 rounded" /> - - {pastGame &&
{JSON.stringify(pastGame, null, 2)}
}
+ setPastGameIndex(e.target.value)} className="mr-2" /> + + {pastGame &&
{JSON.stringify(pastGame, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)}
}

- + {pastGamesCount}
- + {whoAmI}
diff --git a/crypto_clash_frontend/app/clash/Reveal.tsx b/crypto_clash_frontend/app/clash/Reveal.tsx index 23bdc73..2fd568c 100644 --- a/crypto_clash_frontend/app/clash/Reveal.tsx +++ b/crypto_clash_frontend/app/clash/Reveal.tsx @@ -1,5 +1,7 @@ import { useState } from "react"; import Web3 from "web3"; +import { Button } from "./Button"; +import { Input } from "./Input"; interface RevealProps { account: string; @@ -105,52 +107,52 @@ export default function Reveal({ return (

reveal(string clearMove)

- setRevealMove(e.target.value)} - className="border px-2 py-1 mr-2 rounded" + className="mr-2" /> - +
- + {bothRevealed}
- + {playerARevealed}
- + {playerBRevealed}
- + {revealTimeLeft}
diff --git a/crypto_clash_frontend/app/clash/page.tsx b/crypto_clash_frontend/app/clash/page.tsx index 89d29b9..f16dcf8 100644 --- a/crypto_clash_frontend/app/clash/page.tsx +++ b/crypto_clash_frontend/app/clash/page.tsx @@ -16,6 +16,11 @@ export default function Clash() { // Inputs for contract functions const [phase, setPhase] = useState<"lobby" | "commit" | "reveal">("lobby"); + // Clear status when phase changes + useEffect(() => { + setStatus(""); + }, [phase]); + // Load config and contract useEffect(() => { const loadConfig = async () => {