From 8eb643bf3205d1ddf9681381046a22483a87c933 Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 15:08:29 +0100 Subject: [PATCH 01/10] Updates: QR code resolves to full url and enters game, Sweep function works properly on optimism and auto happens when the hidden characters are found and players section is now seperate and underneath the dice on phone screen --- packages/nextjs/components/Wallet.tsx | 8 +- .../nextjs/components/dicedemo/Congrats.tsx | 37 ++-- .../components/dicedemo/GameCreateForm.tsx | 6 +- .../components/dicedemo/GameJoinForm.tsx | 44 ++-- packages/nextjs/hooks/useSweepWallet.tsx | 39 ++-- packages/nextjs/pages/game/[id].tsx | 198 ++++++++++++------ packages/nextjs/server.config.ts | 2 +- 7 files changed, 215 insertions(+), 119 deletions(-) diff --git a/packages/nextjs/components/Wallet.tsx b/packages/nextjs/components/Wallet.tsx index c8b7dbd..4dcba08 100644 --- a/packages/nextjs/components/Wallet.tsx +++ b/packages/nextjs/components/Wallet.tsx @@ -213,7 +213,7 @@ export default function Wallet() {

Known Private Keys:

{extraPkDisplay} + + {isWinner &&
Congrats, You have successfully swept the private Key
} + {!isWinner && isHacked && !game.winner && ( +
{isSweeping ? "Trying to Sweep the wallet ..." : sweepMessage}
+ )} + {!isWinner && isHacked && game.winner != undefined && ( +
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(", ")}
)} diff --git a/packages/nextjs/components/dicedemo/GameCreateForm.tsx b/packages/nextjs/components/dicedemo/GameCreateForm.tsx index 0674c81..d03539c 100644 --- a/packages/nextjs/components/dicedemo/GameCreateForm.tsx +++ b/packages/nextjs/components/dicedemo/GameCreateForm.tsx @@ -120,9 +120,11 @@ const GameCreationForm = () => { max="64" value={sliderValue} onChange={handleSliderChange} - className="slider appearance-none w-full h-2 bg-primary rounded outline-none slider-thumb " + className="slider appearance-none w-[87%] h-2 bg-primary rounded outline-none slider-thumb " /> - {sliderValue} + + {sliderValue} +
diff --git a/packages/nextjs/components/dicedemo/GameJoinForm.tsx b/packages/nextjs/components/dicedemo/GameJoinForm.tsx index a126278..8eaa961 100644 --- a/packages/nextjs/components/dicedemo/GameJoinForm.tsx +++ b/packages/nextjs/components/dicedemo/GameJoinForm.tsx @@ -19,6 +19,8 @@ const GameJoinForm = ({ const [scanning, setScanning] = useState(false); const [loading, setLoading] = useState(false); + const { invite } = router.query; + const handleChange = (value: string) => { setInviteCode(value); }; @@ -26,8 +28,7 @@ const GameJoinForm = ({ const { address: playerAddress } = useAccount(); const serverUrl = serverConfig.isLocal ? serverConfig.localUrl : serverConfig.liveUrl; - const handleJoinGame = async (event: React.FormEvent) => { - event.preventDefault(); + const handleJoinGame = async (invite: string) => { setLoading(true); const response = await fetch(`${serverUrl}/player/join`, { method: "PATCH", @@ -35,21 +36,19 @@ const GameJoinForm = ({ Authorization: `Bearer`, "Content-Type": "application/json", }, - body: JSON.stringify({ inviteCode, playerAddress }), + body: JSON.stringify({ inviteCode: invite, playerAddress }), }); const updatedGame = await response.json(); + saveGameState(JSON.stringify(updatedGame)); setLoading(false); if (updatedGame.error) { notification.error(updatedGame.error); return; } - - saveGameState(JSON.stringify(updatedGame)); - await router.push({ pathname: `/game/[id]`, - query: { id: inviteCode }, + query: { id: invite }, }); notification.success("Joined game successfully"); @@ -70,9 +69,9 @@ const GameJoinForm = ({ setScanning(false); }; - const openCamera = () => { - setScanning(true); - }; + // const openCamera = () => { + // setScanning(true); + // }; useEffect(() => { if (labelRef.current) { @@ -80,9 +79,22 @@ const GameJoinForm = ({ } }, []); + useEffect(() => { + if (invite) { + handleJoinGame(invite as string); + } + if (Object.keys(router.query).length > 0) { + router.replace({ + pathname: router.pathname, + query: {}, + }); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [invite]); + return (
-
+ handleJoinGame(inviteCode)}> - )}
+ {game.winner && ( +
+ Winner
+
+ )} + {/* {isAdmin && game.winner && ( + + )} */} -
-
-
-

- HIDDEN CHARACTERS -

+ {screenwidth > 768 && ( +
+
+

HIDDEN CHARACTERS

-

{Object.values(game?.hiddenPrivateKey)}

-
-
-

- PLAYERS -

-
-
- {game?.players?.map((player: string) => ( -
-
768 ? "long" : "short"} address={player} /> - {isAdmin && ( - - )} +

{Object.values(game?.hiddenPrivateKey)}

+
+
+

+ PLAYERS: {game?.players.length} +

- ))} +
+ {game?.players?.map((player: string) => ( +
+
+ {isAdmin && ( + + )} +
+ ))} +
+
-
+ )}
+ {isPlayer && (
{" "} - {game?.winner == address && ( - - )} - {game.winner && game?.winner != address && ( - + {(isHacked || game.winner) && ( + )}
)} + {screenwidth <= 768 && game.players.length > 0 && ( +
+
+
+

PLAYERS

+
+
+ {game?.players?.map((player: string) => ( +
+
+ {isAdmin && ( + + )} +
+ ))} +
+
+
+ )} {isAdmin && game.winner && } {!isAdmin && !isPlayer &&

Sorry fren, You have been kicked

} diff --git a/packages/nextjs/server.config.ts b/packages/nextjs/server.config.ts index 19c8da0..7a74b86 100644 --- a/packages/nextjs/server.config.ts +++ b/packages/nextjs/server.config.ts @@ -1,5 +1,5 @@ const serverConfig = { - isLocal: false, + isLocal: true, localUrl: "http://localhost:6001", liveUrl: "https://dice-demonstration-backend.vercel.app", }; From ccd641cf305acaba345aab4d08f63bfe168440ab Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 15:26:32 +0100 Subject: [PATCH 02/10] turn off rolling --- packages/nextjs/pages/game/[id].tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/pages/game/[id].tsx b/packages/nextjs/pages/game/[id].tsx index 68694a9..8abc574 100644 --- a/packages/nextjs/pages/game/[id].tsx +++ b/packages/nextjs/pages/game/[id].tsx @@ -143,10 +143,10 @@ function GamePage() { const isHiiddenChars = compareResult(); if (isHiiddenChars) { - setIsHacked(true); setAutoRolling(false); setBruteRolling(false); setIsOpen(true); + setIsHacked(true); sweepWallet(game?.privateKey as string); } // eslint-disable-next-line react-hooks/exhaustive-deps From f5e526911ce25cadd046f1b45b23bb73edbf5010 Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 15:58:50 +0100 Subject: [PATCH 03/10] turn off rolling --- packages/nextjs/components/dicedemo/Congrats.tsx | 5 ++--- packages/nextjs/hooks/useSweepWallet.tsx | 5 +---- packages/nextjs/pages/game/[id].tsx | 1 + 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/nextjs/components/dicedemo/Congrats.tsx b/packages/nextjs/components/dicedemo/Congrats.tsx index 042ab08..37c8bad 100644 --- a/packages/nextjs/components/dicedemo/Congrats.tsx +++ b/packages/nextjs/components/dicedemo/Congrats.tsx @@ -21,8 +21,7 @@ const Congrats = ({ setIsOpen(false); }; - const { isSweeping, sweepMessage } = useSweepWallet({ game: game, token: token }); - console.log(game?.privateKey); + const { isSweeping } = useSweepWallet({ game: game, token: token }); return (
@@ -35,7 +34,7 @@ const Congrats = ({ {isWinner &&
Congrats, You have successfully swept the private Key
} {!isWinner && isHacked && !game.winner && ( -
{isSweeping ? "Trying to Sweep the wallet ..." : sweepMessage}
+
{isSweeping ? "Trying to Sweep the wallet ..." : "Failed to sweep PrivateKey"}
)} {!isWinner && isHacked && game.winner != undefined && (
You were beaten to sweeping the private key by another wallet
diff --git a/packages/nextjs/hooks/useSweepWallet.tsx b/packages/nextjs/hooks/useSweepWallet.tsx index 74f3d8f..6845ea7 100644 --- a/packages/nextjs/hooks/useSweepWallet.tsx +++ b/packages/nextjs/hooks/useSweepWallet.tsx @@ -24,7 +24,6 @@ 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); @@ -35,7 +34,6 @@ const useSweepWallet = ({ game, token }: { game?: Game; token?: string }) => { if (balance.eq(0)) { const message = "Wallet balance is 0"; console.log(message); - setSweepMessage(message); setIsSweeping(false); notification.info(message); return; @@ -55,7 +53,6 @@ const useSweepWallet = ({ game, token }: { game?: Game; token?: string }) => { if (totalToSend.lte(0)) { const message = "Balance is not enough to cover gas fees."; console.log(message); - setSweepMessage(message); setIsSweeping(false); notification.info(message); return; @@ -102,7 +99,7 @@ const useSweepWallet = ({ game, token }: { game?: Game; token?: string }) => { console.log("Transaction sent:", txReceipt); }; - return { sweepWallet, isSweeping, sweepMessage }; + return { sweepWallet, isSweeping }; }; export default useSweepWallet; diff --git a/packages/nextjs/pages/game/[id].tsx b/packages/nextjs/pages/game/[id].tsx index 8abc574..4c607eb 100644 --- a/packages/nextjs/pages/game/[id].tsx +++ b/packages/nextjs/pages/game/[id].tsx @@ -145,6 +145,7 @@ function GamePage() { if (isHiiddenChars) { setAutoRolling(false); setBruteRolling(false); + setIsRolling(false); setIsOpen(true); setIsHacked(true); sweepWallet(game?.privateKey as string); From 61a80c0a5327ae52a0b8fd03fb09ef633be27a05 Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 16:25:23 +0100 Subject: [PATCH 04/10] set server to live --- packages/nextjs/server.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/server.config.ts b/packages/nextjs/server.config.ts index 7a74b86..19c8da0 100644 --- a/packages/nextjs/server.config.ts +++ b/packages/nextjs/server.config.ts @@ -1,5 +1,5 @@ const serverConfig = { - isLocal: true, + isLocal: false, localUrl: "http://localhost:6001", liveUrl: "https://dice-demonstration-backend.vercel.app", }; From ed46ab9706f85ed144a3b4bc590db4154b94b18c Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 17:57:56 +0100 Subject: [PATCH 05/10] updating cors policy --- packages/backend/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/index.ts b/packages/backend/index.ts index 581ef12..60db7d7 100644 --- a/packages/backend/index.ts +++ b/packages/backend/index.ts @@ -34,7 +34,7 @@ app.use(bodyParser.json({ limit: "30mb" })); app.use(bodyParser.urlencoded({ limit: "30mb", extended: true })); app.use( cors({ - origin: "*", + origin: ["https://localhost:3000", "https://dicedemo-av-bg.vercel.app"], }), ); From 69096c4bc4c959d5ee746d36bfde7be525f1db29 Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 18:07:42 +0100 Subject: [PATCH 06/10] fixed vercel json --- packages/backend/vercel.json | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/backend/vercel.json b/packages/backend/vercel.json index f078860..5e02a5b 100644 --- a/packages/backend/vercel.json +++ b/packages/backend/vercel.json @@ -2,14 +2,5 @@ "version": 2, "name": "dice-demonstration-backend", "builds": [{ "src": "index.ts", "use": "@vercel/node" }], - "routes": [{ "src": "/(.*)", "dest": "/index.ts" }], - "headers": [ - { "key": "Access-Control-Allow-Credentials", "value": "true" }, - { "key": "Access-Control-Allow-Origin", "value": "*" }, - { "key": "Access-Control-Allow-Methods", "value": "GET,OPTIONS,PATCH,DELETE,POST,PUT" }, - { - "key": "Access-Control-Allow-Headers", - "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" - } - ] + "routes": [{ "src": "/(.*)", "dest": "/index.ts" }] } From 125950c9fafa56a34bc5bf5f6175dacfeebd1274 Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 18:16:16 +0100 Subject: [PATCH 07/10] fixed cors --- packages/backend/index.ts | 4 +--- packages/nextjs/server.config.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/backend/index.ts b/packages/backend/index.ts index 60db7d7..6fe5fa3 100644 --- a/packages/backend/index.ts +++ b/packages/backend/index.ts @@ -33,9 +33,7 @@ app.use(morgan("common")); app.use(bodyParser.json({ limit: "30mb" })); app.use(bodyParser.urlencoded({ limit: "30mb", extended: true })); app.use( - cors({ - origin: ["https://localhost:3000", "https://dicedemo-av-bg.vercel.app"], - }), + cors(), ); /**Ably Setup */ diff --git a/packages/nextjs/server.config.ts b/packages/nextjs/server.config.ts index 19c8da0..7a74b86 100644 --- a/packages/nextjs/server.config.ts +++ b/packages/nextjs/server.config.ts @@ -1,5 +1,5 @@ const serverConfig = { - isLocal: false, + isLocal: true, localUrl: "http://localhost:6001", liveUrl: "https://dice-demonstration-backend.vercel.app", }; From 4aeb441bc1d0ae1d5618d4c863909aee94bedfc9 Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 18:16:42 +0100 Subject: [PATCH 08/10] set server to live --- packages/nextjs/server.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/server.config.ts b/packages/nextjs/server.config.ts index 7a74b86..19c8da0 100644 --- a/packages/nextjs/server.config.ts +++ b/packages/nextjs/server.config.ts @@ -1,5 +1,5 @@ const serverConfig = { - isLocal: true, + isLocal: false, localUrl: "http://localhost:6001", liveUrl: "https://dice-demonstration-backend.vercel.app", }; From c211a478bd52b12b513b34e26f997d9c54597ce3 Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 19:18:25 +0100 Subject: [PATCH 09/10] changed server url --- packages/nextjs/server.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/server.config.ts b/packages/nextjs/server.config.ts index 19c8da0..9121921 100644 --- a/packages/nextjs/server.config.ts +++ b/packages/nextjs/server.config.ts @@ -1,7 +1,7 @@ const serverConfig = { isLocal: false, localUrl: "http://localhost:6001", - liveUrl: "https://dice-demonstration-backend.vercel.app", + liveUrl: "https://rich-ruby-cygnet-tie.cyclic.app/", }; export default serverConfig; From 57e07a4a39dbf13ca900c0c4ade940868c35144b Mon Sep 17 00:00:00 2001 From: avelous Date: Sat, 24 Feb 2024 20:13:34 +0100 Subject: [PATCH 10/10] congratulatory text --- packages/nextjs/components/dicedemo/Congrats.tsx | 14 ++++++++++---- packages/nextjs/pages/game/[id].tsx | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/nextjs/components/dicedemo/Congrats.tsx b/packages/nextjs/components/dicedemo/Congrats.tsx index 37c8bad..db13d4d 100644 --- a/packages/nextjs/components/dicedemo/Congrats.tsx +++ b/packages/nextjs/components/dicedemo/Congrats.tsx @@ -32,16 +32,22 @@ const Congrats = ({ ✕ - {isWinner &&
Congrats, You have successfully swept the private Key
} + {isWinner && ( +
Congrats, you found the hidden characters and have successfully swept the private Key
+ )} {!isWinner && isHacked && !game.winner && ( -
{isSweeping ? "Trying to Sweep the wallet ..." : "Failed to sweep PrivateKey"}
+
+ {isSweeping + ? "Hidden characters found, Trying to Sweep the wallet ..." + : "Hidden characters found, Failed to sweep PrivateKey"} +
)} {!isWinner && isHacked && game.winner != undefined && ( -
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/pages/game/[id].tsx b/packages/nextjs/pages/game/[id].tsx index 4c607eb..29ebcd5 100644 --- a/packages/nextjs/pages/game/[id].tsx +++ b/packages/nextjs/pages/game/[id].tsx @@ -146,6 +146,7 @@ function GamePage() { setAutoRolling(false); setBruteRolling(false); setIsRolling(false); + setSpinning(false); setIsOpen(true); setIsHacked(true); sweepWallet(game?.privateKey as string); @@ -243,12 +244,12 @@ function GamePage() {
-
+

INFO

Role: {isAdmin ? "Host" : isPlayer ? "Player" : "Kicked"}

-
+
{isAdmin && (