From 6aac4b371cb035ec761c4d16841c789c48bb252d Mon Sep 17 00:00:00 2001 From: Avelous Ujiri <86206128+Avelous@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:24:30 +0100 Subject: [PATCH 1/3] Merge Staging (#53) * Merge from main (#31) * Fixed sweeping gas handling following EIP-4844 upgrades on optimism (#35) * Fixed gas issues following EIP-4844 upgrade on optimism * Pk dice updates (#36) * Added a welcome roll section to home screen, set theme to light mode only, removed ai background & responsive UI updates * Added admin feature to increase and decrease hidden characters (#38) * Added admin feature to increase and decrease hidden characters * set server to live (#40) * Changed backend to heroku's deployment (#42) * vercel backend config * vercel backend config * vercel backend config * vercel backend config * vercel backend config * vercel backend config * backend with heroku * backend deployed to fly.io (#44) * deployed backend to fly.io * removed welcome roll condition (#46) * Welcome roll new Ui background (#48) * removed welcome roll condition * welcome roll ui background * ui updates (#50) * removed welcome roll condition * welcome roll ui background * ui update * welcome roll ui update (#52) * removed welcome roll condition * welcome roll ui background * ui update * welcome roll ui update --- .../components/dicedemo/WelcomeRoll.tsx | 71 ++++++++----------- packages/nextjs/pages/index.tsx | 4 +- 2 files changed, 32 insertions(+), 43 deletions(-) diff --git a/packages/nextjs/components/dicedemo/WelcomeRoll.tsx b/packages/nextjs/components/dicedemo/WelcomeRoll.tsx index a321ea7..1fed3fb 100644 --- a/packages/nextjs/components/dicedemo/WelcomeRoll.tsx +++ b/packages/nextjs/components/dicedemo/WelcomeRoll.tsx @@ -75,18 +75,16 @@ const WelcomeRoll = () => { }, [rolledResult]); return ( -
- +
+
+ +
{rolledAddress != "" && ( -
+
@@ -96,45 +94,34 @@ const WelcomeRoll = () => {
)}
-
- {Array.from({ length: 64 }).map((_, index) => - rolled ? ( - isUnitRolling[index] ? ( -
-
- spinning -
-
- ) : ( -
-
- rolled -
-
- ) - ) : ( +
+ {Array.from({ length: 64 }).map((_, index) => { + let src, alt; + + if (rolled) { + if (isUnitRolling[index]) { + src = "/rolls-gif/Spin.gif"; + alt = "spinning"; + } else { + src = `/rolls-jpg/${rolls[index]}.jpg`; + alt = "rolled"; + } + } else { + src = "/rolls-jpg/0.jpg"; + alt = "zero roll"; + } + + return (
- zero roll + {alt}
- ), - )} + ); + })}
); diff --git a/packages/nextjs/pages/index.tsx b/packages/nextjs/pages/index.tsx index d2c5fa3..399cb41 100644 --- a/packages/nextjs/pages/index.tsx +++ b/packages/nextjs/pages/index.tsx @@ -34,7 +34,9 @@ const Home: NextPage = () => {
- +
+ +
  • setGameState("joinGame")}> From 3af9ce4958346a076d0f2ff1e02dd4f2c0936b44 Mon Sep 17 00:00:00 2001 From: Damian Martinelli Date: Thu, 25 Jul 2024 04:04:09 -0300 Subject: [PATCH 2/3] Remove hiddenChars and use privateKeyToAccount to validate PK found (#54) --- packages/backend/controllers/Admin.ts | 9 +++----- packages/backend/models/Game.ts | 4 ---- .../components/dicedemo/GameCreateForm.tsx | 4 ---- .../components/dicedemo/HostAnnouncement.tsx | 3 --- .../components/dicedemo/RestartWithNewPk.tsx | 4 ---- packages/nextjs/pages/game/[id].tsx | 21 +++++++++++-------- packages/nextjs/types/game/game.ts | 1 - packages/nextjs/utils/diceDemo/apiUtils.ts | 7 +------ 8 files changed, 16 insertions(+), 37 deletions(-) diff --git a/packages/backend/controllers/Admin.ts b/packages/backend/controllers/Admin.ts index 221bd27..6c372f6 100644 --- a/packages/backend/controllers/Admin.ts +++ b/packages/backend/controllers/Admin.ts @@ -41,7 +41,7 @@ async function generateUniqueInvite(length: number) { export const createGame = async (req: Request, res: Response) => { try { - const { diceCount, hiddenChars, privateKey, hiddenPrivateKey, mode, adminAddress } = req.body; + const { diceCount, privateKey, hiddenPrivateKey, mode, adminAddress } = req.body; const salt = await bcrypt.genSalt(); // const privateKeyHash = await bcrypt.hash(privateKey, salt); @@ -54,7 +54,6 @@ export const createGame = async (req: Request, res: Response) => { mode, privateKey, hiddenPrivateKey, - hiddenChars, }); let token; @@ -70,7 +69,7 @@ export const createGame = async (req: Request, res: Response) => { export const restartWithNewPk = async (req: Request, res: Response) => { try { - const { diceCount, hiddenChars, privateKey, hiddenPrivateKey, adminAddress } = req.body; + const { diceCount, privateKey, hiddenPrivateKey, adminAddress } = req.body; const { id } = req.params; const game = await Game.findById(id); @@ -79,7 +78,6 @@ export const restartWithNewPk = async (req: Request, res: Response) => { } game.diceCount = diceCount; - game.hiddenChars = hiddenChars; game.privateKey = privateKey; game.hiddenPrivateKey = hiddenPrivateKey; game.mode = "manual"; @@ -247,7 +245,7 @@ export const kickPlayer = async (req: Request, res: Response) => { export const varyHiddenPrivatekey = async (req: Request, res: Response) => { try { const { id } = req.params; - const { hiddenChars, hiddenPrivateKey, diceCount } = req.body; + const { hiddenPrivateKey, diceCount } = req.body; const game = await Game.findById(id); if (!game) { @@ -258,7 +256,6 @@ export const varyHiddenPrivatekey = async (req: Request, res: Response) => { return res.status(400).json({ error: "Invalid dice count." }); } - game.hiddenChars = hiddenChars; game.hiddenPrivateKey = hiddenPrivateKey; game.diceCount = diceCount; const updatedGame = await game.save(); diff --git a/packages/backend/models/Game.ts b/packages/backend/models/Game.ts index 7d47211..ba6b394 100644 --- a/packages/backend/models/Game.ts +++ b/packages/backend/models/Game.ts @@ -34,10 +34,6 @@ const gameSchema = new mongoose.Schema( type: String, required: true, }, - hiddenChars: { - type: Object, - required: true, - }, players: { type: [String], default: [], diff --git a/packages/nextjs/components/dicedemo/GameCreateForm.tsx b/packages/nextjs/components/dicedemo/GameCreateForm.tsx index 5112182..89ccda9 100644 --- a/packages/nextjs/components/dicedemo/GameCreateForm.tsx +++ b/packages/nextjs/components/dicedemo/GameCreateForm.tsx @@ -11,7 +11,6 @@ interface FormData { mode: "auto" | "manual" | "brute"; privateKey: string; hiddenPrivateKey: string; - hiddenChars: { [key: number]: string }; adminAddress: string | undefined; } @@ -27,7 +26,6 @@ const GameCreationForm = () => { mode: "manual", hiddenPrivateKey: "*" + initialPrivateKey.slice(1), privateKey: initialPrivateKey, - hiddenChars: { 0: initialPrivateKey.charAt(0) }, adminAddress, }); @@ -53,7 +51,6 @@ const GameCreationForm = () => { setFormData(formData => ({ ...formData, - hiddenChars: characterObject, diceCount: selectedSlots.length, hiddenPrivateKey: "*".repeat(selectedSlots.length) + privateKey.slice(selectedSlots.length), })); @@ -86,7 +83,6 @@ const GameCreationForm = () => { diceCount: 0, mode: "auto", privateKey: loadBurnerSK(), - hiddenChars: {}, hiddenPrivateKey: "", adminAddress, }); diff --git a/packages/nextjs/components/dicedemo/HostAnnouncement.tsx b/packages/nextjs/components/dicedemo/HostAnnouncement.tsx index a5bffeb..3564563 100644 --- a/packages/nextjs/components/dicedemo/HostAnnouncement.tsx +++ b/packages/nextjs/components/dicedemo/HostAnnouncement.tsx @@ -26,9 +26,6 @@ const HostAnnouncement = ({

    The Winner is

    -

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

)} diff --git a/packages/nextjs/components/dicedemo/RestartWithNewPk.tsx b/packages/nextjs/components/dicedemo/RestartWithNewPk.tsx index a57d463..c97ed69 100644 --- a/packages/nextjs/components/dicedemo/RestartWithNewPk.tsx +++ b/packages/nextjs/components/dicedemo/RestartWithNewPk.tsx @@ -11,7 +11,6 @@ interface FormData { diceCount: number; privateKey: string; hiddenPrivateKey: string; - hiddenChars: { [key: number]: string }; adminAddress: string | undefined; } @@ -29,7 +28,6 @@ const RestartWithNewPk = ({ isOpen, setIsOpen }: { isOpen: boolean; setIsOpen: D diceCount: 0, hiddenPrivateKey: "", privateKey: "", - hiddenChars: {}, adminAddress: undefined, }); @@ -79,7 +77,6 @@ const RestartWithNewPk = ({ isOpen, setIsOpen }: { isOpen: boolean; setIsOpen: D setFormData(formData => ({ ...formData, diceCount: selectedSlots.length, - hiddenChars: characterObject, hiddenPrivateKey: "*".repeat(selectedSlots.length) + newPk.slice(selectedSlots.length), })); }; @@ -96,7 +93,6 @@ const RestartWithNewPk = ({ isOpen, setIsOpen }: { isOpen: boolean; setIsOpen: D adminAddress: account.address, hiddenPrivateKey: "*" + pk.slice(1), privateKey: pk, - hiddenChars: { 0: pk.charAt(0) }, })); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/packages/nextjs/pages/game/[id].tsx b/packages/nextjs/pages/game/[id].tsx index 813dcd2..5015119 100644 --- a/packages/nextjs/pages/game/[id].tsx +++ b/packages/nextjs/pages/game/[id].tsx @@ -21,6 +21,7 @@ import useSweepWallet from "~~/hooks/useSweepWallet"; import { Game } from "~~/types/game/game"; import { kickPlayer, pauseResumeGame, toggleMode, varyHiddenPrivatekey } from "~~/utils/diceDemo/apiUtils"; import { calculateLength, compareResult, generateRandomHex } from "~~/utils/diceDemo/gameUtils"; +import { privateKeyToAccount } from "viem/accounts"; function GamePage() { const router = useRouter(); @@ -127,8 +128,10 @@ function GamePage() { useEffect(() => { let isHiiddenChars; - if (rolled && rolledResult.length > 0 && game?.hiddenChars) { - isHiiddenChars = compareResult(rolledResult, game?.hiddenChars); + if (rolled && rolledResult.length > 0 && game?.hiddenPrivateKey) { + const pk: `0x{string}` = `0x${rolledResult.join("")}${game?.hiddenPrivateKey.replaceAll("*", "")}` as `0x{string}`; + const account = privateKeyToAccount(pk); + isHiiddenChars = account.address == game?.adminAddress; } if (isHiiddenChars) { @@ -477,8 +480,8 @@ function GamePage() { game.mode === "auto" ? setAutoRolling(true) : game.mode === "brute" - ? setBruteRolling(true) - : rollTheDice(); + ? setBruteRolling(true) + : rollTheDice(); }} disabled={ isRolling || @@ -502,12 +505,12 @@ function GamePage() {
)}
- {Object.entries(game.hiddenChars).map(([key], index) => + {rolls.map((value, index) => rolled ? ( isUnitRolling[index] || (isRolling && game.mode == "brute") ? ( spinning; players: string[]; winner?: string | null; } diff --git a/packages/nextjs/utils/diceDemo/apiUtils.ts b/packages/nextjs/utils/diceDemo/apiUtils.ts index 9fffe0a..49243f1 100644 --- a/packages/nextjs/utils/diceDemo/apiUtils.ts +++ b/packages/nextjs/utils/diceDemo/apiUtils.ts @@ -68,19 +68,14 @@ export const kickPlayer = async (game: Game, token: string, playerAddress: strin export const varyHiddenPrivatekey = async (game: Game, token: string, vary: "increase" | "decrease") => { let hiddenPrivateKey = game?.hiddenPrivateKey; - const hiddenChars = game?.hiddenChars; const privateKey = game?.privateKey; let diceCount = game?.diceCount; - const hiddCharsCopy = { ...hiddenChars }; - if (vary === "increase") { hiddenPrivateKey = "*".repeat(diceCount + 1) + privateKey.slice(diceCount + 1); - hiddCharsCopy[diceCount] = privateKey[diceCount]; diceCount++; } else { hiddenPrivateKey = "*".repeat(diceCount - 1) + privateKey.slice(diceCount - 1); - delete hiddCharsCopy[diceCount - 1]; diceCount--; } @@ -96,7 +91,7 @@ export const varyHiddenPrivatekey = async (game: Game, token: string, vary: "inc Authorization: `Bearer ${token}`, "Content-Type": "application/json", }, - body: JSON.stringify({ hiddenChars: hiddCharsCopy, hiddenPrivateKey: hiddenPrivateKey, diceCount: diceCount }), + body: JSON.stringify({ hiddenPrivateKey: hiddenPrivateKey, diceCount: diceCount }), }); notification.success("Updated hidden characters"); From 30bae7920f83932462a27aab9101a091a07b9d03 Mon Sep 17 00:00:00 2001 From: Avelous Ujiri <86206128+Avelous@users.noreply.github.com> Date: Thu, 25 Jul 2024 08:09:44 +0100 Subject: [PATCH 3/3] delete unused variable --- 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 5015119..1f9cb95 100644 --- a/packages/nextjs/pages/game/[id].tsx +++ b/packages/nextjs/pages/game/[id].tsx @@ -20,7 +20,7 @@ import useGameData from "~~/hooks/useGameData"; import useSweepWallet from "~~/hooks/useSweepWallet"; import { Game } from "~~/types/game/game"; import { kickPlayer, pauseResumeGame, toggleMode, varyHiddenPrivatekey } from "~~/utils/diceDemo/apiUtils"; -import { calculateLength, compareResult, generateRandomHex } from "~~/utils/diceDemo/gameUtils"; +import { calculateLength, generateRandomHex } from "~~/utils/diceDemo/gameUtils"; import { privateKeyToAccount } from "viem/accounts"; function GamePage() {