diff --git a/web/src/App.tsx b/web/src/App.tsx index 4b60752..835037c 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -49,7 +49,7 @@ export const App: React.FC = () => { playHandsign(client, game, handsign, setGame, enqueueSnackbar) } leaveGame={() => setGame(undefined)} - claimInactivity={async () => setGame(await Game.claimInactivity(client, game))} + claimInactivity={() => claimInactivity(client, game, setGame, enqueueSnackbar)} enqueueSnackbar={enqueueSnackbar} /> @@ -123,7 +123,6 @@ const playGame = async ( return; } if (e.message.includes('Error when posting tx ')) { - console.log('playGame error:', e.message); enqueueSnackbar('Error posting transaction', { variant: 'error' }); setGame(undefined); return; @@ -157,9 +156,47 @@ const playHandsign = async ( setGame((g: Game.Game) => ({ ...g, lastHandsign: handsign })); try { await Game.playHandsign(client, game, handsign); - } catch (error) { + } catch (e) { setGame((g: Game.Game) => ({ ...g, lastHandsign: undefined })); - enqueueSnackbar('Secret error', { variant: 'error' }); + if (e instanceof Error) { + if (e.message === 'Request rejected') { + enqueueSnackbar('Transaction rejected', { variant: 'error' }); + throw e; + } + if (e.message.includes('Error when posting tx ')) { + enqueueSnackbar('Error posting transaction', { variant: 'error' }); + throw e; + } + } + console.log('playHandsign error:', e.message); + enqueueSnackbar('Error playing handsign', { variant: 'error' }); + throw e; + } +}; + +const claimInactivity = async ( + client: SecretJS.SigningCosmWasmClient, + game: Game.Game, + setGame: Function, + enqueueSnackbar: Function, +) => { + try { + await Game.claimInactivity(client, game); + setGame(undefined); + } catch (e) { + if (e instanceof Error) { + if (e.message === 'Request rejected') { + enqueueSnackbar('Transaction rejected', { variant: 'error' }); + throw e; + } + if (e.message.includes('Error when posting tx ')) { + enqueueSnackbar('Error posting transaction', { variant: 'error' }); + throw e; + } + } + console.log('claimInactivity error:', e.message); + enqueueSnackbar('Error ending game', { variant: 'error' }); + throw e; } }; diff --git a/web/src/GamePlaying.tsx b/web/src/GamePlaying.tsx index 0355553..6d53239 100644 --- a/web/src/GamePlaying.tsx +++ b/web/src/GamePlaying.tsx @@ -43,7 +43,7 @@ const useStyles = makeStyles((theme) => ({ interface Props { game: Game.Game; - playHandsign: Function; + playHandsign: (handsign: Msg.Handsign) => Promise; leaveGame: Function; claimInactivity: () => Promise; enqueueSnackbar: Function; @@ -61,16 +61,19 @@ const GamePlaying = (props: Props) => { const { game, playHandsign, leaveGame, claimInactivity, enqueueSnackbar } = props; const [pickedRound, setPickedRound] = useState(); const [claimingInactivity, setClaimingInactivity] = useState(false); - const pickHandsign = (handsign: Msg.Handsign) => { + const pickHandsign = async (handsign: Msg.Handsign) => { setPickedRound(game.round); - playHandsign(handsign); + try { + await playHandsign(handsign); + } catch { + setPickedRound(undefined); + } }; const tryClaimInactivity = async () => { setClaimingInactivity(true); try { await claimInactivity(); } catch { - enqueueSnackbar('Secret error', { variant: 'error' }); setClaimingInactivity(false); } }; diff --git a/web/src/game.ts b/web/src/game.ts index b94256d..51d8267 100644 --- a/web/src/game.ts +++ b/web/src/game.ts @@ -204,7 +204,10 @@ const playHandsign = async ( try { await client.execute(game.contract, { play_hand: { handsign, locator: game.locator } }); } catch (e) { - if (e.message !== 'ciphertext not set') throw e; + if (e instanceof Error) { + if (e.message === 'ciphertext not set') return; + } + throw e; } }; @@ -212,7 +215,10 @@ const claimInactivity = async (client: SecretJS.SigningCosmWasmClient, game: Gam try { await client.execute(game.contract, { claim_inactivity: { locator: game.locator } }); } catch (e) { - if (e.message !== 'ciphertext not set') throw e; + if (e instanceof Error) { + if (e.message === 'ciphertext not set') return; + } + throw e; } };