Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 4 additions & 5 deletions examples/example-vite-react-sdk/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { WalletAccount } from "./wallet-account.tsx";
import { useSystemCalls } from "./useSystemCalls.ts";
import { Events } from "./events.tsx";
import { HistoricalEvents } from "./historical-events.tsx";
import { dojoProvider } from "./types.ts";

/**
* Main application component that provides game functionality and UI.
Expand All @@ -23,7 +24,6 @@ function App() {
const { useDojoStore, client } = useDojoSDK();
const { account } = useAccount();
const entities = useDojoStore((state) => state.entities);
console.log(entities);

const { spawn } = useSystemCalls();

Expand Down Expand Up @@ -117,10 +117,9 @@ function App() {
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={idx}
onClick={async () => {
await client.actions.move(
account!,
direction
);
await dojoProvider.move(account!, {
direction: direction,
});
}}
Comment on lines 119 to 123
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard move when wallet is disconnected.

Prevents crashes from account! and improves UX.

-                                    onClick={async () => {
-                                        await dojoProvider.move(account!, {
-                                            direction: direction,
-                                        });
-                                    }}
+                                    onClick={async () => {
+                                        if (!account) {
+                                            console.warn("Connect wallet to move.");
+                                            return;
+                                        }
+                                        await dojoProvider.move(account, { direction });
+                                    }}
📝 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
onClick={async () => {
await client.actions.move(
account!,
direction
);
await dojoProvider.move(account!, {
direction: direction,
});
}}
onClick={async () => {
if (!account) {
console.warn("Connect wallet to move.");
return;
}
await dojoProvider.move(account, { direction });
}}
🤖 Prompt for AI Agents
In examples/example-vite-react-sdk/src/App.tsx around lines 119 to 123, the
onClick handler calls dojoProvider.move(account!, ...) using a non-null
assertion which will crash when wallet is disconnected; guard the handler by
checking that account is defined before calling move (e.g. early return if
!account), remove the non-null assertion, and optionally disable the button or
show a connect-wallet prompt when account is falsy to improve UX.

>
{label}
Expand Down
Loading
Loading