Skip to content

Commit 395e561

Browse files
authored
Merge pull request #375 from dojoengine/feat/update-dojo-version
feat: update dojo version
2 parents 57b923a + 84dd776 commit 395e561

File tree

27 files changed

+641
-541
lines changed

27 files changed

+641
-541
lines changed

.changeset/dull-jeans-reply.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@dojoengine/core": patch
3+
"@dojoengine/create-burner": patch
4+
"@dojoengine/create-dojo": patch
5+
"@dojoengine/predeployed-connector": patch
6+
"@dojoengine/react": patch
7+
"@dojoengine/sdk": patch
8+
"@dojoengine/state": patch
9+
"@dojoengine/torii-client": patch
10+
"@dojoengine/torii-wasm": patch
11+
"@dojoengine/utils": patch
12+
"@dojoengine/utils-wasm": patch
13+
---
14+
15+
Updated packages to latest dojo version // accept and convert array by @rsodre // add missing params for query and subscription by @rsodre // update starknet-core-version by @rsodre

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: git submodule update --init --recursive
2121

2222
- run: curl -L https://install.dojoengine.org | bash
23-
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.0.9
23+
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.0.10
2424
- run: |
2525
cd worlds/dojo-starter
2626
/home/runner/.config/.dojo/bin/sozo build

examples/example-vite-kitchen-sink/src/app/page.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import { useDojoDb } from "@/dojo/provider";
2-
import { useEffect, useState } from "react";
3-
import { OnchainDashSchemaType } from "@/dojo/models";
4-
import { SDK } from "@dojoengine/sdk";
5-
import { Subscription } from "@dojoengine/torii-client";
61
import GlobalCounter from "@/components/global-counter";
72
import CallerCounter from "@/components/caller-counter";
83
import Chat from "@/components/chat";

examples/example-vite-kitchen-sink/src/components/caller-counter.tsx

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import { useCallback, useEffect, useState } from "react";
22
import { Button } from "./ui/button";
3-
import { useAccount, useContractWrite } from "@starknet-react/core";
3+
import { useAccount, useSendTransaction } from "@starknet-react/core";
44
import { useDojoDb } from "@/dojo/provider";
55
import { ensureStarkFelt } from "@/lib/utils";
6-
import { SDK } from "@dojoengine/sdk";
7-
import { OnchainDashSchemaType } from "@/dojo/models";
6+
import { ParsedEntity, QueryBuilder, SDK } from "@dojoengine/sdk";
87
import { Subscription } from "@dojoengine/torii-wasm";
98
import { dojoConfig } from "@/../dojoConfig";
9+
import { SchemaType } from "@/typescript/models.gen";
10+
import { addAddressPadding } from "starknet";
1011

1112
export default function CallerCounter() {
1213
const [count, setCount] = useState(0);
1314
const [isLoading, setIsLoading] = useState(false);
1415
const [sub, setSub] = useState<Subscription | null>(null);
1516
const { address } = useAccount();
16-
const { write: incrementCallerCounter } = useContractWrite({
17+
const { send: incrementCallerCounter } = useSendTransaction({
1718
calls: [
1819
{
1920
contractAddress: dojoConfig.manifest.contracts[0].address,
@@ -30,25 +31,18 @@ export default function CallerCounter() {
3031

3132
const { db } = useDojoDb();
3233
useEffect(() => {
33-
async function getEntity(
34-
db: SDK<OnchainDashSchemaType>,
35-
address: string
36-
) {
34+
async function getEntity(db: SDK<SchemaType>, address: string) {
3735
const entity = await db.getEntities({
38-
query: {
39-
onchain_dash: {
40-
CallerCounter: {
41-
$: {
42-
where: {
43-
caller: { $eq: ensureStarkFelt(address) },
44-
},
45-
},
46-
},
47-
},
48-
},
36+
query: new QueryBuilder<SchemaType>()
37+
.namespace("onchain_dash", (n) =>
38+
n.entity("CallerCounter", (e) =>
39+
e.eq("caller", addAddressPadding(address))
40+
)
41+
)
42+
.build(),
4943
callback: () => {},
5044
});
51-
const counter = entity.pop();
45+
const counter = entity.pop() as ParsedEntity<SchemaType>;
5246
if (!counter) {
5347
return 0;
5448
}
@@ -66,25 +60,20 @@ export default function CallerCounter() {
6660

6761
useEffect(() => {
6862
async function subscribeToEntityUpdates(
69-
db: SDK<OnchainDashSchemaType>,
63+
db: SDK<SchemaType>,
7064
address: string
7165
) {
7266
const sub = await db.subscribeEntityQuery({
73-
// @ts-expect-error $eq is working there
74-
query: {
75-
onchain_dash: {
76-
CallerCounter: {
77-
$: {
78-
where: {
79-
caller: { $eq: ensureStarkFelt(address) },
80-
},
81-
},
82-
},
83-
},
84-
},
67+
query: new QueryBuilder<SchemaType>()
68+
.namespace("onchain_dash", (n) =>
69+
n.entity("CallerCounter", (e) =>
70+
e.eq("caller", addAddressPadding(address))
71+
)
72+
)
73+
.build(),
8574
callback: ({ data, error }) => {
8675
if (data) {
87-
const entity = data.pop();
76+
const entity = data.pop() as ParsedEntity<SchemaType>;
8877
if (!entity) {
8978
return;
9079
}

examples/example-vite-kitchen-sink/src/components/chat.tsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { useForm } from "react-hook-form";
88
import { useDojoDb } from "@/dojo/provider";
99
import { useAccount } from "@starknet-react/core";
1010
import { toValidAscii } from "@/lib/utils";
11-
import { SDK } from "@dojoengine/sdk";
12-
import { Message, OnchainDashSchemaType } from "@/dojo/models";
11+
import { ParsedEntity, SDK } from "@dojoengine/sdk";
1312
import { Subscription } from "@dojoengine/torii-wasm";
1413
import { shortAddress } from "@/lib/utils";
14+
import { Message, SchemaType } from "@/typescript/models.gen";
1515

1616
interface MessageItem {
1717
content: string;
@@ -61,24 +61,26 @@ export default function Chat() {
6161
);
6262

6363
useEffect(() => {
64-
async function getEntity(db: SDK<OnchainDashSchemaType>) {
64+
async function getEntity(db: SDK<SchemaType>) {
6565
const entity = await db.getEntities({
6666
query: {
6767
onchain_dash: { Message: { $: {} } },
6868
},
6969
callback: () => {},
7070
});
7171

72-
// @ts-expect-error a & b are not undefined as they are filtered out with `filer(Boolean)`
73-
return entity
74-
.map((e) => e.models.onchain_dash.Message)
75-
.filter(Boolean)
76-
.sort((a: Message, b: Message): number =>
77-
parseInt(a.timestamp.toString(), 16) <
78-
parseInt(b.timestamp.toString(), 16)
79-
? -1
80-
: 1
81-
);
72+
return (
73+
entity
74+
.map((e) => e.models.onchain_dash.Message)
75+
.filter(Boolean)
76+
// @ts-expect-error a & b are not undefined as they are filtered out with `filer(Boolean)`
77+
.sort((a: Message, b: Message): number =>
78+
parseInt(a.timestamp.toString(), 16) <
79+
parseInt(b.timestamp.toString(), 16)
80+
? -1
81+
: 1
82+
)
83+
);
8284
}
8385
if (db && messages.length === 0 && sub === null) {
8486
// @ts-expect-error ts is getting drunk there
@@ -87,24 +89,25 @@ export default function Chat() {
8789
}, [db, messages, sub]);
8890

8991
useEffect(() => {
90-
async function subscribeToEntityUpdates(
91-
db: SDK<OnchainDashSchemaType>
92-
) {
92+
async function subscribeToEntityUpdates(db: SDK<SchemaType>) {
9393
const sub = await db.subscribeEntityQuery({
9494
query: {
9595
onchain_dash: { Message: { $: {} } },
9696
},
9797
callback: ({ data }) => {
9898
if (data) {
99-
const entity = data.pop();
99+
const entity = data.pop() as ParsedEntity<SchemaType>;
100100
if (!entity) {
101101
return;
102102
}
103103
const msg = entity.models.onchain_dash.Message;
104104
if (msg === undefined) {
105105
return;
106106
}
107-
setMessages((prevMessages) => [...prevMessages, msg]);
107+
setMessages((prevMessages) => [
108+
...prevMessages,
109+
msg as MessageItem,
110+
]);
108111
}
109112
},
110113
});

examples/example-vite-kitchen-sink/src/components/global-counter.tsx

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { useCallback, useEffect, useState } from "react";
22
import { Button } from "./ui/button";
3-
import { useContractWrite } from "@starknet-react/core";
3+
import { useSendTransaction } from "@starknet-react/core";
44
import { useDojoDb } from "@/dojo/provider";
5-
import { SDK } from "@dojoengine/sdk";
6-
import { OnchainDashSchemaType } from "@/dojo/models";
5+
import { ParsedEntity, QueryBuilder, SDK } from "@dojoengine/sdk";
76
import { Subscription } from "@dojoengine/torii-wasm";
87
import { dojoConfig } from "@/../dojoConfig";
8+
import { SchemaType } from "@/typescript/models.gen";
9+
import { addAddressPadding } from "starknet";
910

1011
export default function GlobalCOunter() {
1112
const [count, setCount] = useState(0);
1213
const [isLoading, setIsLoading] = useState(false);
1314
const [sub, setSub] = useState<Subscription | null>(null);
14-
const { write: incrementGlobalCounter } = useContractWrite({
15+
const { send: incrementGlobalCounter } = useSendTransaction({
1516
calls: [
1617
{
1718
contractAddress: dojoConfig.manifest.contracts[0].address,
@@ -28,21 +29,19 @@ export default function GlobalCOunter() {
2829
const { db } = useDojoDb();
2930

3031
useEffect(() => {
31-
async function getEntity(db: SDK<OnchainDashSchemaType>) {
32+
async function getEntity(db: SDK<SchemaType>) {
3233
const entity = await db.getEntities({
33-
query: {
34-
onchain_dash: {
35-
GlobalCounter: {
36-
$: {
37-
where: { global_counter_key: { $eq: 9999999 } },
38-
},
39-
},
40-
},
41-
},
34+
query: new QueryBuilder<SchemaType>()
35+
.namespace("onchain_dash", (n) =>
36+
n.entity("GlobalCounter", (e) =>
37+
e.eq("global_counter_key", 9999999)
38+
)
39+
)
40+
.build(),
4241
callback: ({ data, error }) => {},
4342
});
4443

45-
const counter = entity.pop();
44+
const counter = entity.pop() as ParsedEntity<SchemaType>;
4645
if (!counter) {
4746
return 0;
4847
}
@@ -59,23 +58,18 @@ export default function GlobalCOunter() {
5958
}, [db]);
6059

6160
useEffect(() => {
62-
async function subscribeToEntityUpdates(
63-
db: SDK<OnchainDashSchemaType>
64-
) {
61+
async function subscribeToEntityUpdates(db: SDK<SchemaType>) {
6562
const sub = await db.subscribeEntityQuery({
66-
query: {
67-
// @ts-expect-error $eq is working there
68-
onchain_dash: {
69-
GlobalCounter: {
70-
$: {
71-
where: { global_counter_key: { $eq: 9999999 } },
72-
},
73-
},
74-
},
75-
},
63+
query: new QueryBuilder<SchemaType>()
64+
.namespace("onchain_dash", (n) =>
65+
n.entity("GlobalCounter", (e) =>
66+
e.eq("global_counter_key", 9999999)
67+
)
68+
)
69+
.build(),
7670
callback: ({ data, error }) => {
7771
if (data) {
78-
const entity = data.pop();
72+
const entity = data.pop() as ParsedEntity<SchemaType>;
7973
if (!entity) {
8074
return;
8175
}

examples/example-vite-kitchen-sink/src/components/sidebar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export default function Sidebar() {
167167
>
168168
<div className="absolute left-2 top-1/2 flex size-8 -translate-y-1/2 items-center justify-center rounded-xs bg-background">
169169
<img
170+
// @ts-expect-error this is working
170171
src={connector.icon.dark}
171172
className="size-5"
172173
alt={`${connector.name}`}

examples/example-vite-kitchen-sink/src/components/starknet-provider.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import type { PropsWithChildren } from "react";
22
import CartridgeConnector from "@cartridge/connector";
33
import { Chain, mainnet } from "@starknet-react/chains";
4-
import { jsonRpcProvider, StarknetConfig, voyager } from "@starknet-react/core";
4+
import {
5+
Connector,
6+
jsonRpcProvider,
7+
StarknetConfig,
8+
voyager,
9+
} from "@starknet-react/core";
510
import { env, getRpcUrl } from "@/env";
611
import { dojoConfig } from "@/../dojoConfig";
712
import {
@@ -44,6 +49,7 @@ export default function StarknetProvider({ children }: PropsWithChildren) {
4449
<StarknetConfig
4550
chains={[mainnet]}
4651
provider={provider}
52+
// @ts-expect-error this is ok
4753
connectors={[cartridge, ...pa]}
4854
explorer={voyager}
4955
autoConnect

0 commit comments

Comments
 (0)