From 50cc19ea944c5712e5df6062e4b73e472c21e877 Mon Sep 17 00:00:00 2001 From: Valentin Dosimont Date: Sat, 4 Jan 2025 17:56:47 +0100 Subject: [PATCH 1/3] feat: fix react-sdk example + predeployed connector + historical events --- examples/example-vite-react-sdk/package.json | 3 + examples/example-vite-react-sdk/src/App.tsx | 131 ++++++++-------- .../src/DojoContext.tsx | 8 +- .../example-vite-react-sdk/src/bindings.ts | 105 ------------- .../src/contracts.gen.ts | 63 -------- .../src/historical-events.tsx | 101 +++++++++++++ examples/example-vite-react-sdk/src/main.tsx | 9 +- .../src/starknet-provider.tsx | 33 ++++ .../src/typescript/contracts.gen.ts | 66 ++++++++ .../src/typescript/models.gen.ts | 142 ++++++++++++++++++ .../example-vite-react-sdk/src/useModel.tsx | 13 +- .../src/useSystemCalls.ts | 7 +- .../src/wallet-account.tsx | 68 +++++++++ packages/predeployed-connector/src/index.ts | 57 ++----- .../sdk/src/__tests__/parseEntities.test.ts | 9 +- packages/sdk/src/convertQuerytoClause.ts | 11 +- packages/sdk/src/getEventMessages.ts | 26 +++- packages/sdk/src/index.ts | 2 +- packages/sdk/src/parseHistoricalEvents.ts | 52 +++++++ packages/sdk/src/subscribeEventQuery.ts | 13 +- packages/sdk/src/types.ts | 6 +- pnpm-lock.yaml | 13 +- 22 files changed, 619 insertions(+), 319 deletions(-) delete mode 100644 examples/example-vite-react-sdk/src/bindings.ts delete mode 100644 examples/example-vite-react-sdk/src/contracts.gen.ts create mode 100644 examples/example-vite-react-sdk/src/historical-events.tsx create mode 100644 examples/example-vite-react-sdk/src/starknet-provider.tsx create mode 100644 examples/example-vite-react-sdk/src/typescript/contracts.gen.ts create mode 100644 examples/example-vite-react-sdk/src/typescript/models.gen.ts create mode 100644 examples/example-vite-react-sdk/src/wallet-account.tsx create mode 100644 packages/sdk/src/parseHistoricalEvents.ts diff --git a/examples/example-vite-react-sdk/package.json b/examples/example-vite-react-sdk/package.json index 75ca5973..1e8ca01a 100644 --- a/examples/example-vite-react-sdk/package.json +++ b/examples/example-vite-react-sdk/package.json @@ -12,10 +12,13 @@ "dependencies": { "@dojoengine/core": "workspace:*", "@dojoengine/create-burner": "workspace:*", + "@dojoengine/predeployed-connector": "workspace:*", "@dojoengine/sdk": "workspace:*", "@dojoengine/torii-client": "workspace:*", "@dojoengine/torii-wasm": "workspace:*", "@dojoengine/utils": "workspace:*", + "@starknet-react/chains": "catalog:", + "@starknet-react/core": "catalog:", "@types/uuid": "^10.0.0", "immer": "^10.1.1", "react": "^18.3.1", diff --git a/examples/example-vite-react-sdk/src/App.tsx b/examples/example-vite-react-sdk/src/App.tsx index 2850a16f..4ea5c014 100644 --- a/examples/example-vite-react-sdk/src/App.tsx +++ b/examples/example-vite-react-sdk/src/App.tsx @@ -1,17 +1,29 @@ import { useEffect, useMemo } from "react"; import { QueryBuilder, SDK, createDojoStore } from "@dojoengine/sdk"; import { getEntityIdFromKeys } from "@dojoengine/utils"; -import { addAddressPadding } from "starknet"; +import { + AccountInterface, + addAddressPadding, + CairoOption, + CairoOptionVariant, +} from "starknet"; -import { Models, Schema } from "./bindings.ts"; +import { + Direction, + ModelsMapping, + SchemaType, +} from "./typescript/models.gen.ts"; import { useDojo } from "./useDojo.tsx"; import useModel from "./useModel.tsx"; import { useSystemCalls } from "./useSystemCalls.ts"; +import { useAccount, useConnect } from "@starknet-react/core"; +import { WalletAccount } from "./wallet-account.tsx"; +import { HistoricalEvents } from "./historical-events.tsx"; /** * Global store for managing Dojo game state. */ -export const useDojoStore = createDojoStore(); +export const useDojoStore = createDojoStore(); /** * Main application component that provides game functionality and UI. @@ -19,39 +31,41 @@ export const useDojoStore = createDojoStore(); * * @param props.sdk - The Dojo SDK instance configured with the game schema */ -function App({ sdk }: { sdk: SDK }) { +function App({ sdk }: { sdk: SDK }) { const { - account, setup: { client }, } = useDojo(); + const { account } = useAccount(); const state = useDojoStore((state) => state); const entities = useDojoStore((state) => state.entities); const { spawn } = useSystemCalls(); - const entityId = useMemo( - () => getEntityIdFromKeys([BigInt(account?.account.address)]), - [account?.account.address] - ); + const entityId = useMemo(() => { + if (account) { + return getEntityIdFromKeys([BigInt(account.address)]); + } + return BigInt(0); + }, [account]); useEffect(() => { let unsubscribe: (() => void) | undefined; - const subscribe = async () => { + const subscribe = async (account: AccountInterface) => { const subscription = await sdk.subscribeEntityQuery({ - query: new QueryBuilder() + query: new QueryBuilder() .namespace("dojo_starter", (n) => n .entity("Moves", (e) => e.eq( "player", - addAddressPadding(account.account.address) + addAddressPadding(account.address) ) ) .entity("Position", (e) => e.is( "player", - addAddressPadding(account.account.address) + addAddressPadding(account.address) ) ) ) @@ -66,7 +80,6 @@ function App({ sdk }: { sdk: SDK }) { response.data && response.data[0].entityId !== "0x0" ) { - console.log("subscribed", response.data[0]); state.updateEntity(response.data[0]); } }, @@ -75,25 +88,27 @@ function App({ sdk }: { sdk: SDK }) { unsubscribe = () => subscription.cancel(); }; - subscribe(); + if (account) { + subscribe(account); + } return () => { if (unsubscribe) { unsubscribe(); } }; - }, [sdk, account?.account.address]); + }, [sdk, account]); useEffect(() => { - const fetchEntities = async () => { + const fetchEntities = async (account: AccountInterface) => { try { await sdk.getEntities({ - query: new QueryBuilder() + query: new QueryBuilder() .namespace("dojo_starter", (n) => n.entity("Moves", (e) => e.eq( "player", - addAddressPadding(account.account.address) + addAddressPadding(account.address) ) ) ) @@ -116,53 +131,18 @@ function App({ sdk }: { sdk: SDK }) { } }; - fetchEntities(); - }, [sdk, account?.account.address]); + if (account) { + fetchEntities(account); + } + }, [sdk, account]); - const moves = useModel(entityId, Models.Moves); - const position = useModel(entityId, Models.Position); + const moves = useModel(entityId as string, ModelsMapping.Moves); + const position = useModel(entityId as string, ModelsMapping.Position); return (
- - -
-
{`Burners Deployed: ${account.count}`}
-
- - -
- -
+
@@ -185,7 +165,9 @@ function App({ sdk }: { sdk: SDK }) { : "Need to Spawn"}
- {moves && moves.last_direction} + {moves && moves.last_direction.isSome() + ? moves.last_direction.unwrap() + : ""}
@@ -194,22 +176,22 @@ function App({ sdk }: { sdk: SDK }) {
{[ { - direction: "Up" as const, + direction: Direction.Up, label: "↑", col: "col-start-2", }, { - direction: "Left" as const, + direction: Direction.Left, label: "←", col: "col-start-1", }, { - direction: "Right" as const, + direction: Direction.Right, label: "→", col: "col-start-3", }, { - direction: "Down" as const, + direction: Direction.Down, label: "↓", col: "col-start-2", }, @@ -218,10 +200,10 @@ function App({ sdk }: { sdk: SDK }) { className={`${col} h-12 w-12 bg-gray-600 rounded-full shadow-md active:shadow-inner active:bg-gray-500 focus:outline-none text-2xl font-bold text-gray-200`} key={direction} onClick={async () => { - await client.actions.move({ - account: account.account, - direction: { type: direction }, - }); + await client.actions.move( + account!, + direction + ); }} > {label} @@ -265,6 +247,10 @@ function App({ sdk }: { sdk: SDK }) { entity.models.dojo_starter.Position; const moves = entity.models.dojo_starter.Moves; + const lastDirection = + moves?.last_direction.isSome() + ? moves.last_direction.unwrap() + : "N/A"; return ( }) { "N/A"} - {moves?.last_direction ?? "N/A"} + {lastDirection} {moves?.remaining ?? "N/A"} @@ -300,6 +286,9 @@ function App({ sdk }: { sdk: SDK }) {
+ + {/* // Here sdk is passed as props but this can be done via contexts */} +
); diff --git a/examples/example-vite-react-sdk/src/DojoContext.tsx b/examples/example-vite-react-sdk/src/DojoContext.tsx index 272e398b..157bd4b2 100644 --- a/examples/example-vite-react-sdk/src/DojoContext.tsx +++ b/examples/example-vite-react-sdk/src/DojoContext.tsx @@ -7,7 +7,7 @@ import { import { Account } from "starknet"; import { dojoConfig } from "../dojoConfig"; import { DojoProvider } from "@dojoengine/core"; -import { client } from "./contracts.gen"; +import { setupWorld } from "./typescript/contracts.gen"; /** * Interface defining the shape of the Dojo context. @@ -16,7 +16,7 @@ interface DojoContextType { /** The master account used for administrative operations */ masterAccount: Account; /** The Dojo client instance */ - client: ReturnType; + client: ReturnType; /** The current burner account information */ account: BurnerAccount; } @@ -58,7 +58,7 @@ export const DojoContextProvider = ({ dojoConfig.masterPrivateKey, "1" ), - [] + [dojoProvider.provider] ); const burnerManagerData = useBurnerManager({ burnerManager }); @@ -67,7 +67,7 @@ export const DojoContextProvider = ({ >; - -export function client(provider: DojoProvider) { - // System definitions for `dojo_starter-actions` contract - function actions() { - const contract_name = "actions"; - - // Call the `spawn` system with the specified Account and calldata - const spawn = async (props: { account: Account }) => { - try { - return await provider.execute( - props.account, - { - contractName: contract_name, - entrypoint: "spawn", - calldata: [], - }, - "dojo_starter" - ); - } catch (error) { - console.error("Error executing spawn:", error); - throw error; - } - }; - - // Call the `move` system with the specified Account and calldata - const move = async (props: { account: Account; direction: any }) => { - try { - return await provider.execute( - props.account, - { - contractName: contract_name, - entrypoint: "move", - calldata: [ - ["None", "Left", "Right", "Up", "Down"].indexOf( - props.direction.type - ), - ], - }, - "dojo_starter" - ); - } catch (error) { - console.error("Error executing spawn:", error); - throw error; - } - }; - - return { - spawn, - move, - }; - } - - return { - actions: actions(), - }; -} diff --git a/examples/example-vite-react-sdk/src/historical-events.tsx b/examples/example-vite-react-sdk/src/historical-events.tsx new file mode 100644 index 00000000..ecdccf60 --- /dev/null +++ b/examples/example-vite-react-sdk/src/historical-events.tsx @@ -0,0 +1,101 @@ +import { SDK } from "@dojoengine/sdk"; +import { useAccount } from "@starknet-react/core"; +import { SchemaType } from "./typescript/models.gen"; +import { AccountInterface, addAddressPadding } from "starknet"; +import { useEffect, useState } from "react"; + +export function HistoricalEvents({ sdk }: { sdk: SDK }) { + const { account } = useAccount(); + const [events, setEvents] = useState([]); + const [unsubscribe, setSubscription] = useState(null); + + useEffect(() => { + async function getHistoricalEvents(account: AccountInterface) { + try { + const e = await sdk.getEventMessages({ + // query: { + // event_messages_historical: { + // Moved: { + // $: { where: { player: { $eq: addAddressPadding(account.address) } } } + // } + // } + // }, + query: { entityIds: [addAddressPadding(account.address)] }, + callback: () => {}, + historical: true, + }); + setEvents(e); + } catch (error) { + setEvents([]); + console.error(error); + } + } + + if (account) { + getHistoricalEvents(account); + } + }, [account, setEvents]); + + useEffect(() => { + async function subscribeHistoricalEvent(account: AccountInterface) { + try { + const s = await sdk.subscribeEventQuery({ + // query: { + // event_messages_historical: { + // Moved: { + // $: { where: { player: { $eq: addAddressPadding(account.address) } } } + // } + // } + // }, + query: { entityIds: [addAddressPadding(account.address)] }, + callback: (resp, error) => { + console.log(resp, error); + }, + historical: true, + }); + setSubscription(s); + } catch (error) { + setEvents([]); + if (unsubscribe) { + unsubscribe(); + } + console.error(error); + } + } + + if (account) { + subscribeHistoricalEvent(account); + } + }, [account, setEvents]); + + if (!account) { + return ( +
+

Please connect your wallet

+
+ ); + } + return ( +
+

Player Events :

+ {events.map((e, key) => { + return ; + })} +
+ ); +} +function Event({ event }) { + if (!event) return null; + const player = event.models?.dojo_starter?.Moved?.player; + const direction = event.models?.dojo_starter?.Moved?.direction; + + return ( +
+
{event.entityId}
+
+
Player: {player}
+
Direction: {direction}
+
+
+ ); +} diff --git a/examples/example-vite-react-sdk/src/main.tsx b/examples/example-vite-react-sdk/src/main.tsx index d1bf9cbe..7b9d811f 100644 --- a/examples/example-vite-react-sdk/src/main.tsx +++ b/examples/example-vite-react-sdk/src/main.tsx @@ -5,10 +5,11 @@ import App from "./App.tsx"; import "./index.css"; import { init } from "@dojoengine/sdk"; -import { Schema, schema } from "./bindings.ts"; +import { SchemaType, schema } from "./typescript/models.gen.ts"; import { dojoConfig } from "../dojoConfig.ts"; import { DojoContextProvider } from "./DojoContext.tsx"; import { setupBurnerManager } from "@dojoengine/create-burner"; +import StarknetProvider from "./starknet-provider.tsx"; /** * Initializes and bootstraps the Dojo application. @@ -17,7 +18,7 @@ import { setupBurnerManager } from "@dojoengine/create-burner"; * @throws {Error} If initialization fails */ async function main() { - const sdk = await init( + const sdk = await init( { client: { rpcUrl: dojoConfig.rpcUrl, @@ -40,7 +41,9 @@ async function main() { - + + + ); diff --git a/examples/example-vite-react-sdk/src/starknet-provider.tsx b/examples/example-vite-react-sdk/src/starknet-provider.tsx new file mode 100644 index 00000000..3aaf8ef2 --- /dev/null +++ b/examples/example-vite-react-sdk/src/starknet-provider.tsx @@ -0,0 +1,33 @@ +import type { PropsWithChildren } from "react"; +import { Chain, mainnet } from "@starknet-react/chains"; +import { jsonRpcProvider, StarknetConfig, voyager } from "@starknet-react/core"; +import { dojoConfig } from "../dojoConfig"; +import { + predeployedAccounts, + PredeployedAccountsConnector, +} from "@dojoengine/predeployed-connector"; + +let pa: PredeployedAccountsConnector[] = []; +predeployedAccounts({ + rpc: dojoConfig.rpcUrl as string, + id: "katana", + name: "Katana", +}).then((p) => (pa = p)); + +export default function StarknetProvider({ children }: PropsWithChildren) { + const provider = jsonRpcProvider({ + rpc: (chain: Chain) => ({ nodeUrl: dojoConfig.rpcUrl as string }), + }); + + return ( + + {children} + + ); +} diff --git a/examples/example-vite-react-sdk/src/typescript/contracts.gen.ts b/examples/example-vite-react-sdk/src/typescript/contracts.gen.ts new file mode 100644 index 00000000..4e050947 --- /dev/null +++ b/examples/example-vite-react-sdk/src/typescript/contracts.gen.ts @@ -0,0 +1,66 @@ +import { DojoProvider } from "@dojoengine/core"; +import { + Account, + AccountInterface, + BigNumberish, + CairoOption, + CairoCustomEnum, + ByteArray, +} from "starknet"; +import * as models from "./models.gen"; + +export function setupWorld(provider: DojoProvider) { + const build_actions_move_calldata = (direction: models.Direction) => { + return { + contractName: "actions", + entrypoint: "move", + calldata: [direction], + }; + }; + + const actions_move = async ( + snAccount: Account | AccountInterface, + direction: models.Direction + ) => { + try { + return await provider.execute( + snAccount, + build_actions_move_calldata(direction), + "dojo_starter" + ); + } catch (error) { + console.error(error); + throw error; + } + }; + + const build_actions_spawn_calldata = () => { + return { + contractName: "actions", + entrypoint: "spawn", + calldata: [], + }; + }; + + const actions_spawn = async (snAccount: Account | AccountInterface) => { + try { + return await provider.execute( + snAccount, + build_actions_spawn_calldata(), + "dojo_starter" + ); + } catch (error) { + console.error(error); + throw error; + } + }; + + return { + actions: { + move: actions_move, + buildMoveCalldata: build_actions_move_calldata, + spawn: actions_spawn, + buildSpawnCalldata: build_actions_spawn_calldata, + }, + }; +} diff --git a/examples/example-vite-react-sdk/src/typescript/models.gen.ts b/examples/example-vite-react-sdk/src/typescript/models.gen.ts new file mode 100644 index 00000000..3208eca1 --- /dev/null +++ b/examples/example-vite-react-sdk/src/typescript/models.gen.ts @@ -0,0 +1,142 @@ +import type { SchemaType as ISchemaType } from "@dojoengine/sdk"; + +import { CairoOption, CairoOptionVariant, BigNumberish } from "starknet"; + +type WithFieldOrder = T & { fieldOrder: string[] }; + +// Type definition for `dojo_starter::models::DirectionsAvailable` struct +export interface DirectionsAvailable { + player: string; + directions: Array; +} + +// Type definition for `dojo_starter::models::DirectionsAvailableValue` struct +export interface DirectionsAvailableValue { + directions: Array; +} + +// Type definition for `dojo_starter::models::Moves` struct +export interface Moves { + player: string; + remaining: BigNumberish; + last_direction: CairoOption; + can_move: boolean; +} + +// Type definition for `dojo_starter::models::MovesValue` struct +export interface MovesValue { + remaining: BigNumberish; + last_direction: CairoOption; + can_move: boolean; +} + +// Type definition for `dojo_starter::models::Position` struct +export interface Position { + player: string; + vec: Vec2; +} + +// Type definition for `dojo_starter::models::PositionValue` struct +export interface PositionValue { + vec: Vec2; +} + +// Type definition for `dojo_starter::models::Vec2` struct +export interface Vec2 { + x: BigNumberish; + y: BigNumberish; +} + +// Type definition for `dojo_starter::systems::actions::actions::Moved` struct +export interface Moved { + player: string; + direction: Direction; +} + +// Type definition for `dojo_starter::systems::actions::actions::MovedValue` struct +export interface MovedValue { + direction: Direction; +} + +// Type definition for `dojo_starter::models::Direction` enum +export enum Direction { + Left, + Right, + Up, + Down, +} + +export interface SchemaType extends ISchemaType { + dojo_starter: { + DirectionsAvailable: WithFieldOrder; + DirectionsAvailableValue: WithFieldOrder; + Moves: WithFieldOrder; + MovesValue: WithFieldOrder; + Position: WithFieldOrder; + PositionValue: WithFieldOrder; + Vec2: WithFieldOrder; + Moved: WithFieldOrder; + MovedValue: WithFieldOrder; + }; +} +export const schema: SchemaType = { + dojo_starter: { + DirectionsAvailable: { + fieldOrder: ["player", "directions"], + player: "", + directions: [Direction.Left], + }, + DirectionsAvailableValue: { + fieldOrder: ["directions"], + directions: [Direction.Left], + }, + Moves: { + fieldOrder: ["player", "remaining", "last_direction", "can_move"], + player: "", + remaining: 0, + last_direction: new CairoOption(CairoOptionVariant.None), + can_move: false, + }, + MovesValue: { + fieldOrder: ["remaining", "last_direction", "can_move"], + remaining: 0, + last_direction: new CairoOption(CairoOptionVariant.None), + can_move: false, + }, + Position: { + fieldOrder: ["player", "vec"], + player: "", + vec: { fieldOrder: ["x", "y"], x: 0, y: 0 }, + }, + PositionValue: { + fieldOrder: ["vec"], + vec: { fieldOrder: ["x", "y"], x: 0, y: 0 }, + }, + Vec2: { + fieldOrder: ["x", "y"], + x: 0, + y: 0, + }, + Moved: { + fieldOrder: ["player", "direction"], + player: "", + direction: Direction.Left, + }, + MovedValue: { + fieldOrder: ["direction"], + direction: Direction.Left, + }, + }, +}; +export enum ModelsMapping { + Direction = "dojo_starter-Direction", + DirectionsAvailable = "dojo_starter-DirectionsAvailable", + DirectionsAvailableValue = "dojo_starter-DirectionsAvailableValue", + Moves = "dojo_starter-Moves", + MovesValue = "dojo_starter-MovesValue", + Position = "dojo_starter-Position", + PositionValue = "dojo_starter-PositionValue", + Vec2 = "dojo_starter-Vec2", + Moved = "dojo_starter-Moved", + MovedValue = "dojo_starter-MovedValue", +} diff --git a/examples/example-vite-react-sdk/src/useModel.tsx b/examples/example-vite-react-sdk/src/useModel.tsx index 228e4cc7..15c8dc5f 100644 --- a/examples/example-vite-react-sdk/src/useModel.tsx +++ b/examples/example-vite-react-sdk/src/useModel.tsx @@ -1,5 +1,6 @@ +import { BigNumberish } from "starknet"; import { useDojoStore } from "./App"; -import { Schema } from "./bindings"; +import { SchemaType } from "./typescript/models.gen.ts"; /** * Custom hook to retrieve a specific model for a given entityId within a specified namespace. @@ -8,17 +9,17 @@ import { Schema } from "./bindings"; * @param model - The model to retrieve, specified as a string in the format "namespace-modelName". * @returns The model structure if found, otherwise undefined. */ -function useModel( - entityId: string, - model: `${N}-${M}` -): Schema[N][M] | undefined { +function useModel< + N extends keyof SchemaType, + M extends keyof SchemaType[N] & string, +>(entityId: BigNumberish, model: `${N}-${M}`): SchemaType[N][M] | undefined { const [namespace, modelName] = model.split("-") as [N, M]; // Select only the specific model data for the given entityId const modelData = useDojoStore( (state) => state.entities[entityId]?.models?.[namespace]?.[modelName] as - | Schema[N][M] + | SchemaType[N][M] | undefined ); diff --git a/examples/example-vite-react-sdk/src/useSystemCalls.ts b/examples/example-vite-react-sdk/src/useSystemCalls.ts index a8557a8d..7887972e 100644 --- a/examples/example-vite-react-sdk/src/useSystemCalls.ts +++ b/examples/example-vite-react-sdk/src/useSystemCalls.ts @@ -2,6 +2,7 @@ import { getEntityIdFromKeys } from "@dojoengine/utils"; import { useDojoStore } from "./App"; import { useDojo } from "./useDojo"; import { v4 as uuidv4 } from "uuid"; +import { useAccount } from "@starknet-react/core"; /** * Custom hook to handle system calls and state management in the Dojo application. @@ -15,15 +16,15 @@ export const useSystemCalls = () => { const { setup: { client }, - account: { account }, } = useDojo(); + const { account } = useAccount(); /** * Generates a unique entity ID based on the current account address. * @returns {string} The generated entity ID */ const generateEntityId = () => { - return getEntityIdFromKeys([BigInt(account?.address)]); + return getEntityIdFromKeys([BigInt(account!.address)]); }; /** @@ -52,7 +53,7 @@ export const useSystemCalls = () => { try { // Execute the spawn action from the client - await client.actions.spawn({ account }); + await client.actions.spawn(account!); // Wait for the entity to be updated with the new state await state.waitForEntityChange(entityId, (entity) => { diff --git a/examples/example-vite-react-sdk/src/wallet-account.tsx b/examples/example-vite-react-sdk/src/wallet-account.tsx new file mode 100644 index 00000000..5bdf445d --- /dev/null +++ b/examples/example-vite-react-sdk/src/wallet-account.tsx @@ -0,0 +1,68 @@ +import { + Connector, + useAccount, + useConnect, + useDisconnect, +} from "@starknet-react/core"; +import { useCallback, useState } from "react"; + +export function WalletAccount() { + const { connectAsync, connectors } = useConnect(); + const { address } = useAccount(); + const { disconnect } = useDisconnect(); + const [pendingConnectorId, setPendingConnectorId] = useState< + string | undefined + >(undefined); + + const connect = useCallback( + async (connector: Connector) => { + setPendingConnectorId(connector.id); + try { + await connectAsync({ connector }); + } catch (error) { + console.error(error); + } + setPendingConnectorId(undefined); + }, + [connectAsync] + ); + + function isWalletConnecting(connectorId: string) { + return pendingConnectorId === connectorId; + } + + if (undefined !== address) { + return ( +
+
+ +
+
+ ); + } + + return ( +
+

Connect Wallet

+
+ {} + {connectors.map((connector) => ( + + ))} +
+
+ ); +} diff --git a/packages/predeployed-connector/src/index.ts b/packages/predeployed-connector/src/index.ts index e04aacdf..de8e613d 100644 --- a/packages/predeployed-connector/src/index.ts +++ b/packages/predeployed-connector/src/index.ts @@ -1,4 +1,4 @@ -import { Connector } from "@starknet-react/core"; +import { InjectedConnector } from "@starknet-react/core"; import { Account, AccountInterface, @@ -30,65 +30,39 @@ export type PredeployedAccountsConnectorOptions = { id: string; name: string; rpc: string; - account: WalletAccount; + account: PredeployedWalletAccount; }; export type PredeployedAccount = { id: string; name: string; - account: WalletAccount; + account: PredeployedWalletAccount; }; -type ConnectorIcons = { dark: string; light: string }; +// type ConnectorIcons = { dark: string; light: string }; const icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAABkyAAAZMgGvFqWRAAAAB3RJTUUH6AkEFwsj7EvbJQAAAAZiS0dEAP8A/wD/oL2nkwAAK45JREFUeNrt3XmUXVWBqPE42+3Qj5hQ995zb1WlUqkkVZlIAhnJPIKAIogICEGGtlugFVBaxAbsVgw+FWlooEFtRFAmZRbClDAlICAg4MTQDY4MAiIy6X5nX8JrQQippKruOef+vrW+Zf9hr2XOsPd3T52z96BBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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kn3mfaUk+VAcY00zyDaTJr0pvVj3SC/au924JLnB3lWf+C3qg5w+EXhPOUkuTi/k593MJPmaPl8uly9Kx87t/OJHIUiSpFqqVD7jqQBJvqJ3p7/2D4tjpRkDRY6BrjQGDi6/sOXwc258kk1oHPuuiWNhHBPNDGg6Wlpa3pZe/PMrlcrh6Y1wXnzZxcBAsoDeG8e4uFZ/HPPi2GcGAF5GfaXBUqmnVK1uVS6X90n9bOp/pTfQuakr4h7X6X/+qJwk95BkQ41j0Qtj0or6GJWOVekPmiPj2BXHsDiWxTHNyA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATcP/A/VYuD9l6UjwAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDI0LTA5LTA0VDIzOjExOjM1KzAwOjAw9BAQcQAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyNC0wOS0wNFQyMzoxMTozNSswMDowMIVNqM0AAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAV3pUWHRSYXcgcHJvZmlsZSB0eXBlIGlwdGMAAHic4/IMCHFWKCjKT8vMSeVSAAMjCy5jCxMjE0uTFAMTIESANMNkAyOzVCDL2NTIxMzEHMQHy4BIoEouAOoXEXTyQjWVAAAAAElFTkSuQmCC"; -// @ts-ignore -export class PredeployedAccountsConnector extends Connector { +export class PredeployedAccountsConnector extends InjectedConnector { constructor(private options: PredeployedAccountsConnectorOptions) { - super(); + super({ options: { id: options.id, name: options.name } }); } - get id(): string { - return this.options.id; - } - get name(): string { - return this.options.name; - } - get icon(): ConnectorIcons { - return { - dark: icon, - light: icon, - }; - } available(): boolean { return !!this.options.account; } - ready(): Promise { - return new Promise((resolve) => { - resolve(!!this.options.account); - }); - } - disconnect(): Promise { - throw new Error("Method not implemented."); - } - async account(): Promise { - return this.options.account; - } - async chainId(): Promise { - // @ts-ignore - return await this.options.account.getChainId(); - } - async connect(): Promise { - return this.options.account; - } } class PredeployedWalletAccount extends WalletAccount { + private _inner: PredeployedWallet; constructor(base: any, rpc: string) { super({ nodeUrl: rpc }, base); + this._inner = base; } + request: RequestFn = async (call) => { + return await this._inner.request(call); + }; } class PredeployedWallet implements StarknetWindowObject { @@ -105,6 +79,10 @@ class PredeployedWallet implements StarknetWindowObject { private account: AccountInterface ) { this.subscriptions = []; + + if (typeof window !== "undefined") { + (window as any)[`starknet_${id}`] = this; + } } // @ts-ignore @@ -212,11 +190,6 @@ class PredeployedWallet implements StarknetWindowObject { } }; - // async request(call): RequestFn { - // console.log(call); - // return []; - // }; - on: WalletEventListener = ( event: E, handler: WalletEventHandlers[E] diff --git a/packages/sdk/src/__tests__/parseEntities.test.ts b/packages/sdk/src/__tests__/parseEntities.test.ts index 38be6795..72333a36 100644 --- a/packages/sdk/src/__tests__/parseEntities.test.ts +++ b/packages/sdk/src/__tests__/parseEntities.test.ts @@ -222,7 +222,8 @@ describe("parseEntities", () => { }; const res = parseEntities(toriiResult); const expected = new CairoOption(CairoOptionVariant.Some, 1734537235); - expect(res[0]?.models?.onchain_dash?.CallerCounter?.timestamp).toEqual( + // @ts-ignore can be undefined + expect(res[0].models.onchain_dash.CallerCounter.timestamp).toEqual( expected ); }); @@ -276,7 +277,8 @@ describe("parseEntities", () => { }; const res = parseEntities(toriiResult); const expected = new CairoCustomEnum({ Predefined: "Dojo" }); - expect(res[0]?.models?.onchain_dash?.Theme?.value).toEqual(expected); + // @ts-ignore can be undefined + expect(res[0].models.onchain_dash.Theme.value).toEqual(expected); }); it("should parse enum with nested struct", () => { @@ -333,6 +335,7 @@ describe("parseEntities", () => { "0x0000000000000000000000000000000000000000637573746f6d5f636c617373", }, }); - expect(res[0]?.models?.onchain_dash?.Theme?.value).toEqual(expected); + // @ts-ignore can be undefined + expect(res[0].models.onchain_dash.Theme.value).toEqual(expected); }); }); diff --git a/packages/sdk/src/convertQuerytoClause.ts b/packages/sdk/src/convertQuerytoClause.ts index d1390155..60ba5aaa 100644 --- a/packages/sdk/src/convertQuerytoClause.ts +++ b/packages/sdk/src/convertQuerytoClause.ts @@ -19,7 +19,16 @@ export function convertQueryToClause( const clauses: torii.Clause[] = []; for (const [namespace, models] of Object.entries(query)) { - if (namespace === "entityIds") continue; // Skip entityIds + if (namespace === "entityIds") { + return { + // match every models that has at least input keys as key + Keys: { + keys: [...models], + pattern_matching: "VariableLen", + models: [], + }, + }; + } if (models && typeof models === "object") { const modelClauses = processModels(namespace, models, schema); diff --git a/packages/sdk/src/getEventMessages.ts b/packages/sdk/src/getEventMessages.ts index ba8977c7..046b5f67 100644 --- a/packages/sdk/src/getEventMessages.ts +++ b/packages/sdk/src/getEventMessages.ts @@ -2,7 +2,13 @@ import * as torii from "@dojoengine/torii-client"; import { convertQueryToClause } from "./convertQuerytoClause"; import { parseEntities } from "./parseEntities"; -import { QueryType, SchemaType, StandardizedQueryResult } from "./types"; +import { + ParsedEntity, + QueryType, + SchemaType, + StandardizedQueryResult, +} from "./types"; +import { parseHistoricalEvents } from "./parseHistoricalEvents"; /** * Fetches event messages from the Torii client based on the provided query. @@ -31,7 +37,7 @@ export async function getEventMessages( query: QueryType, schema: T, callback: (response: { - data?: StandardizedQueryResult; + data?: StandardizedQueryResult | StandardizedQueryResult[]; error?: Error; }) => void, orderBy: torii.OrderBy[] = [], @@ -40,8 +46,9 @@ export async function getEventMessages( offset: number = 0, // Default offset options?: { logging?: boolean }, // Logging option historical?: boolean -): Promise> { +): Promise | StandardizedQueryResult[]> { const clause = convertQueryToClause(query, schema); + const isHistorical = !!historical; let cursor = offset; let continueFetching = true; @@ -54,14 +61,14 @@ export async function getEventMessages( order_by: orderBy, entity_models: entityModels, clause, - dont_include_hashed_keys: false, + dont_include_hashed_keys: true, entity_updated_after: 0, }; try { const entities = await client.getEventMessages( toriiQuery, - historical ?? true + isHistorical ); if (options?.logging) { @@ -70,7 +77,9 @@ export async function getEventMessages( Object.assign(allEntities, entities); - const parsedEntities = parseEntities(allEntities); + const parsedEntities = isHistorical + ? parseHistoricalEvents(allEntities, options) + : parseEntities(allEntities, options); callback({ data: parsedEntities }); @@ -91,5 +100,8 @@ export async function getEventMessages( if (options?.logging) { console.log("All fetched entities:", allEntities); } - return parseEntities(allEntities); + + return isHistorical + ? parseHistoricalEvents(allEntities, options) + : parseEntities(allEntities, options); } diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 99926bab..1305db15 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -92,7 +92,7 @@ export async function init( * Fetches event messages based on the provided query. * * @param {GetParams} params - Parameters object - * @returns {Promise>} - A promise that resolves to the standardized query result. + * @returns {Promise | StandardizedQueryResult[]>} - A promise that resolves to the standardized query result. */ getEventMessages: ({ query, diff --git a/packages/sdk/src/parseHistoricalEvents.ts b/packages/sdk/src/parseHistoricalEvents.ts new file mode 100644 index 00000000..7bf5ede7 --- /dev/null +++ b/packages/sdk/src/parseHistoricalEvents.ts @@ -0,0 +1,52 @@ +import * as torii from "@dojoengine/torii-client"; + +import { ParsedEntity, SchemaType, StandardizedQueryResult } from "./types"; +import { parseEntities } from "./parseEntities"; + +/** + * Parses historical events returned by torii + * + * @template T - The schema type. + * @param {torii.Entities} entities - The collection of entities to parse. + * @param {{ logging?: boolean }} [options] - Optional settings for logging. + * @returns {StandardizedQueryResult} - The parsed entities in a standardized query result format. + * + * @example + * const parsedResult = parseHistoricalEvents(entities, { logging: true }); + * console.log(parsedResult); + */ +export function parseHistoricalEvents( + entities: torii.Entities, + options?: { logging?: boolean } +): StandardizedQueryResult[] { + // Events come from torii flagged as "dojo_starter-Moved-idx" + let events: torii.Entities[] = []; + for (const entityId in entities) { + const entityData = entities[entityId]; + const keys = Object.keys(entityData); + + //sort keys to preserve order given by torii + const sortedKeys = keys.sort((a, b) => { + // Extract the last number from each string using regex + const getLastNumber = (str: string) => { + const match = str.match(/-(\d+)$/); + return match ? parseInt(match[1]) : 0; + }; + + return getLastNumber(a) - getLastNumber(b); + }); + + for (const model of sortedKeys) { + const modelData = entityData[model]; + const modelNameSplit = model.split("-"); + modelNameSplit.pop(); + // event at index 0 does not have index thus, we take modelName as is + const modelName = + modelNameSplit.length > 1 ? modelNameSplit.join("-") : model; + + events = [...events, { [entityId]: { [modelName]: modelData } }]; + } + } + + return events.map((e) => parseEntities(e, options)); +} diff --git a/packages/sdk/src/subscribeEventQuery.ts b/packages/sdk/src/subscribeEventQuery.ts index c994797b..e353baf2 100644 --- a/packages/sdk/src/subscribeEventQuery.ts +++ b/packages/sdk/src/subscribeEventQuery.ts @@ -7,6 +7,7 @@ import { StandardizedQueryResult, SubscriptionQueryType, } from "./types"; +import { parseHistoricalEvents } from "./parseHistoricalEvents"; /** * Subscribes to event messages based on the provided query and invokes the callback with the updated data. @@ -33,21 +34,23 @@ export async function subscribeEventQuery( query: SubscriptionQueryType, schema: T, callback?: (response: { - data?: StandardizedQueryResult; + data?: StandardizedQueryResult | StandardizedQueryResult[]; error?: Error; }) => void, options?: { logging?: boolean }, historical?: boolean ): Promise { + const isHistorical = !!historical; return client.onEventMessageUpdated( convertQueryToEntityKeyClauses(query, schema), - historical ?? true, + isHistorical, (entityId: string, entityData: any) => { try { if (callback) { - const parsedData = parseEntities({ - [entityId]: entityData, - }); + const data = { [entityId]: entityData }; + const parsedData = isHistorical + ? parseHistoricalEvents(data, options) + : parseEntities(data, options); if (options?.logging) { console.log("Parsed entity data:", parsedData); } diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index c29349eb..62f10d79 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -300,7 +300,7 @@ export interface SDK { */ getEventMessages: ( params: GetParams - ) => Promise>; + ) => Promise | StandardizedQueryResult[]>; generateTypedData: >( primaryType: string, message: M, @@ -387,7 +387,7 @@ export interface SubscribeParams { query: SubscriptionQueryType; // The callback function to handle the response. callback: (response: { - data?: StandardizedQueryResult; + data?: StandardizedQueryResult | StandardizedQueryResult[]; error?: Error; }) => void; // Optional settings. @@ -401,7 +401,7 @@ export interface GetParams { query: QueryType; // The callback function to handle the response. callback: (response: { - data?: StandardizedQueryResult; + data?: StandardizedQueryResult | StandardizedQueryResult[]; error?: Error; }) => void; // The order to sort the entities by. diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b3fae88a..98d3ad07 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -671,6 +671,9 @@ importers: '@dojoengine/create-burner': specifier: workspace:* version: link:../../packages/create-burner + '@dojoengine/predeployed-connector': + specifier: workspace:* + version: link:../../packages/predeployed-connector '@dojoengine/sdk': specifier: workspace:* version: link:../../packages/sdk @@ -683,6 +686,12 @@ importers: '@dojoengine/utils': specifier: workspace:* version: link:../../packages/utils + '@starknet-react/chains': + specifier: 'catalog:' + version: 3.1.0 + '@starknet-react/core': + specifier: 'catalog:' + version: 3.6.2(get-starknet-core@4.0.0)(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(typescript@5.7.2) '@types/uuid': specifier: ^10.0.0 version: 10.0.0 @@ -25730,8 +25739,8 @@ snapshots: webauthn-p256@0.0.10: dependencies: - '@noble/curves': 1.6.0 - '@noble/hashes': 1.5.0 + '@noble/curves': 1.7.0 + '@noble/hashes': 1.6.1 webgl-constants@1.1.1: {} From ffc30b41671fd29c7e230635ab6c254c198f6c60 Mon Sep 17 00:00:00 2001 From: Valentin Dosimont Date: Mon, 6 Jan 2025 07:11:05 +0100 Subject: [PATCH 2/3] fix: build-examples --- examples/example-vite-react-sdk/src/App.tsx | 48 ++++++++++--------- .../src/historical-events.tsx | 24 +++++----- .../src/starknet-provider.tsx | 4 +- .../src/typescript/contracts.gen.ts | 9 +--- .../src/typescript/models.gen.ts | 4 +- .../example-vite-react-sdk/src/useModel.tsx | 6 +-- .../tsconfig.app.tsbuildinfo | 2 +- packages/predeployed-connector/src/index.ts | 6 ++- packages/sdk/src/types.ts | 22 ++++----- 9 files changed, 63 insertions(+), 62 deletions(-) diff --git a/examples/example-vite-react-sdk/src/App.tsx b/examples/example-vite-react-sdk/src/App.tsx index 4ea5c014..89ddc8a4 100644 --- a/examples/example-vite-react-sdk/src/App.tsx +++ b/examples/example-vite-react-sdk/src/App.tsx @@ -1,12 +1,12 @@ import { useEffect, useMemo } from "react"; -import { QueryBuilder, SDK, createDojoStore } from "@dojoengine/sdk"; -import { getEntityIdFromKeys } from "@dojoengine/utils"; import { - AccountInterface, - addAddressPadding, - CairoOption, - CairoOptionVariant, -} from "starknet"; + ParsedEntity, + QueryBuilder, + SDK, + createDojoStore, +} from "@dojoengine/sdk"; +import { getEntityIdFromKeys } from "@dojoengine/utils"; +import { AccountInterface, addAddressPadding } from "starknet"; import { Direction, @@ -16,7 +16,7 @@ import { import { useDojo } from "./useDojo.tsx"; import useModel from "./useModel.tsx"; import { useSystemCalls } from "./useSystemCalls.ts"; -import { useAccount, useConnect } from "@starknet-react/core"; +import { useAccount } from "@starknet-react/core"; import { WalletAccount } from "./wallet-account.tsx"; import { HistoricalEvents } from "./historical-events.tsx"; @@ -70,17 +70,14 @@ function App({ sdk }: { sdk: SDK }) { ) ) .build(), - callback: (response) => { - if (response.error) { - console.error( - "Error setting up entity sync:", - response.error - ); + callback: ({ error, data }) => { + if (error) { + console.error("Error setting up entity sync:", error); } else if ( - response.data && - response.data[0].entityId !== "0x0" + data && + (data[0] as ParsedEntity).entityId !== "0x0" ) { - state.updateEntity(response.data[0]); + state.updateEntity(data[0] as ParsedEntity); } }, }); @@ -122,7 +119,9 @@ function App({ sdk }: { sdk: SDK }) { return; } if (resp.data) { - state.setEntities(resp.data); + state.setEntities( + resp.data as ParsedEntity[] + ); } }, }); @@ -248,8 +247,8 @@ function App({ sdk }: { sdk: SDK }) { const moves = entity.models.dojo_starter.Moves; const lastDirection = - moves?.last_direction.isSome() - ? moves.last_direction.unwrap() + moves?.last_direction?.isSome() + ? moves.last_direction?.unwrap() : "N/A"; return ( @@ -264,10 +263,12 @@ function App({ sdk }: { sdk: SDK }) { {position?.player ?? "N/A"} - {position?.vec?.x ?? "N/A"} + {position?.vec?.x.toString() ?? + "N/A"} - {position?.vec?.y ?? "N/A"} + {position?.vec?.y.toString() ?? + "N/A"} {moves?.can_move?.toString() ?? @@ -277,7 +278,8 @@ function App({ sdk }: { sdk: SDK }) { {lastDirection} - {moves?.remaining ?? "N/A"} + {moves?.remaining?.toString() ?? + "N/A"} ); diff --git a/examples/example-vite-react-sdk/src/historical-events.tsx b/examples/example-vite-react-sdk/src/historical-events.tsx index ecdccf60..f49a3c73 100644 --- a/examples/example-vite-react-sdk/src/historical-events.tsx +++ b/examples/example-vite-react-sdk/src/historical-events.tsx @@ -1,13 +1,14 @@ -import { SDK } from "@dojoengine/sdk"; +import { ParsedEntity, SDK } from "@dojoengine/sdk"; import { useAccount } from "@starknet-react/core"; import { SchemaType } from "./typescript/models.gen"; import { AccountInterface, addAddressPadding } from "starknet"; import { useEffect, useState } from "react"; +import { Subscription } from "@dojoengine/torii-client"; export function HistoricalEvents({ sdk }: { sdk: SDK }) { const { account } = useAccount(); - const [events, setEvents] = useState([]); - const [unsubscribe, setSubscription] = useState(null); + const [events, setEvents] = useState[][]>([]); + const [subscription, setSubscription] = useState(null); useEffect(() => { async function getHistoricalEvents(account: AccountInterface) { @@ -24,6 +25,7 @@ export function HistoricalEvents({ sdk }: { sdk: SDK }) { callback: () => {}, historical: true, }); + // @ts-expect-error FIX: type here setEvents(e); } catch (error) { setEvents([]); @@ -34,7 +36,7 @@ export function HistoricalEvents({ sdk }: { sdk: SDK }) { if (account) { getHistoricalEvents(account); } - }, [account, setEvents]); + }, [account, setEvents, sdk]); useEffect(() => { async function subscribeHistoricalEvent(account: AccountInterface) { @@ -48,16 +50,16 @@ export function HistoricalEvents({ sdk }: { sdk: SDK }) { // } // }, query: { entityIds: [addAddressPadding(account.address)] }, - callback: (resp, error) => { - console.log(resp, error); + callback: ({ data, error }) => { + console.log(data, error); }, historical: true, }); setSubscription(s); } catch (error) { setEvents([]); - if (unsubscribe) { - unsubscribe(); + if (subscription) { + subscription.free(); } console.error(error); } @@ -78,20 +80,20 @@ export function HistoricalEvents({ sdk }: { sdk: SDK }) { return (

Player Events :

- {events.map((e, key) => { + {events.map((e: ParsedEntity[], key) => { return ; })}
); } -function Event({ event }) { +function Event({ event }: { event: ParsedEntity }) { if (!event) return null; const player = event.models?.dojo_starter?.Moved?.player; const direction = event.models?.dojo_starter?.Moved?.direction; return (
-
{event.entityId}
+
{event.entityId.toString()}
Player: {player}
Direction: {direction}
diff --git a/examples/example-vite-react-sdk/src/starknet-provider.tsx b/examples/example-vite-react-sdk/src/starknet-provider.tsx index 3aaf8ef2..50da5139 100644 --- a/examples/example-vite-react-sdk/src/starknet-provider.tsx +++ b/examples/example-vite-react-sdk/src/starknet-provider.tsx @@ -1,5 +1,5 @@ import type { PropsWithChildren } from "react"; -import { Chain, mainnet } from "@starknet-react/chains"; +import { mainnet } from "@starknet-react/chains"; import { jsonRpcProvider, StarknetConfig, voyager } from "@starknet-react/core"; import { dojoConfig } from "../dojoConfig"; import { @@ -16,7 +16,7 @@ predeployedAccounts({ export default function StarknetProvider({ children }: PropsWithChildren) { const provider = jsonRpcProvider({ - rpc: (chain: Chain) => ({ nodeUrl: dojoConfig.rpcUrl as string }), + rpc: () => ({ nodeUrl: dojoConfig.rpcUrl as string }), }); return ( diff --git a/examples/example-vite-react-sdk/src/typescript/contracts.gen.ts b/examples/example-vite-react-sdk/src/typescript/contracts.gen.ts index 4e050947..aeffdc60 100644 --- a/examples/example-vite-react-sdk/src/typescript/contracts.gen.ts +++ b/examples/example-vite-react-sdk/src/typescript/contracts.gen.ts @@ -1,12 +1,5 @@ import { DojoProvider } from "@dojoengine/core"; -import { - Account, - AccountInterface, - BigNumberish, - CairoOption, - CairoCustomEnum, - ByteArray, -} from "starknet"; +import { Account, AccountInterface } from "starknet"; import * as models from "./models.gen"; export function setupWorld(provider: DojoProvider) { diff --git a/examples/example-vite-react-sdk/src/typescript/models.gen.ts b/examples/example-vite-react-sdk/src/typescript/models.gen.ts index 3208eca1..004351f6 100644 --- a/examples/example-vite-react-sdk/src/typescript/models.gen.ts +++ b/examples/example-vite-react-sdk/src/typescript/models.gen.ts @@ -106,11 +106,11 @@ export const schema: SchemaType = { Position: { fieldOrder: ["player", "vec"], player: "", - vec: { fieldOrder: ["x", "y"], x: 0, y: 0 }, + vec: { x: 0, y: 0 }, }, PositionValue: { fieldOrder: ["vec"], - vec: { fieldOrder: ["x", "y"], x: 0, y: 0 }, + vec: { x: 0, y: 0 }, }, Vec2: { fieldOrder: ["x", "y"], diff --git a/examples/example-vite-react-sdk/src/useModel.tsx b/examples/example-vite-react-sdk/src/useModel.tsx index 15c8dc5f..b3efe5da 100644 --- a/examples/example-vite-react-sdk/src/useModel.tsx +++ b/examples/example-vite-react-sdk/src/useModel.tsx @@ -18,9 +18,9 @@ function useModel< // Select only the specific model data for the given entityId const modelData = useDojoStore( (state) => - state.entities[entityId]?.models?.[namespace]?.[modelName] as - | SchemaType[N][M] - | undefined + state.entities[entityId.toString()]?.models?.[namespace]?.[ + modelName + ] as SchemaType[N][M] | undefined ); return modelData; diff --git a/examples/example-vite-react-sdk/tsconfig.app.tsbuildinfo b/examples/example-vite-react-sdk/tsconfig.app.tsbuildinfo index 75be23fb..a6d16e06 100644 --- a/examples/example-vite-react-sdk/tsconfig.app.tsbuildinfo +++ b/examples/example-vite-react-sdk/tsconfig.app.tsbuildinfo @@ -1 +1 @@ -{"root":["./src/app.tsx","./src/dojocontext.tsx","./src/bindings.ts","./src/contracts.gen.ts","./src/main.tsx","./src/usedojo.tsx","./src/usemodel.tsx","./src/usesystemcalls.ts","./src/vite-env.d.ts"],"version":"5.7.2"} \ No newline at end of file +{"root":["./src/app.tsx","./src/dojocontext.tsx","./src/historical-events.tsx","./src/main.tsx","./src/starknet-provider.tsx","./src/usedojo.tsx","./src/usemodel.tsx","./src/usesystemcalls.ts","./src/vite-env.d.ts","./src/wallet-account.tsx","./src/typescript/contracts.gen.ts","./src/typescript/models.gen.ts"],"version":"5.7.2"} \ No newline at end of file diff --git a/packages/predeployed-connector/src/index.ts b/packages/predeployed-connector/src/index.ts index de8e613d..77761b4b 100644 --- a/packages/predeployed-connector/src/index.ts +++ b/packages/predeployed-connector/src/index.ts @@ -30,6 +30,8 @@ export type PredeployedAccountsConnectorOptions = { id: string; name: string; rpc: string; +}; +export type WithAccount = T & { account: PredeployedWalletAccount; }; @@ -45,7 +47,9 @@ const icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAABkyAAAZMgGvFqWRAAAAB3RJTUUH6AkEFwsj7EvbJQAAAAZiS0dEAP8A/wD/oL2nkwAAK45JREFUeNrt3XmUXVWBqPE42+3Qj5hQ995zb1WlUqkkVZlIAhnJPIKAIogICEGGtlugFVBaxAbsVgw+FWlooEFtRFAmZRbClDAlICAg4MTQDY4MAiIy6X5nX8JrQQippKruOef+vrW+Zf9hr2XOsPd3T52z96BBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgCWhpaRlWqVT2LFcq/5m6MvW+1EdTn08N3CCfX3sM7ysnydXpf56UHuNl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wk95BkQ41j0Qtj0or6GJWOVekPmiPj2BXHsDiWxTHNyA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATcP/A/VYuD9l6UjwAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDI0LTA5LTA0VDIzOjExOjM1KzAwOjAw9BAQcQAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyNC0wOS0wNFQyMzoxMTozNSswMDowMIVNqM0AAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAV3pUWHRSYXcgcHJvZmlsZSB0eXBlIGlwdGMAAHic4/IMCHFWKCjKT8vMSeVSAAMjCy5jCxMjE0uTFAMTIESANMNkAyOzVCDL2NTIxMzEHMQHy4BIoEouAOoXEXTyQjWVAAAAAElFTkSuQmCC"; export class PredeployedAccountsConnector extends InjectedConnector { - constructor(private options: PredeployedAccountsConnectorOptions) { + constructor( + private options: WithAccount + ) { super({ options: { id: options.id, name: options.name } }); } diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 62f10d79..93531b4e 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -143,17 +143,17 @@ export interface QueryWhereOptions extends QueryOptions { * - An object containing at least one SubscriptionWhereOptions condition to filter the subscription results. * - Alternatively, an array of strings representing specific values to subscribe to. */ -export type SubscriptionQueryType = { - entityIds?: string[]; -} & { - [K in keyof T]?: { - [L in keyof T[K]]?: - | AtLeastOne<{ - $: SubscriptionWhereOptions; - }> - | string[]; - }; -}; +export type SubscriptionQueryType = + | BaseQueryType + | { + [K in keyof T]?: { + [L in keyof T[K]]?: + | AtLeastOne<{ + $: SubscriptionWhereOptions; + }> + | string[]; + }; + }; export type BaseQueryType = { entityIds?: string[]; From 8dd2ca07b77bbc34ff6eeb14596abf52df19a0e9 Mon Sep 17 00:00:00 2001 From: Valentin Dosimont Date: Mon, 6 Jan 2025 21:08:40 +0100 Subject: [PATCH 3/3] feat: update dojo-starter version --- worlds/dojo-starter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/dojo-starter b/worlds/dojo-starter index 3b23256c..cbd43d50 160000 --- a/worlds/dojo-starter +++ b/worlds/dojo-starter @@ -1 +1 @@ -Subproject commit 3b23256caf7bb4a96d6bfa9637a5cf513d7ea07d +Subproject commit cbd43d5036b472483086a4069552e806de23083f