Skip to content

Commit

Permalink
chore(client): update Dojo integration
Browse files Browse the repository at this point in the history
  • Loading branch information
0xibs committed Oct 2, 2024
1 parent 28522b3 commit b6be016
Show file tree
Hide file tree
Showing 26 changed files with 742 additions and 388 deletions.
14 changes: 7 additions & 7 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
},
"dependencies": {
"@apollo/client": "^3.11.8",
"@dojoengine/core": "1.0.0-alpha.5",
"@dojoengine/create-burner": "1.0.0-alpha.5",
"@dojoengine/react": "1.0.0-alpha.5",
"@dojoengine/core": "1.0.0-alpha.14",
"@dojoengine/create-burner": "1.0.0-alpha.14",
"@dojoengine/react": "1.0.0-alpha.14",
"@dojoengine/recs": "2.0.13",
"@dojoengine/state": "1.0.0-alpha.5",
"@dojoengine/torii-client": "1.0.0-alpha.5",
"@dojoengine/utils": "1.0.0-alpha.5",
"@dojoengine/state": "1.0.0-alpha.14",
"@dojoengine/torii-client": "1.0.0-alpha.14",
"@dojoengine/utils": "1.0.0-alpha.14",
"@latticexyz/react": "^2.0.12",
"@latticexyz/utils": "^2.0.12",
"@starknet-react/chains": "^0.1.7",
Expand Down Expand Up @@ -57,4 +57,4 @@
"typescript": "^5.5.4",
"vite": "^4.3.9"
}
}
}
64 changes: 32 additions & 32 deletions client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/scripts/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOJO_MANIFEST_PATH=../onchain/scarb.toml sozo build --typescript --bindings-output=./src/dojo
1 change: 1 addition & 0 deletions client/scripts/gen_cc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx @dojoengine/core ../onchain/manifests/dev/deployment/manifest.json ./_dojo http://localhost:5050 0x4e4a8cb96198772361acc30c71d81768bccc6c29501f211b0f0ca7045b194a4
48 changes: 46 additions & 2 deletions client/src/components/ControlWindows/GameAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getGameProfilesFromAddress,
} from "../../utils/helpers";
import { FaArrowAltCircleRight } from "react-icons/fa";
import { useDojo } from "../../dojo/useDojo";

const ConnectWallet = () => {
const { connectors, connect } = useConnect();
Expand Down Expand Up @@ -63,6 +64,8 @@ const GameAccount = () => {
disconnect();
};

const { system } = useDojo();

const addGameProfile = async () => {
if (newProfileName === undefined || newProfileName?.length < 2) {
alert("profile name must be greater than 2");
Expand All @@ -74,8 +77,9 @@ const GameAccount = () => {
return;
}

await createGameProfile(newProfileName, account);
setNewProfileName("");
// await createGameProfile(newProfileName, account);
await system.createUsername(account, newProfileName);
await setNewProfileName("");

await getGameProfilesFromAddress(address, setGameProfiles);
};
Expand Down Expand Up @@ -166,6 +170,46 @@ const GameAccount = () => {
<button>DELETE</button>
<button>SELL</button>
</div>

<div className="game-profiles">
<div className="profile-heading">Game Profiles</div>
<div className="game-profiles-outer-list">
{gameProfiles !== undefined ? (
<div className="game-profiles-inner-list">
{gameProfiles?.length > 0 ? (
<div className="games-profiles-core-list">
{gameProfiles.map((gameProfile) => (
<div className="list-profile">
<span>{convertHexToText(gameProfile)}</span>

<FaArrowAltCircleRight cursor={"pointer"} />
</div>
))}
</div>
) : (
<div style={{ color: "gray" }}>--no profile found--</div>
)}
</div>
) : (
<div style={{ color: "gray" }} className="loading-txt">
Loading...
</div>
)}
</div>
<div className="add-profile">
<input
placeholder="username"
value={newProfileName}
onChange={(e) => setNewProfileName(e.target.value)}
/>
<button
className="add-profile-btn"
onClick={() => addGameProfile()}
>
Add new profile
</button>
</div>
</div>
</div>
)}
</div>
Expand Down
130 changes: 63 additions & 67 deletions client/src/dojo/DojoContext.tsx
Original file line number Diff line number Diff line change
@@ -1,83 +1,79 @@
import { createContext, ReactNode, useContext, useMemo } from "react";
import { BurnerAccount, useBurnerManager } from "@dojoengine/create-burner";
import { ReactNode, createContext, useContext, useMemo } from "react";
import { Account } from "starknet";
import { SetupResult } from "./generated/setup";

import { SetupResult } from "./setup";

interface DojoContextType extends SetupResult {
masterAccount: Account;
account: BurnerAccount;
masterAccount: Account;
account: BurnerAccount;
}

export const DojoContext = createContext<DojoContextType | null>(null);

export const DojoProvider = ({
children,
value,
children,
value,
}: {
children: ReactNode;
value: SetupResult;
children: ReactNode;
value: SetupResult;
}) => {
const currentValue = useContext(DojoContext);
if (currentValue) throw new Error("DojoProvider can only be used once");
const currentValue = useContext(DojoContext);
if (currentValue) throw new Error("DojoProvider can only be used once");

const {
config: { masterAddress, masterPrivateKey },
burnerManager,
dojoProvider,
} = value;
const {
config: { masterAddress, masterPrivateKey },
burnerManager,
dojoProvider,
} = value;

const masterAccount = useMemo(
() =>
new Account(
dojoProvider.provider,
masterAddress,
masterPrivateKey,
"1"
),
[masterAddress, masterPrivateKey, dojoProvider.provider]
);
const masterAccount = useMemo(
() =>
new Account(dojoProvider.provider, masterAddress, masterPrivateKey, "1"),
[masterAddress, masterPrivateKey, dojoProvider.provider]
);

const {
create,
list,
get,
select,
deselect,
remove,
clear,
account,
isDeploying,
count,
copyToClipboard,
applyFromClipboard,
checkIsDeployed,
} = useBurnerManager({
burnerManager,
});
const {
create,
list,
get,
select,
deselect,
remove,
clear,
account,
isDeploying,
count,
copyToClipboard,
applyFromClipboard,
checkIsDeployed,
} = useBurnerManager({
burnerManager,
});

return (
<DojoContext.Provider
value={{
...value,
masterAccount,
account: {
create,
list,
get,
select,
deselect,
remove,
clear,
account: account ? account : masterAccount,
isDeploying,
count,
copyToClipboard,
applyFromClipboard,
checkIsDeployed,
},
}}
>
{children}
</DojoContext.Provider>
);
return (
<DojoContext.Provider
value={{
...value,
masterAccount,
account: {
create,
list,
get,
select,
deselect,
remove,
clear,
account: account ? account : masterAccount,
isDeploying,
count,
copyToClipboard,
applyFromClipboard,
checkIsDeployed,
},
}}
>
{children}
</DojoContext.Provider>
);
};
Loading

0 comments on commit b6be016

Please sign in to comment.