Skip to content

fix: prettier #277

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
Sep 25, 2024
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
43 changes: 8 additions & 35 deletions examples/example-vite-react-sdk/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import { useEffect, useState } from "react";

import "./App.css";
import { ParsedEntity, SDK } from "@dojoengine/sdk";
import { Schema } from "./bindings.ts";

import { init, ParsedEntity } from "@dojoengine/sdk";

import { dojoConfig } from "../dojoConfig.ts";
import { Schema, schema } from "./bindings.ts";

const db = await init<Schema>(
{
client: {
rpcUrl: dojoConfig.rpcUrl,
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
worldAddress:
"0x5d475a9221f6cbf1a016b12400a01b9a89935069aecd57e9876fcb2a7bb29da",
},
domain: {
name: "Example",
version: "1.0",
chainId: "your-chain-id",
revision: "1",
},
},
schema
);

function App() {
function App({ db }: { db: SDK<Schema> }) {
const [entities, setEntities] = useState<ParsedEntity<Schema>[]>([]);

useEffect(() => {
Expand All @@ -37,13 +14,7 @@ function App() {
{
dojo_starter: {
Moves: {
$: {
where: {
player: {
$is: "0x3628a39cc6bd2347e79967e9458ac41ab65bac6949f2aa311b311aff0d7334d",
},
},
},
$: {},
},
},
},
Expand Down Expand Up @@ -81,7 +52,9 @@ function App() {
unsubscribe();
}
};
}, []);
}, [db]);

console.log("entities:");

useEffect(() => {
const fetchEntities = async () => {
Expand Down Expand Up @@ -129,7 +102,7 @@ function App() {
};

fetchEntities();
}, []);
}, [db]);

return (
<div>
Expand Down
37 changes: 32 additions & 5 deletions examples/example-vite-react-sdk/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,36 @@ import { createRoot } from "react-dom/client";
import App from "./App.tsx";

import "./index.css";
import { init } from "@dojoengine/sdk";
import { Schema, schema } from "./bindings.ts";
import { dojoConfig } from "../dojoConfig.ts";

createRoot(document.getElementById("root")!).render(
<StrictMode>
<App />
</StrictMode>
);
async function main() {
const db = await init<Schema>(
{
client: {
rpcUrl: dojoConfig.rpcUrl,
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
worldAddress: dojoConfig.manifest.world.address,
},
domain: {
name: "Example",
version: "1.0",
chainId: "your-chain-id",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace placeholder chainId with the actual value.

The chainId is currently set to "your-chain-id". Please update this to the correct chain ID for your environment to ensure proper connectivity and functionality.

revision: "1",
},
},
schema
);

createRoot(document.getElementById("root")!).render(
<StrictMode>
<App db={db} />
</StrictMode>
);
}
Comment on lines +11 to +35
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider handling initialization within React components.

Initializing the database before rendering delays the application's initial render, which may lead to a blank screen during the wait. To improve user experience, consider moving the initialization logic inside the App component or a higher-order component. This allows you to display loading states or spinners while the initialization is in progress.


main().catch((error) => {
console.error("Failed to initialize the application:", error);
});
Comment on lines +37 to +39
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance user feedback on initialization failure.

If the application fails to initialize, the error is only logged to the console. Consider providing a user-friendly error message or rendering a fallback UI to inform the user about the issue.

Loading