From 6644c7dd9c75542bd6ceffc7724da2cc51fd8774 Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 16:58:25 +0300 Subject: [PATCH 01/11] requireSignature dialog --- .../components/tokens/StartAtBatDialog.tsx | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 web/src/components/tokens/StartAtBatDialog.tsx diff --git a/web/src/components/tokens/StartAtBatDialog.tsx b/web/src/components/tokens/StartAtBatDialog.tsx new file mode 100644 index 00000000..a7fb73cb --- /dev/null +++ b/web/src/components/tokens/StartAtBatDialog.tsx @@ -0,0 +1,35 @@ +import styles from "./Roster.module.css"; +import { useEffect, useRef } from "react"; + +const StartAtBatDialog = ({ + onClick, + onClose, +}: { + onClick: (requireSignature: boolean) => void; + onClose: () => void; +}) => { + const dialogRef = useRef(null); + const handleClickOutside = (event: MouseEvent) => { + if (dialogRef.current && !dialogRef.current.contains(event.target as Node)) { + onClose(); + event.stopPropagation(); + } + }; + useEffect(() => { + document.addEventListener("click", handleClickOutside, true); + return () => document.removeEventListener("click", handleClickOutside, true); + }, []); + + return ( +
+ + +
+ ); +}; + +export default StartAtBatDialog; From 1540da869f79bcdf2ffe75c6a3070f303b1b914a Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 16:59:10 +0300 Subject: [PATCH 02/11] remove 0x from sign --- web/src/tokenInterfaces/FullcountPlayerAPI.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/tokenInterfaces/FullcountPlayerAPI.ts b/web/src/tokenInterfaces/FullcountPlayerAPI.ts index d19dcd5b..30365497 100644 --- a/web/src/tokenInterfaces/FullcountPlayerAPI.ts +++ b/web/src/tokenInterfaces/FullcountPlayerAPI.ts @@ -118,7 +118,7 @@ export async function startSessionFullcountPlayer({ `token_address:${token.address}`, `token_id:${token.id}`, ]); - return { sessionID: data.session_id, sign: "0x" + data.signature }; + return { sessionID: data.session_id, sign: data.signature }; } export const delay = (delayInms: number) => { From b5d5ce06d482e0a27eb0c4811c40e9228d5efa30 Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 16:59:48 +0300 Subject: [PATCH 03/11] fetching if atBat requires signature --- web/src/services/fullcounts.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/web/src/services/fullcounts.ts b/web/src/services/fullcounts.ts index fea6be0c..cfa7e1cb 100644 --- a/web/src/services/fullcounts.ts +++ b/web/src/services/fullcounts.ts @@ -185,11 +185,17 @@ export const getAtBats = async ({ tokensCache }: { tokensCache: Token[] }) => { .sessionProgress(lastSessions[i - oldestAtBatNumber]) .encodeABI(), }); + progressQueries.push({ + target: GAME_CONTRACT, + callData: gameContract.methods + .SessionRequiresSignature(lastSessions[i - oldestAtBatNumber]) + .encodeABI(), + }); } - const [progresses] = await getMulticallResults( + const [progresses, signatures] = await getMulticallResults( FullcountABI, - ["sessionProgress"], + ["sessionProgress", "SessionRequiresSignature"], progressQueries, ); @@ -235,6 +241,7 @@ export const getAtBats = async ({ tokensCache }: { tokensCache: Token[] }) => { numberOfSessions: Number(numbersOfSessions[idx]), lastSessionId: Number(lastSessions[idx]), progress: Number(progresses[idx]), + requiresSignature: signatures[idx], })) .reverse(), tokens, From 1e75cb15296dbc96c6c139c47bd4fad6a06d6290 Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 17:00:09 +0300 Subject: [PATCH 04/11] overlay class for modals --- web/src/components/GlobalStyles.module.css | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/src/components/GlobalStyles.module.css b/web/src/components/GlobalStyles.module.css index f404a93f..2d7e000d 100644 --- a/web/src/components/GlobalStyles.module.css +++ b/web/src/components/GlobalStyles.module.css @@ -117,4 +117,15 @@ } +.overlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: #262019; + opacity: 25%; + z-index: 1; +} + From 0541a029503c1fb064384b867dc3a8e560300959 Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 17:00:40 +0300 Subject: [PATCH 05/11] add invite code to invite link --- web/src/components/atbat/InviteLinkView.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/src/components/atbat/InviteLinkView.tsx b/web/src/components/atbat/InviteLinkView.tsx index 0c4fd0bc..355598c2 100644 --- a/web/src/components/atbat/InviteLinkView.tsx +++ b/web/src/components/atbat/InviteLinkView.tsx @@ -5,13 +5,22 @@ import QuestionMarkIcon from "../icons/QuestionMarkIcon"; import BallIconWhite from "../icons/BallIconWhite"; import BatIconWhite from "../icons/BatIconWhite"; import LinkIcon from "../icons/LinkIcon"; +import { getLocalStorageInviteCodeKey, getLocalStorageItem } from "../../utils/localStorage"; +import { GAME_CONTRACT } from "../../constants"; const InviteLinkView = ({ atBat }: { atBat: AtBatStatus }) => { + const inviteCodeKey = getLocalStorageInviteCodeKey( + GAME_CONTRACT, + String(atBat.pitches[0].sessionID), + ); + const inviteCode = getLocalStorageItem(inviteCodeKey); const link = `${window.location.protocol}//${ window.location.host }/?invite_from=${encodeURIComponent( atBat.pitcher ? atBat.pitcher.name : atBat.batter ? atBat.batter.name : "", - )}&id=${atBat.pitches[0].sessionID}`; + )}&id=${atBat.pitches[0].sessionID}${inviteCode ? "&invite_code=" : ""}${ + inviteCode ? inviteCode : "" + }`; const { onCopy, hasCopied } = useClipboard(link); return ( From 1dff274f5f31b422f5b8c9c66b1687f1639b540c Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 17:01:47 +0300 Subject: [PATCH 06/11] starting private atBats --- web/src/components/tokens/PlayButtons.tsx | 79 ++++++++++++----------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/web/src/components/tokens/PlayButtons.tsx b/web/src/components/tokens/PlayButtons.tsx index 2565d338..fa87d029 100644 --- a/web/src/components/tokens/PlayButtons.tsx +++ b/web/src/components/tokens/PlayButtons.tsx @@ -7,9 +7,12 @@ import { AtBat, OwnedToken, Token } from "../../types"; import { startSessionFullcountPlayer } from "../../tokenInterfaces/FullcountPlayerAPI"; import { getLocalStorageInviteCodeKey, setLocalStorageItem } from "../../utils/localStorage"; import { GAME_CONTRACT, ZERO_ADDRESS } from "../../constants"; -import router, { useRouter } from "next/router"; +import { useRouter } from "next/router"; import { sendReport } from "../../utils/humbug"; import { useSound } from "../../hooks/useSound"; +import { useState } from "react"; +import StartAtBatDialog from "./StartAtBatDialog"; +import globalStyles from "../GlobalStyles.module.css"; const PlayButtons = ({ token }: { token: OwnedToken }) => { const queryClient = useQueryClient(); @@ -17,6 +20,7 @@ const PlayButtons = ({ token }: { token: OwnedToken }) => { const router = useRouter(); const { user } = useUser(); const playSound = useSound(); + const [role, setRole] = useState<0 | 1 | undefined>(undefined); const startSession = useMutation( async ({ @@ -40,6 +44,7 @@ const PlayButtons = ({ token }: { token: OwnedToken }) => { pitcher: role === 0 ? token : undefined, outcome: 0, progress: 2, + requiresSignature: requireSignature, }; return { sessionID, sign, atBat, token }; }, @@ -99,67 +104,67 @@ const PlayButtons = ({ token }: { token: OwnedToken }) => { }, ); + const handleClick = (role: 0 | 1) => { + playSound(role === 0 ? "pitchButton" : "batButton"); + if (token.tokenProgress !== 6 && token.stakedSessionID) { + router.push(`atbats/?session_id=${token.stakedSessionID}`); + return; + } + setRole(role); + }; + + const handleChoice = (requireSignature: boolean) => { + if (role === undefined) { + return; + } + startSession.mutate({ + role, + token, + requireSignature, + }); + setRole(undefined); + }; + return (
+ {role !== undefined && ( + setRole(undefined)} /> + )} + {role !== undefined &&
} + {(!token.isStaked || token.tokenProgress === 6 || (token.activeSession?.batterNFT.nftAddress === token.address && token.activeSession?.batterNFT.tokenID === token.id)) && ( -
{ - playSound("batButton"); - if ( - token.activeSession?.batterNFT.nftAddress === token.address && - token.activeSession?.batterNFT.tokenID === token.id && - token.tokenProgress !== 6 - ) { - router.push(`atbats/?session_id=${token.stakedSessionID}`); - return; - } - startSession.mutate({ - role: 1, - token, - requireSignature: false, - }); - }} + disabled={startSession.isLoading} + style={{ zIndex: role === 0 ? 0 : 1, cursor: role === undefined ? "pointer" : "default" }} + onClick={() => handleClick(1)} > {startSession.isLoading && startSession.variables?.role === 1 ? ( ) : ( "Bat" )} -
+ )} {(!token.isStaked || token.tokenProgress === 6 || (token.activeSession?.pitcherNFT.nftAddress === token.address && token.activeSession?.pitcherNFT.tokenID === token.id)) && ( -
{ - playSound("pitchButton"); - if ( - token.activeSession?.pitcherNFT.nftAddress === token.address && - token.activeSession?.pitcherNFT.tokenID === token.id && - token.tokenProgress !== 6 - ) { - router.push(`atbats/?session_id=${token.stakedSessionID}`); - return; - } - startSession.mutate({ - role: 0, - token, - requireSignature: false, - }); - }} + style={{ zIndex: role === 1 ? 0 : 1, cursor: role === undefined ? "pointer" : "default" }} + onClick={() => handleClick(0)} > {startSession.isLoading && startSession.variables?.role === 0 ? ( ) : ( "Pitch" )} -
+ )}
); From e8f25be82ac45571e91b54ac7626fec143f90ca4 Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 17:02:33 +0300 Subject: [PATCH 07/11] tokens in expired session are ok to choose --- web/src/components/Playing.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/Playing.tsx b/web/src/components/Playing.tsx index df541c37..7253fdf1 100644 --- a/web/src/components/Playing.tsx +++ b/web/src/components/Playing.tsx @@ -232,7 +232,7 @@ const Playing = () => { )} {inviteFrom && inviteSession && ownedTokens.data && ownedTokens.data.length > 0 && ( !t.isStaked)} + tokens={ownedTokens.data.filter((t) => !t.isStaked || t.tokenProgress === 6)} sessionID={Number(inviteSession)} inviteCode={inviteCode} inviteFrom={inviteFrom} From dabbab20ee6b7b991f3ed57c70bc02f4a4544479 Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 17:03:47 +0300 Subject: [PATCH 08/11] displaying private sessions --- .../components/HomePage/TokenToPlay.module.css | 18 ++++++++++++++++++ web/src/components/HomePage/TokenToPlay.tsx | 9 ++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/web/src/components/HomePage/TokenToPlay.module.css b/web/src/components/HomePage/TokenToPlay.module.css index 818a5ad2..d2d23957 100644 --- a/web/src/components/HomePage/TokenToPlay.module.css +++ b/web/src/components/HomePage/TokenToPlay.module.css @@ -78,6 +78,24 @@ height: 31.5px; } +.private { + display: flex; + padding: 5px 20px; + justify-content: center; + align-items: center; + gap: 10px; + align-self: stretch; + background: #8EAB8F; + color: #FFF; + text-align: center; + line-height: normal; + height: 31.5px; + font-family: Pangolin, cursive; + font-size: 12px; + font-style: normal; + font-weight: 400; +} + .heatMapContainer { position: absolute; top: -1px; diff --git a/web/src/components/HomePage/TokenToPlay.tsx b/web/src/components/HomePage/TokenToPlay.tsx index e51831e8..691fea48 100644 --- a/web/src/components/HomePage/TokenToPlay.tsx +++ b/web/src/components/HomePage/TokenToPlay.tsx @@ -10,6 +10,7 @@ const TokenToPlay = ({ isLoading, isForGame, showId = true, + requiresSignature = false, }: { token: Token | undefined; isPitcher: boolean; @@ -17,6 +18,7 @@ const TokenToPlay = ({ isLoading?: boolean; isForGame?: boolean; showId?: boolean; + requiresSignature?: boolean; }) => { if (!token) { return <>; @@ -45,10 +47,11 @@ const TokenToPlay = ({
{showId &&
{token.id}
} - {onClick && ( -
+ {onClick && requiresSignature &&
Private
} + {onClick && !requiresSignature && ( +
+ )} From eefb5c6932003162c8e8d965ed35f73b322b4dc0 Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 17:04:27 +0300 Subject: [PATCH 09/11] private session dialog styles --- web/src/components/tokens/Roster.module.css | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/web/src/components/tokens/Roster.module.css b/web/src/components/tokens/Roster.module.css index 7a5cd0d0..11b2bdd4 100644 --- a/web/src/components/tokens/Roster.module.css +++ b/web/src/components/tokens/Roster.module.css @@ -76,9 +76,11 @@ gap: 5px; align-self: stretch; width: 130px; + position: relative; } .button { + width: 100%; display: flex; height: 40px; padding: 5px 20px; @@ -140,6 +142,40 @@ height: 130px; } +.dialog { + position: absolute; + z-index: 20; + top: calc(100% + 5px); + left: 0; + display: flex; + padding: 10px; + flex-direction: column; + align-items: flex-start; + gap: 5px; + border: 1px solid #262019; + background: #FFF; +} + +.dialogButton { + display: flex; + width: 145px; + padding: 5px 15px; + justify-content: center; + align-items: center; + gap: 10px; + background: #328449; + color: #FFF; + text-align: center; + font-family: Bangers, cursive; + font-size: 18px; + font-style: normal; + font-weight: 400; + line-height: normal; + white-space: nowrap; +} + + + @media (min-width: 768px) { .container { From 73f3b88008913f345419ab432a2b17eb74619cc0 Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 17:04:55 +0300 Subject: [PATCH 10/11] pass requiresSignature --- web/src/components/HomePage/PvpView.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/src/components/HomePage/PvpView.tsx b/web/src/components/HomePage/PvpView.tsx index e7d197d3..e88a902f 100644 --- a/web/src/components/HomePage/PvpView.tsx +++ b/web/src/components/HomePage/PvpView.tsx @@ -171,6 +171,7 @@ const PvpView = ({ atBats, tokens }: { atBats: AtBat[]; tokens: OwnedToken[] }) .map((openAtBat, idx) => { return openAtBat.pitcher ? ( { @@ -202,6 +203,7 @@ const PvpView = ({ atBats, tokens }: { atBats: AtBat[]; tokens: OwnedToken[] }) .map((openAtBat, idx) => { return openAtBat.batter ? ( { From 9e8f96ab9898abbb6b45b6251e34005edd2178d9 Mon Sep 17 00:00:00 2001 From: Anton Mushnin Date: Thu, 9 May 2024 17:05:19 +0300 Subject: [PATCH 11/11] adding requiresSignature to AtBAt interface --- web/src/types.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/web/src/types.d.ts b/web/src/types.d.ts index 047c9b39..6778e25b 100644 --- a/web/src/types.d.ts +++ b/web/src/types.d.ts @@ -128,6 +128,7 @@ interface AtBat { numberOfSessions?: number; lastSession?: SessionState; progress: number; + requiresSignature: boolean; } interface AtBatStatus {