Skip to content

Commit 8752573

Browse files
committed
fix play
1 parent df3761c commit 8752573

7 files changed

Lines changed: 26 additions & 14 deletions

File tree

client/src/api/indexer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export const useIndexer = () => {
292292
let games = gamesData.map((game) => {
293293
let gameData = gameEvents.find(
294294
(event) =>
295-
parseInt(event.game_id, 16) === game.game_id
295+
parseInt(event.game_id, 16) === game.token_id
296296
);
297297

298298
let tokenId = game.token_id;

client/src/container/LoadingContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function LoadingContainer() {
130130
}
131131

132132
gameContext.setGame({
133-
gameId: data.game_id,
133+
gameId: tokenData.id,
134134
state: data.state,
135135

136136
playerName: tokenData.playerName,

client/src/contexts/dojoContext.jsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CallData, RpcProvider } from 'starknet';
66
import { VRF_PROVIDER_ADDRESS } from "../helpers/constants";
77
import { translateEvent } from "../helpers/events";
88
import { useDynamicConnector } from "./starknet";
9+
import { delay } from "../helpers/utilities";
910

1011
export const DojoContext = createContext()
1112

@@ -43,7 +44,6 @@ export const DojoProvider = ({ children }) => {
4344

4445
if (includeVRF) {
4546
let contractAddress = txs[txs.length - 1].contractAddress
46-
4747
txs.unshift({
4848
contractAddress: VRF_PROVIDER_ADDRESS,
4949
entrypoint: 'request_random',
@@ -56,8 +56,8 @@ export const DojoProvider = ({ children }) => {
5656

5757
try {
5858
const tx = await account.execute(txs);
59-
await new Promise(resolve => setTimeout(resolve, 1000));
60-
const receipt = await account.waitForTransaction(tx.transaction_hash, { retryInterval: 500 })
59+
await delay(1000);
60+
const receipt = await waitForTransaction(tx.transaction_hash, 0)
6161

6262
if (receipt.execution_status === "REVERTED") {
6363
console.log('contract error', receipt)
@@ -78,6 +78,25 @@ export const DojoProvider = ({ children }) => {
7878
}
7979
}
8080

81+
const waitForTransaction = async (txHash, retries) => {
82+
if (retries > 9) {
83+
throw new Error("Transaction failed");
84+
}
85+
86+
try {
87+
const receipt = await account.waitForTransaction(
88+
txHash,
89+
{ retryInterval: 500 }
90+
);
91+
92+
return receipt;
93+
} catch (error) {
94+
console.error("Error waiting for transaction :", error);
95+
await delay(500);
96+
return waitForTransaction(txHash, retries + 1);
97+
}
98+
}
99+
81100
return (
82101
<DojoContext.Provider
83102
value={{

client/src/contexts/draftContext.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const DraftProvider = ({ children }) => {
4747
})
4848

4949
game.setLoadingProgress(99)
50-
const res = await dojo.executeTx(txs, true)
50+
const res = await dojo.executeTx(txs, false)
5151

5252
if (res) {
5353
const gameValues = res.find(e => e.componentName === 'Game')

client/src/contexts/gameContext.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,10 @@ export const GameProvider = ({ children }) => {
5959
useEffect(() => {
6060
if (values.gameId) {
6161
setLoading(false);
62+
window.history.replaceState(null, '', `/play/${values.gameId}`)
6263
}
6364
}, [values.gameId])
6465

65-
useEffect(() => {
66-
if (values.gameId && GG_questMode) {
67-
setValues(prev => ({ ...prev, questTarget: GG_questTargetScore }))
68-
}
69-
}, [GG_questMode, values.gameId, GG_questTargetScore])
70-
7166
const setGame = (values) => {
7267
if (!isNaN(values.state || 0)) {
7368
values.state = GAME_STATES[values.state]

client/src/contexts/replayContext.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export const ReplayProvider = ({ children }) => {
6060

6161
const startReplay = async (_game) => {
6262
setLoadingReplay(true)
63-
navigate('/watch/' + _game.id)
6463

6564
let txs = await getGameTxs(_game.id)
6665
await game.actions.loadGameDetails(_game)

client/src/pages/ArenaPage.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function ArenaPage() {
4444
gameContext.setLoadingProgress(10)
4545

4646
let game = await getTokenMetadata(watchGameId)
47-
4847
if (game) {
4948
replay.startReplay(game)
5049
} else {

0 commit comments

Comments
 (0)