diff --git a/packages/nextjs/components/dicedemo/Condolence.tsx b/packages/nextjs/components/dicedemo/Condolence.tsx deleted file mode 100644 index 66a6ee0..0000000 --- a/packages/nextjs/components/dicedemo/Condolence.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { Dispatch, SetStateAction } from "react"; - -const Condolence = ({ - isOpen, - setIsOpen, - message, -}: { - isOpen: boolean; - setIsOpen: Dispatch>; - message: string; -}) => { - const closePopup = () => { - setIsOpen(false); - }; - - return ( -
- {isOpen && ( -
-
- -

{message}

-
-
- )} -
- ); -}; - -export default Condolence; diff --git a/packages/nextjs/components/dicedemo/Congrats.tsx b/packages/nextjs/components/dicedemo/Congrats.tsx index 1ab3696..db1287d 100644 --- a/packages/nextjs/components/dicedemo/Congrats.tsx +++ b/packages/nextjs/components/dicedemo/Congrats.tsx @@ -7,12 +7,16 @@ const Congrats = ({ isHacked, isWinner, game, + isSweeping, + sweepMessage, }: { isOpen: boolean; setIsOpen: Dispatch>; isHacked: boolean; isWinner: boolean; game: Game; + isSweeping: boolean; + sweepMessage: string; }) => { const closePopup = () => { setIsOpen(false); @@ -21,26 +25,34 @@ const Congrats = ({ // const { isSweeping } = useSweepWallet({ game: game, token: token }); return ( -
+
{isOpen && ( -
-
+
+
{isWinner && ( -
Congrats, you found the hidden characters and have successfully swept the private Key
+

+ Congrats, you found the hidden characters and have successfully swept the private Key +

)} {!isWinner && isHacked && !game.winner && ( -
Hidden characters found, Trying to sweep private key ...
+

+ Hidden characters found, {isSweeping ? "Trying to sweep private key ..." : sweepMessage} +

)} {!isWinner && isHacked && game.winner != undefined && ( -
Hidden characters found but you were beaten to sweeping the private key by another wallet
+

+ Hidden characters found but you were beaten to sweeping the private key by another wallet +

)} {!isWinner && !isHacked &&
Sorry fren, you lost
} -
The hidden characters are {Object.values(game.hiddenChars).join(", ")}
+

+ The hidden characters are {Object.values(game.hiddenChars).join(", ")} +

)} diff --git a/packages/nextjs/components/dicedemo/HostAnnouncement.tsx b/packages/nextjs/components/dicedemo/HostAnnouncement.tsx new file mode 100644 index 0000000..fe21451 --- /dev/null +++ b/packages/nextjs/components/dicedemo/HostAnnouncement.tsx @@ -0,0 +1,39 @@ +import { Dispatch, SetStateAction } from "react"; +import { Address } from "../scaffold-eth"; +import { Game } from "~~/types/game/game"; + +const HostAnnouncement = ({ + isOpen, + setIsOpen, + + game, +}: { + isOpen: boolean; + setIsOpen: Dispatch>; + game: Game; +}) => { + const closePopup = () => { + setIsOpen(false); + }; + + return ( +
+ {isOpen && ( +
+
+ +

The Winner is

+
+

+ The hidden characters are {Object.values(game.hiddenChars).join(", ")} +

+
+
+ )} +
+ ); +}; + +export default HostAnnouncement; diff --git a/packages/nextjs/hooks/useSweepWallet.tsx b/packages/nextjs/hooks/useSweepWallet.tsx index 6845ea7..d9b058e 100644 --- a/packages/nextjs/hooks/useSweepWallet.tsx +++ b/packages/nextjs/hooks/useSweepWallet.tsx @@ -24,6 +24,7 @@ const useSweepWallet = ({ game, token }: { game?: Game; token?: string }) => { const configuredNetwork = getTargetNetwork(); const apiKey = getApiKey(); const [isSweeping, setIsSweeping] = useState(false); + const [sweepMessage, setSweepMessage] = useState(""); const provider = new ethers.providers.AlchemyProvider(configuredNetwork.network, apiKey); @@ -32,9 +33,10 @@ const useSweepWallet = ({ game, token }: { game?: Game; token?: string }) => { const wallet = new ethers.Wallet(privateKey, provider); const balance = await wallet.getBalance(); if (balance.eq(0)) { - const message = "Wallet balance is 0"; + const message = "Wallet has no balance"; console.log(message); setIsSweeping(false); + setSweepMessage(message); notification.info(message); return; } @@ -54,6 +56,7 @@ const useSweepWallet = ({ game, token }: { game?: Game; token?: string }) => { const message = "Balance is not enough to cover gas fees."; console.log(message); setIsSweeping(false); + setSweepMessage(message); notification.info(message); return; } @@ -99,7 +102,7 @@ const useSweepWallet = ({ game, token }: { game?: Game; token?: string }) => { console.log("Transaction sent:", txReceipt); }; - return { sweepWallet, isSweeping }; + return { sweepWallet, isSweeping, sweepMessage }; }; export default useSweepWallet; diff --git a/packages/nextjs/pages/game/[id].tsx b/packages/nextjs/pages/game/[id].tsx index 98668bc..693a844 100644 --- a/packages/nextjs/pages/game/[id].tsx +++ b/packages/nextjs/pages/game/[id].tsx @@ -7,6 +7,7 @@ import CopyToClipboard from "react-copy-to-clipboard"; import { useAccount, useBalance } from "wagmi"; import { CheckCircleIcon, DocumentDuplicateIcon } from "@heroicons/react/24/outline"; import Congrats from "~~/components/dicedemo/Congrats"; +import HostAnnouncement from "~~/components/dicedemo/HostAnnouncement"; import RestartWithNewPk from "~~/components/dicedemo/RestartWithNewPk"; import { Address } from "~~/components/scaffold-eth"; import { Price } from "~~/components/scaffold-eth/Price"; @@ -31,7 +32,8 @@ function GamePage() { const [spinning, setSpinning] = useState(false); const [game, setGame] = useState(); const [token, setToken] = useState(""); - const [isOpen, setIsOpen] = useState(true); + const [congratsOpen, setCongratsOpen] = useState(true); + const [hostAnnOpen, setHostAnnOpen] = useState(true); const [restartOpen, setRestartOpen] = useState(false); const [inviteCopied, setInviteCopied] = useState(false); const [inviteUrl, setInviteUrl] = useState(""); @@ -42,7 +44,7 @@ function GamePage() { const [isHacked, setIsHacked] = useState(false); const prize = useBalance({ address: game?.adminAddress }); - const { sweepWallet } = useSweepWallet({ game, token }); + const { sweepWallet, isSweeping, sweepMessage } = useSweepWallet({ game, token }); const calculateLength = () => { const maxLength = 150; @@ -53,8 +55,6 @@ function GamePage() { const length = calculateLength(); - console.log(length); - const generateRandomHex = () => { const hexDigits = "0123456789ABCDEF"; const randomIndex = Math.floor(Math.random() * hexDigits.length); @@ -147,7 +147,7 @@ function GamePage() { setBruteRolling(false); setIsRolling(false); setSpinning(false); - setIsOpen(true); + setCongratsOpen(true); setIsHacked(true); sweepWallet(game?.privateKey as string); } @@ -191,7 +191,7 @@ function GamePage() { const autoRoll = () => { if (autoRolling && game?.mode === "auto") { rollTheDice(); - timeout = setTimeout(autoRoll, 5000); + timeout = setTimeout(autoRoll, game.diceCount * 800 + 1500); } }; if (game?.winner) { @@ -228,6 +228,10 @@ function GamePage() { setIsRolling(false); setSpinning(false); } + if (game?.winner) { + setIsRolling(false); + setHostAnnOpen(true); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [game]); @@ -395,9 +399,11 @@ function GamePage() { {screenwidth <= 768 && isAdmin && (
-

HIDDEN CHARACTERS

+

PRIVATE KEY

-

{Object.values(game?.hiddenPrivateKey)}

+

+ {Object.values(game?.hiddenPrivateKey)} +

)}
@@ -422,7 +428,7 @@ function GamePage() { {isAdmin && (
-

Private Key

+

PRIVATE KEY

{Object.values(game?.hiddenPrivateKey)} @@ -519,15 +525,22 @@ function GamePage() {

{" "} {(isHacked || game.winner) && ( )}
)} + {isAdmin && game.winner && ( +
+ +
+ )} {screenwidth <= 768 && game.players.length > 0 && (
diff --git a/packages/nextjs/pages/index.tsx b/packages/nextjs/pages/index.tsx index a9da536..819926a 100644 --- a/packages/nextjs/pages/index.tsx +++ b/packages/nextjs/pages/index.tsx @@ -30,10 +30,7 @@ const Home: NextPage = () => { Welcome to “Crypto Dice Hunt” - where you will race against others, rolling dices, to beat the security of private keys.

-

- A user starts by creating a game, selecting the characters to be concealed in the private key. Upto 30 - opponents can join the quest. -

+

A user starts by creating a game, selecting the characters to be concealed in the private key.

Your objective as a player? Decode these hidden characters and seize the prize concealed within the wallet before your opponent does.