From 977d765414e3c1759299ed24f1fcbb44e726ca62 Mon Sep 17 00:00:00 2001 From: Mikael Lindlof Date: Fri, 11 Dec 2020 01:12:20 +0000 Subject: [PATCH] Allow abandoning entry with issues after 10 sec --- web/src/GamePlaying.tsx | 24 ++++++++++++++++++++++-- web/src/game.ts | 13 ++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/web/src/GamePlaying.tsx b/web/src/GamePlaying.tsx index 2f50212..f55f30d 100644 --- a/web/src/GamePlaying.tsx +++ b/web/src/GamePlaying.tsx @@ -76,8 +76,28 @@ const GamePlaying = (props: Props) => { }; if (game.stage === Game.Stage.Creating) { - return ; - // TODO: Leaving game is not getting created + console.log('createdAt', game.createdAt); + const now = Number(new Date()); + // TODO: Confirmation dialog + // TODO: If we can see that entry transaction was rejected abandon automatically + return ( +
+ + {game.createdAt + 10 * 1000 < now && ( +
+ + This is taking a while. You can abandon if your entry transaction doesn't go through. + + + Otherwise, abandoning results in loss of your entry funds (10 SCRT). + + +
+ )} +
+ ); } let displayContent: DisplayContent = DisplayContent.PickHandsign; diff --git a/web/src/game.ts b/web/src/game.ts index bb91777..b94256d 100644 --- a/web/src/game.ts +++ b/web/src/game.ts @@ -5,6 +5,8 @@ interface Game { readonly contract: string; readonly privateGame: boolean; readonly locator: string; + readonly createdAt: number; + readonly updatedAt: number; readonly playerNumber: number | undefined; readonly stage: Stage; readonly round: number; @@ -20,6 +22,7 @@ interface Game { } interface TickUpdate { + readonly updatedAt: number; readonly playerNumber: number | undefined; readonly stage: Stage; readonly round: number; @@ -52,10 +55,12 @@ interface Round { readonly handsign: Msg.Handsign | undefined; } -const defaults = Object.freeze({ +const defaults: Game = Object.freeze({ contract: '', privateGame: false, locator: '', + createdAt: 0, + updatedAt: 0, playerNumber: undefined, stage: Stage.Creating, round: 1, @@ -95,6 +100,7 @@ const create = (contract: string, privateGame: boolean, joinLocator?: string): G locator, playerNumber, stage, + createdAt: Number(new Date()), }; }; @@ -103,6 +109,7 @@ const tick = async ( game: Game, ): Promise => { let update: TickUpdate = { + updatedAt: Number(new Date()), playerNumber: game.playerNumber, stage: game.stage, round: game.round, @@ -120,8 +127,8 @@ const tick = async ( game_lobby: { locator: game.locator }, }); if (!lobby.game_started) { - if (game.stage === Stage.Creating) return { ...game, stage: Stage.Lobby }; - return; + if (game.stage === Stage.Creating) return { ...update, stage: Stage.Lobby }; + return update; } let playerNumber = update.playerNumber;