File tree Expand file tree Collapse file tree
examples/example-vite-react-sdk/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @dojoengine/sdk " : patch
3+ ---
4+
5+ fix: zustand historical state hook
Original file line number Diff line number Diff line change 1- import { KeysClause , ToriiQueryBuilder } from "@dojoengine/sdk" ;
1+ import {
2+ HistoricalToriiQueryBuilder ,
3+ KeysClause ,
4+ ToriiQueryBuilder ,
5+ } from "@dojoengine/sdk" ;
26
37import { ModelsMapping } from "./typescript/models.gen.ts" ;
48import { useSystemCalls } from "./useSystemCalls.ts" ;
@@ -9,6 +13,7 @@ import {
913 useDojoSDK ,
1014 useEntityId ,
1115 useEntityQuery ,
16+ useHistoricalEntityQuery ,
1217 useModel ,
1318} from "@dojoengine/sdk/react" ;
1419import { addAddressPadding , CairoCustomEnum } from "starknet" ;
@@ -45,6 +50,22 @@ function App() {
4550 )
4651 . includeHashedKeys ( )
4752 ) ;
53+ useHistoricalEntityQuery (
54+ new HistoricalToriiQueryBuilder ( )
55+ . withClause (
56+ // Querying Moves and Position models that has at least [account.address] as key
57+ KeysClause (
58+ [ ModelsMapping . Moves , ModelsMapping . Position ] ,
59+ [
60+ account ?. address
61+ ? addAddressPadding ( account . address )
62+ : undefined ,
63+ ] ,
64+ "FixedLen"
65+ ) . build ( )
66+ )
67+ . includeHashedKeys ( )
68+ ) ;
4869
4970 const moves = useModel ( entityId as string , ModelsMapping . Moves ) ;
5071 const position = useModel ( entityId as string , ModelsMapping . Position ) ;
Original file line number Diff line number Diff line change 11import { describe , expect , it } from "vitest" ;
2- import { ToriiQueryBuilder } from "../internal/toriiQueryBuilder" ;
2+ import {
3+ ToriiQueryBuilder ,
4+ HistoricalToriiQueryBuilder ,
5+ } from "../internal/toriiQueryBuilder" ;
36import type { Clause , OrderBy } from "@dojoengine/torii-wasm" ;
47import type { SchemaType } from "../internal/types" ;
58import { ClauseBuilder } from "../internal/clauseBuilder" ;
@@ -177,3 +180,33 @@ describe("ToriiQueryBuilder", () => {
177180 } ) ;
178181 } ) ;
179182} ) ;
183+ describe ( "HistoricalToriiQueryBuilder" , ( ) => {
184+ it ( "should be historical" , ( ) => {
185+ const builder = new HistoricalToriiQueryBuilder < TestModels > ( ) ;
186+ const query = builder
187+ . withLimit ( 10 )
188+ . withCursor ( "cursor" )
189+ . addEntityModel ( "dojo_starter-Position" )
190+ . addOrderBy ( "x" , "Asc" )
191+ . includeHashedKeys ( )
192+ . build ( ) ;
193+
194+ expect ( query ) . toEqual ( {
195+ pagination : {
196+ limit : 10 ,
197+ cursor : "cursor" ,
198+ direction : "Forward" ,
199+ order_by : [
200+ {
201+ field : "x" ,
202+ direction : "Asc" ,
203+ } ,
204+ ] ,
205+ } ,
206+ clause : undefined ,
207+ no_hashed_keys : false ,
208+ models : [ "dojo_starter-Position" ] ,
209+ historical : true ,
210+ } ) ;
211+ } ) ;
212+ } ) ;
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ export function useEntityQuery<Schema extends SchemaType>(
5050export function useHistoricalEntityQuery < Schema extends SchemaType > (
5151 query : ToriiQueryBuilder < Schema >
5252) {
53- if ( query . isHistorical ( ) ) {
53+ if ( ! query . isHistorical ( ) ) {
5454 throw new Error ( "Query must be HistoricalToriiQueryBuilder" ) ;
5555 }
5656 const { sdk, useDojoStore } = useDojoSDK < ( ) => any , Schema > ( ) ;
You can’t perform that action at this time.
0 commit comments