Skip to content

feat: update dojo version #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
]);
Comment on lines +107 to +110
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Unsafe type assertion in state update.

The type assertion to MessageItem could lead to runtime errors if the message structure doesn't match.

-msg as MessageItem,
+{
+    content: msg.content,
+    identity: msg.identity,
+    timestamp: parseInt(msg.timestamp.toString(), 16)
+} as MessageItem,

Committable suggestion skipped: line range outside the PR's diff.

}
},
});
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>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Type assertion needs null check.

The type assertion might fail if entity.pop() returns undefined.

-const counter = entity.pop() as ParsedEntity<SchemaType>;
+const counter = entity.pop();
 if (!counter) {
     return 0;
 }
+const typedCounter = counter as ParsedEntity<SchemaType>;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const counter = entity.pop() as ParsedEntity<SchemaType>;
const counter = entity.pop();
if (!counter) {
return 0;
}
const typedCounter = counter 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(),
Comment on lines +63 to +69
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Similar type assertion issue in subscription handler.

The same type assertion issue exists in the subscription handler.

-const entity = data.pop() as ParsedEntity<SchemaType>;
+const entity = data.pop();
 if (!entity) {
     return;
 }
+const typedEntity = entity as ParsedEntity<SchemaType>;

Also applies to: 72-72

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
Loading