Skip to content

Commit c3f10ed

Browse files
fix: optimistic
1 parent 8f4d697 commit c3f10ed

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

examples/react/react-app/src/dojo/createSystemCalls.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { AccountInterface } from "starknet";
22
import {
33
Entity,
4+
Has,
5+
HasValue,
46
World,
5-
defineComponentSystem,
7+
defineSystem,
68
getComponentValue,
79
} from "@dojoengine/recs";
810
import { uuid } from "@latticexyz/utils";
@@ -53,13 +55,16 @@ export function createSystemCalls(
5355
// Wait for the indexer to update the entity
5456
// By doing this we keep the optimistic UI in sync with the actual state
5557
await new Promise<void>((resolve) => {
56-
defineComponentSystem(world, Moves, (update) => {
57-
const { value } = update;
58-
59-
if (value[0]?.player === BigInt(account.address)) {
58+
defineSystem(
59+
world,
60+
[
61+
Has(Moves),
62+
HasValue(Moves, { player: BigInt(account.address) }),
63+
],
64+
() => {
6065
resolve();
6166
}
62-
});
67+
);
6368
});
6469
} catch (e) {
6570
console.log(e);
@@ -109,13 +114,16 @@ export function createSystemCalls(
109114
// Wait for the indexer to update the entity
110115
// By doing this we keep the optimistic UI in sync with the actual state
111116
await new Promise<void>((resolve) => {
112-
defineComponentSystem(world, Moves, (update) => {
113-
const { value } = update;
114-
115-
if (value[0]?.player === BigInt(account.address)) {
117+
defineSystem(
118+
world,
119+
[
120+
Has(Moves),
121+
HasValue(Moves, { player: BigInt(account.address) }),
122+
],
123+
() => {
116124
resolve();
117125
}
118-
});
126+
);
119127
});
120128
} catch (e) {
121129
console.log(e);

0 commit comments

Comments
 (0)