11import { useEffect , useMemo } from "react" ;
2- import { SDK , createDojoStore } from "@dojoengine/sdk" ;
2+ import { QueryBuilder , SDK , createDojoStore } from "@dojoengine/sdk" ;
33import { getEntityIdFromKeys } from "@dojoengine/utils" ;
44import { addAddressPadding } from "starknet" ;
55
@@ -38,34 +38,25 @@ function App({ sdk }: { sdk: SDK<Schema> }) {
3838 let unsubscribe : ( ( ) => void ) | undefined ;
3939
4040 const subscribe = async ( ) => {
41- const subscription = await sdk . subscribeEntityQuery (
42- {
43- dojo_starter : {
44- Moves : {
45- $ : {
46- where : {
47- player : {
48- $is : addAddressPadding (
49- account . account . address
50- ) ,
51- } ,
52- } ,
53- } ,
54- } ,
55- Position : {
56- $ : {
57- where : {
58- player : {
59- $is : addAddressPadding (
60- account . account . address
61- ) ,
62- } ,
63- } ,
64- } ,
65- } ,
66- } ,
67- } ,
68- ( response ) => {
41+ const subscription = await sdk . subscribeEntityQuery ( {
42+ query : new QueryBuilder < Schema > ( )
43+ . namespace ( "dojo_starter" , ( n ) =>
44+ n
45+ . entity ( "Moves" , ( e ) =>
46+ e . eq (
47+ "player" ,
48+ addAddressPadding ( account . account . address )
49+ )
50+ )
51+ . entity ( "Position" , ( e ) =>
52+ e . is (
53+ "player" ,
54+ addAddressPadding ( account . account . address )
55+ )
56+ )
57+ )
58+ . build ( ) ,
59+ callback : ( response ) => {
6960 if ( response . error ) {
7061 console . error (
7162 "Error setting up entity sync:" ,
@@ -79,8 +70,7 @@ function App({ sdk }: { sdk: SDK<Schema> }) {
7970 state . updateEntity ( response . data [ 0 ] ) ;
8071 }
8172 } ,
82- { logging : true }
83- ) ;
73+ } ) ;
8474
8575 unsubscribe = ( ) => subscription . cancel ( ) ;
8676 } ;
@@ -97,23 +87,18 @@ function App({ sdk }: { sdk: SDK<Schema> }) {
9787 useEffect ( ( ) => {
9888 const fetchEntities = async ( ) => {
9989 try {
100- await sdk . getEntities (
101- {
102- dojo_starter : {
103- Moves : {
104- $ : {
105- where : {
106- player : {
107- $eq : addAddressPadding (
108- account . account . address
109- ) ,
110- } ,
111- } ,
112- } ,
113- } ,
114- } ,
115- } ,
116- ( resp ) => {
90+ await sdk . getEntities ( {
91+ query : new QueryBuilder < Schema > ( )
92+ . namespace ( "dojo_starter" , ( n ) =>
93+ n . entity ( "Moves" , ( e ) =>
94+ e . eq (
95+ "player" ,
96+ addAddressPadding ( account . account . address )
97+ )
98+ )
99+ )
100+ . build ( ) ,
101+ callback : ( resp ) => {
117102 if ( resp . error ) {
118103 console . error (
119104 "resp.error.message:" ,
@@ -124,8 +109,8 @@ function App({ sdk }: { sdk: SDK<Schema> }) {
124109 if ( resp . data ) {
125110 state . setEntities ( resp . data ) ;
126111 }
127- }
128- ) ;
112+ } ,
113+ } ) ;
129114 } catch ( error ) {
130115 console . error ( "Error querying entities:" , error ) ;
131116 }
0 commit comments