Skip to content

Commit 580ebb6

Browse files
fix: prevent actions from from popping up post sign cancel
1 parent b74583f commit 580ebb6

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

client/game/comets.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IGameState } from "../comets";
22
import { fetchLeaderboard, fetchMruInfo } from "../rpc/api";
3+
import { removeFromStore, StorageKey } from "../rpc/storage";
34
import { getWalletClient } from "../rpc/wallet";
45
import { AttractMode } from "./attractMode";
56
import { GameMode } from "./gameMode";
@@ -41,17 +42,20 @@ export class Comets {
4142
this.lastScore = world.score;
4243
if (!this.isSendingTicks) {
4344
this.isSendingTicks = true;
44-
this.tickRecorder
45+
await this.tickRecorder
4546
.sendTicks(this.lastScore)
4647
.then(() => {
4748
console.log("Sent ticks");
48-
this.init();
4949
})
5050
.catch((e) => {
5151
console.error("Error sending ticks", e.message);
5252
})
5353
.finally(() => {
54+
removeFromStore(StorageKey.GAME_ID);
5455
this.isSendingTicks = false;
56+
this.init();
57+
// Reload page
58+
window.location.reload();
5559
});
5660
}
5761
// restart in attract mode

client/game/keys.ts

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export class _Key {
9191
this.touched = !this.touched;
9292
}
9393

94+
clear() {
95+
this.keys = {};
96+
this.prev = {};
97+
}
98+
9499
isPressed(key: number) {
95100
return this.prev[key] === false && this.keys[key] === true;
96101
}

client/rpc/api.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { getAddress } from "viem";
2-
import {
3-
addToStore,
4-
getFromStore,
5-
removeFromStore,
6-
StorageKey,
7-
} from "./storage";
2+
import { addToStore, getFromStore, StorageKey } from "./storage";
83
import { getWalletClient } from "./wallet";
94

105
const API_URL = "http://localhost:3210";
@@ -27,13 +22,18 @@ const submitAction = async (transition: string, inputs: any) => {
2722
const { domain, schemas } = mruInfo;
2823
const msgSender = getAddress(walletClient.account.address);
2924

30-
const signature = await walletClient.signTypedData({
31-
domain,
32-
primaryType: schemas[transition].primaryType,
33-
types: schemas[transition].types,
34-
message: inputs,
35-
account: msgSender,
36-
});
25+
let signature;
26+
try {
27+
signature = await walletClient.signTypedData({
28+
domain,
29+
primaryType: schemas[transition].primaryType,
30+
types: schemas[transition].types,
31+
message: inputs,
32+
account: msgSender,
33+
});
34+
} catch (e) {
35+
console.error("Error signing message", e);
36+
}
3737

3838
const response = await fetch(`${API_URL}/${transition}`, {
3939
method: "POST",
@@ -52,7 +52,6 @@ const submitAction = async (transition: string, inputs: any) => {
5252

5353
const endGame = async (inputs: any) => {
5454
await submitAction("endGame", inputs);
55-
removeFromStore(StorageKey.GAME_ID);
5655
};
5756

5857
const startGame = async () => {

0 commit comments

Comments
 (0)