Skip to content

Commit

Permalink
Improve handling issues on game create
Browse files Browse the repository at this point in the history
  • Loading branch information
lindlof committed Dec 12, 2020
1 parent bbb11b8 commit 07a1bd0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 10 additions & 6 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,23 @@ const playGame = async (
setGame(game);
const method = privateGame ? 'private_game' : 'join_game';
try {
const res = await client.execute(contract, { [method]: { locator: game.locator } }, undefined, [
await client.execute(contract, { [method]: { locator: game.locator } }, undefined, [
{
amount: '10000000',
denom: 'uscrt',
},
]);
console.log('txn', res.transactionHash);
} catch (e) {
if (e.message !== 'ciphertext not set') {
enqueueSnackbar('Game creation erroring', { variant: 'error' });
console.log('playGame error', e);
return;
if (e instanceof Error) {
if (e.message === 'ciphertext not set') return;
if (e.message.includes('Error when posting tx ')) {
console.log('playGame error:', e.message);
enqueueSnackbar('Error posting transaction', { variant: 'error' });
setGame(undefined);
}
}
console.log('playGame error:', e.message);
enqueueSnackbar('Game creation erroring', { variant: 'error' });
}
};

Expand Down
12 changes: 7 additions & 5 deletions web/src/GamePlaying.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,24 @@ const GamePlaying = (props: Props) => {
};

if (game.stage === Game.Stage.Creating) {
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 && (
{now > game.createdAt + 10 * 1000 && (
<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()}>
<Button
variant="contained"
color="secondary"
disabled={now < game.createdAt + 13 * 1000}
onClick={() => leaveGame()}
>
DANGER: Abandon game
</Button>
</div>
Expand Down

0 comments on commit 07a1bd0

Please sign in to comment.