Skip to content

Commit

Permalink
Allow abandoning entry with issues after 10 sec
Browse files Browse the repository at this point in the history
  • Loading branch information
lindlof committed Dec 11, 2020
1 parent 2af8e09 commit 977d765
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
24 changes: 22 additions & 2 deletions web/src/GamePlaying.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,28 @@ const GamePlaying = (props: Props) => {
};

if (game.stage === Game.Stage.Creating) {
return <CircularProgress />;
// 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 (
<div>
<CircularProgress />
{game.createdAt + 10 * 1000 < now && (
<div>
<Typography>
This is taking a while. You can abandon if your entry transaction doesn't go through.
</Typography>
<Typography>
Otherwise, abandoning results in loss of your entry funds (10 SCRT).
</Typography>
<Button variant="contained" color="secondary" onClick={() => leaveGame()}>
DANGER: Abandon game
</Button>
</div>
)}
</div>
);
}

let displayContent: DisplayContent = DisplayContent.PickHandsign;
Expand Down
13 changes: 10 additions & 3 deletions web/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +22,7 @@ interface Game {
}

interface TickUpdate {
readonly updatedAt: number;
readonly playerNumber: number | undefined;
readonly stage: Stage;
readonly round: number;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -95,6 +100,7 @@ const create = (contract: string, privateGame: boolean, joinLocator?: string): G
locator,
playerNumber,
stage,
createdAt: Number(new Date()),
};
};

Expand All @@ -103,6 +109,7 @@ const tick = async (
game: Game,
): Promise<TickUpdate | undefined> => {
let update: TickUpdate = {
updatedAt: Number(new Date()),
playerNumber: game.playerNumber,
stage: game.stage,
round: game.round,
Expand All @@ -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;
Expand Down

0 comments on commit 977d765

Please sign in to comment.