-
Notifications
You must be signed in to change notification settings - Fork 54
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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, | ||||||||||||||
|
@@ -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>; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type assertion needs null check. The type assertion might fail if -const counter = entity.pop() as ParsedEntity<SchemaType>;
+const counter = entity.pop();
if (!counter) {
return 0;
}
+const typedCounter = counter as ParsedEntity<SchemaType>; 📝 Committable suggestion
Suggested change
|
||||||||||||||
if (!counter) { | ||||||||||||||
return 0; | ||||||||||||||
} | ||||||||||||||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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; | ||||||||||||||
} | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe type assertion in state update.
The type assertion to
MessageItem
could lead to runtime errors if the message structure doesn't match.