Skip to content

Commit

Permalink
Merge pull request #375 from dojoengine/feat/update-dojo-version
Browse files Browse the repository at this point in the history
feat: update dojo version
  • Loading branch information
MartianGreed authored Jan 14, 2025
2 parents 57b923a + 84dd776 commit 395e561
Show file tree
Hide file tree
Showing 27 changed files with 641 additions and 541 deletions.
15 changes: 15 additions & 0 deletions .changeset/dull-jeans-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@dojoengine/core": patch
"@dojoengine/create-burner": patch
"@dojoengine/create-dojo": patch
"@dojoengine/predeployed-connector": patch
"@dojoengine/react": patch
"@dojoengine/sdk": patch
"@dojoengine/state": patch
"@dojoengine/torii-client": patch
"@dojoengine/torii-wasm": patch
"@dojoengine/utils": patch
"@dojoengine/utils-wasm": patch
---

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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: git submodule update --init --recursive

- run: curl -L https://install.dojoengine.org | bash
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.0.9
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.0.10
- run: |
cd worlds/dojo-starter
/home/runner/.config/.dojo/bin/sozo build
Expand Down
5 changes: 0 additions & 5 deletions examples/example-vite-kitchen-sink/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { useDojoDb } from "@/dojo/provider";
import { useEffect, useState } from "react";
import { OnchainDashSchemaType } from "@/dojo/models";
import { SDK } from "@dojoengine/sdk";
import { Subscription } from "@dojoengine/torii-client";
import GlobalCounter from "@/components/global-counter";
import CallerCounter from "@/components/caller-counter";
import Chat from "@/components/chat";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { useCallback, useEffect, useState } from "react";
import { Button } from "./ui/button";
import { useAccount, useContractWrite } from "@starknet-react/core";
import { useAccount, useSendTransaction } from "@starknet-react/core";
import { useDojoDb } from "@/dojo/provider";
import { ensureStarkFelt } from "@/lib/utils";
import { SDK } from "@dojoengine/sdk";
import { OnchainDashSchemaType } from "@/dojo/models";
import { ParsedEntity, QueryBuilder, SDK } from "@dojoengine/sdk";
import { Subscription } from "@dojoengine/torii-wasm";
import { dojoConfig } from "@/../dojoConfig";
import { SchemaType } from "@/typescript/models.gen";
import { addAddressPadding } from "starknet";

export default function CallerCounter() {
const [count, setCount] = useState(0);
const [isLoading, setIsLoading] = useState(false);
const [sub, setSub] = useState<Subscription | null>(null);
const { address } = useAccount();
const { write: incrementCallerCounter } = useContractWrite({
const { send: incrementCallerCounter } = useSendTransaction({
calls: [
{
contractAddress: dojoConfig.manifest.contracts[0].address,
Expand All @@ -30,25 +31,18 @@ export default function CallerCounter() {

const { db } = useDojoDb();
useEffect(() => {
async function getEntity(
db: SDK<OnchainDashSchemaType>,
address: string
) {
async function getEntity(db: SDK<SchemaType>, address: string) {
const entity = await db.getEntities({
query: {
onchain_dash: {
CallerCounter: {
$: {
where: {
caller: { $eq: ensureStarkFelt(address) },
},
},
},
},
},
query: new QueryBuilder<SchemaType>()
.namespace("onchain_dash", (n) =>
n.entity("CallerCounter", (e) =>
e.eq("caller", addAddressPadding(address))
)
)
.build(),
callback: () => {},
});
const counter = entity.pop();
const counter = entity.pop() as ParsedEntity<SchemaType>;
if (!counter) {
return 0;
}
Expand All @@ -66,25 +60,20 @@ export default function CallerCounter() {

useEffect(() => {
async function subscribeToEntityUpdates(
db: SDK<OnchainDashSchemaType>,
db: SDK<SchemaType>,
address: string
) {
const sub = await db.subscribeEntityQuery({
// @ts-expect-error $eq is working there
query: {
onchain_dash: {
CallerCounter: {
$: {
where: {
caller: { $eq: ensureStarkFelt(address) },
},
},
},
},
},
query: new QueryBuilder<SchemaType>()
.namespace("onchain_dash", (n) =>
n.entity("CallerCounter", (e) =>
e.eq("caller", addAddressPadding(address))
)
)
.build(),
callback: ({ data, error }) => {
if (data) {
const entity = data.pop();
const entity = data.pop() as ParsedEntity<SchemaType>;
if (!entity) {
return;
}
Expand Down
39 changes: 21 additions & 18 deletions examples/example-vite-kitchen-sink/src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { useForm } from "react-hook-form";
import { useDojoDb } from "@/dojo/provider";
import { useAccount } from "@starknet-react/core";
import { toValidAscii } from "@/lib/utils";
import { SDK } from "@dojoengine/sdk";
import { Message, OnchainDashSchemaType } from "@/dojo/models";
import { ParsedEntity, SDK } from "@dojoengine/sdk";
import { Subscription } from "@dojoengine/torii-wasm";
import { shortAddress } from "@/lib/utils";
import { Message, SchemaType } from "@/typescript/models.gen";

interface MessageItem {
content: string;
Expand Down Expand Up @@ -61,24 +61,26 @@ export default function Chat() {
);

useEffect(() => {
async function getEntity(db: SDK<OnchainDashSchemaType>) {
async function getEntity(db: SDK<SchemaType>) {
const entity = await db.getEntities({
query: {
onchain_dash: { Message: { $: {} } },
},
callback: () => {},
});

// @ts-expect-error a & b are not undefined as they are filtered out with `filer(Boolean)`
return entity
.map((e) => e.models.onchain_dash.Message)
.filter(Boolean)
.sort((a: Message, b: Message): number =>
parseInt(a.timestamp.toString(), 16) <
parseInt(b.timestamp.toString(), 16)
? -1
: 1
);
return (
entity
.map((e) => e.models.onchain_dash.Message)
.filter(Boolean)
// @ts-expect-error a & b are not undefined as they are filtered out with `filer(Boolean)`
.sort((a: Message, b: Message): number =>
parseInt(a.timestamp.toString(), 16) <
parseInt(b.timestamp.toString(), 16)
? -1
: 1
)
);
}
if (db && messages.length === 0 && sub === null) {
// @ts-expect-error ts is getting drunk there
Expand All @@ -87,24 +89,25 @@ export default function Chat() {
}, [db, messages, sub]);

useEffect(() => {
async function subscribeToEntityUpdates(
db: SDK<OnchainDashSchemaType>
) {
async function subscribeToEntityUpdates(db: SDK<SchemaType>) {
const sub = await db.subscribeEntityQuery({
query: {
onchain_dash: { Message: { $: {} } },
},
callback: ({ data }) => {
if (data) {
const entity = data.pop();
const entity = data.pop() as ParsedEntity<SchemaType>;
if (!entity) {
return;
}
const msg = entity.models.onchain_dash.Message;
if (msg === undefined) {
return;
}
setMessages((prevMessages) => [...prevMessages, msg]);
setMessages((prevMessages) => [
...prevMessages,
msg as MessageItem,
]);
}
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { useCallback, useEffect, useState } from "react";
import { Button } from "./ui/button";
import { useContractWrite } from "@starknet-react/core";
import { useSendTransaction } from "@starknet-react/core";
import { useDojoDb } from "@/dojo/provider";
import { SDK } from "@dojoengine/sdk";
import { OnchainDashSchemaType } from "@/dojo/models";
import { ParsedEntity, QueryBuilder, SDK } from "@dojoengine/sdk";
import { Subscription } from "@dojoengine/torii-wasm";
import { dojoConfig } from "@/../dojoConfig";
import { SchemaType } from "@/typescript/models.gen";
import { addAddressPadding } from "starknet";

export default function GlobalCOunter() {
const [count, setCount] = useState(0);
const [isLoading, setIsLoading] = useState(false);
const [sub, setSub] = useState<Subscription | null>(null);
const { write: incrementGlobalCounter } = useContractWrite({
const { send: incrementGlobalCounter } = useSendTransaction({
calls: [
{
contractAddress: dojoConfig.manifest.contracts[0].address,
Expand All @@ -28,21 +29,19 @@ export default function GlobalCOunter() {
const { db } = useDojoDb();

useEffect(() => {
async function getEntity(db: SDK<OnchainDashSchemaType>) {
async function getEntity(db: SDK<SchemaType>) {
const entity = await db.getEntities({
query: {
onchain_dash: {
GlobalCounter: {
$: {
where: { global_counter_key: { $eq: 9999999 } },
},
},
},
},
query: new QueryBuilder<SchemaType>()
.namespace("onchain_dash", (n) =>
n.entity("GlobalCounter", (e) =>
e.eq("global_counter_key", 9999999)
)
)
.build(),
callback: ({ data, error }) => {},
});

const counter = entity.pop();
const counter = entity.pop() as ParsedEntity<SchemaType>;
if (!counter) {
return 0;
}
Expand All @@ -59,23 +58,18 @@ export default function GlobalCOunter() {
}, [db]);

useEffect(() => {
async function subscribeToEntityUpdates(
db: SDK<OnchainDashSchemaType>
) {
async function subscribeToEntityUpdates(db: SDK<SchemaType>) {
const sub = await db.subscribeEntityQuery({
query: {
// @ts-expect-error $eq is working there
onchain_dash: {
GlobalCounter: {
$: {
where: { global_counter_key: { $eq: 9999999 } },
},
},
},
},
query: new QueryBuilder<SchemaType>()
.namespace("onchain_dash", (n) =>
n.entity("GlobalCounter", (e) =>
e.eq("global_counter_key", 9999999)
)
)
.build(),
callback: ({ data, error }) => {
if (data) {
const entity = data.pop();
const entity = data.pop() as ParsedEntity<SchemaType>;
if (!entity) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export default function Sidebar() {
>
<div className="absolute left-2 top-1/2 flex size-8 -translate-y-1/2 items-center justify-center rounded-xs bg-background">
<img
// @ts-expect-error this is working
src={connector.icon.dark}
className="size-5"
alt={`${connector.name}`}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { PropsWithChildren } from "react";
import CartridgeConnector from "@cartridge/connector";
import { Chain, mainnet } from "@starknet-react/chains";
import { jsonRpcProvider, StarknetConfig, voyager } from "@starknet-react/core";
import {
Connector,
jsonRpcProvider,
StarknetConfig,
voyager,
} from "@starknet-react/core";
import { env, getRpcUrl } from "@/env";
import { dojoConfig } from "@/../dojoConfig";
import {
Expand Down Expand Up @@ -44,6 +49,7 @@ export default function StarknetProvider({ children }: PropsWithChildren) {
<StarknetConfig
chains={[mainnet]}
provider={provider}
// @ts-expect-error this is ok
connectors={[cartridge, ...pa]}
explorer={voyager}
autoConnect
Expand Down
Loading

0 comments on commit 395e561

Please sign in to comment.