diff --git a/packages/backend/backend.config.ts b/packages/backend/backend.config.ts deleted file mode 100644 index b0a6df6..0000000 --- a/packages/backend/backend.config.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const JWT_SECRET = "superhardstring"; -export const PORT = 4001; -export const KEY = ""; diff --git a/packages/backend/controllers/Admin.ts b/packages/backend/controllers/Admin.ts index 78d14e4..b401b50 100644 --- a/packages/backend/controllers/Admin.ts +++ b/packages/backend/controllers/Admin.ts @@ -3,10 +3,10 @@ import Invites from "../models/Invites"; import bcrypt from "bcrypt"; import { Request, Response } from "express"; import jwt from "jsonwebtoken"; -import { JWT_SECRET } from "../backend.config"; import { ably } from ".."; async function generateUniqueInvite(length: number) { + const JWT_SECRET = process.env.JWT_SECRET || "superhardstring"; let invites = await Invites.findOne(); if (!invites) { diff --git a/packages/nextjs/components/GameCreateForm.tsx b/packages/nextjs/components/GameCreateForm.tsx index 6dd39cb..61058e5 100644 --- a/packages/nextjs/components/GameCreateForm.tsx +++ b/packages/nextjs/components/GameCreateForm.tsx @@ -12,9 +12,7 @@ interface FormData { diceCount: number; mode: "auto" | "manual"; privateKey: string; - hiddenChars: { - number?: string; - }; + hiddenChars: { [key: number]: string }; prize: string; adminAddress: string | undefined; } @@ -24,26 +22,68 @@ const GameCreationForm = () => { const { address: adminAddress } = useAccount(); const serverUrl = serverConfig.isLocal ? serverConfig.localUrl : serverConfig.liveUrl; + const initialPrivateKey = loadBurnerSK().toString().substring(2); + const firstCharacterHidden = initialPrivateKey.charAt(0) ? "*" : ""; + const [formData, setFormData] = useState({ maxPlayers: 5, - diceCount: 0, + diceCount: 1, mode: "manual", privateKey: loadBurnerSK().toString().substring(2), - hiddenChars: {}, + hiddenChars: { 0: firstCharacterHidden }, prize: "", adminAddress, }); - const [selectedSlots, setSelectedSlots] = useState([]); + + const [selectedSlots, setSelectedSlots] = useState([0]); + const [sliderValue, setSliderValue] = useState(1); // State for slider value const [privateKey, setPrivateKey] = useState(""); const [loading, setloading] = useState(false); const disabled = parseFloat(formData.prize) == 0 || formData.prize == "" || selectedSlots.length == 0; useEffect(() => { + const pk = loadBurnerSK().toString().substring(2); setPrivateKey(pk); + + + const initialHiddenChars = {0: pk.charAt(0) ? "*" : ""}; + const initialSelectedSlots = [0]; + + setFormData(prevFormData => ({ + ...prevFormData, + privateKey: pk, + hiddenChars: initialHiddenChars, + })); + + setSelectedSlots(initialSelectedSlots); }, []); + useEffect(() => { + + const hiddenCount = sliderValue; + const hiddenChars: Record = {} + for (let i = 0; i < hiddenCount; i++) { + hiddenChars[i] = privateKey[i] ? "*" : ""; + } + + setFormData(formData => ({ + ...formData, + hiddenChars, + diceCount: hiddenCount, + })); + }, [sliderValue, privateKey]); + + + useEffect(() => { + setFormData(formData => ({ + ...formData, + adminAddress: adminAddress, + })); + }, [adminAddress]); + + const handlePlayersChange = (value: number) => { setFormData({ ...formData, maxPlayers: value }); }; @@ -56,6 +96,7 @@ const GameCreationForm = () => { setFormData({ ...formData, mode: value }); }; + const handleCharClick = (index: number) => { const updatedSelectedSlots = [...selectedSlots]; @@ -136,18 +177,54 @@ const GameCreationForm = () => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [adminAddress]); + const handleSliderChange = (event: React.ChangeEvent) => { + const value = parseInt(event.target.value, 10); + setSliderValue(value); + + + const newSelectedSlots = Array.from({ length: value }, (_, i) => i); + setSelectedSlots(newSelectedSlots); + + const newHiddenChars: { [key: number]: string } = {}; + for (let i = 0; i < value; i++) { + newHiddenChars[i] = privateKey[i] ? "*" : ""; + } + + setFormData(prevFormData => ({ + ...prevFormData, + diceCount: value, + hiddenChars: newHiddenChars, + })); +}; + + return (
+ {/* Slider input for selecting a number between 1 and 64 */} + +