-
- Oops, it appears that you are attempting to access a game that doesn't exist or to which access has been
- lost. Please return to the homepage to join a new game.
-
+
);
}
diff --git a/packages/nextjs/server.config.ts b/packages/nextjs/server.config.ts
index de04575..30e9f32 100644
--- a/packages/nextjs/server.config.ts
+++ b/packages/nextjs/server.config.ts
@@ -2,6 +2,7 @@ const serverConfig = {
isLocal: false,
localUrl: "http://localhost:6001",
liveUrl: "https://dicedemo-backend.fly.dev",
+ ably_api_key: "Fbq6sA.xC_GgQ:a9uQJKCunyvMmh1nVvcZaZFuZw_2LYbcHvTno5uPV5c",
};
export default serverConfig;
diff --git a/packages/nextjs/types/game/game.ts b/packages/nextjs/types/game/game.ts
index 02d938f..2cd31dd 100644
--- a/packages/nextjs/types/game/game.ts
+++ b/packages/nextjs/types/game/game.ts
@@ -5,7 +5,6 @@ export interface Game {
inviteCode: string;
diceCount: number;
mode: "auto" | "manual" | "brute";
- privateKey: string;
hiddenPrivateKey: string;
players: string[];
winner?: string | null;
diff --git a/packages/nextjs/utils/diceDemo/apiUtils.ts b/packages/nextjs/utils/diceDemo/apiUtils.ts
index 49243f1..fffe673 100644
--- a/packages/nextjs/utils/diceDemo/apiUtils.ts
+++ b/packages/nextjs/utils/diceDemo/apiUtils.ts
@@ -1,9 +1,29 @@
import { notification } from "../scaffold-eth";
+import { saveGameState } from "./game";
import serverConfig from "~~/server.config";
import { Game } from "~~/types/game/game";
const serverUrl = serverConfig.isLocal ? serverConfig.localUrl : serverConfig.liveUrl;
+export const joinGame = async (invite: string, playerAddress: string) => {
+ const response = await fetch(`${serverUrl}/player/join`, {
+ method: "PATCH",
+ headers: {
+ Authorization: `Bearer`,
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ inviteCode: invite, playerAddress }),
+ });
+
+ const updatedGame = await response.json();
+ saveGameState(JSON.stringify(updatedGame));
+
+ if (updatedGame.error) {
+ notification.error(updatedGame.error);
+ return;
+ }
+};
+
export const endGame = async (game: Game, token: string, address: string) => {
await fetch(`${serverUrl}/game/${game?._id}`, {
method: "PATCH",
@@ -66,9 +86,13 @@ export const kickPlayer = async (game: Game, token: string, playerAddress: strin
}
};
-export const varyHiddenPrivatekey = async (game: Game, token: string, vary: "increase" | "decrease") => {
+export const varyHiddenPrivatekey = async (
+ game: Game,
+ token: string,
+ vary: "increase" | "decrease",
+ privateKey: string,
+) => {
let hiddenPrivateKey = game?.hiddenPrivateKey;
- const privateKey = game?.privateKey;
let diceCount = game?.diceCount;
if (vary === "increase") {