Skip to content

Commit

Permalink
add ability to retrieve games for a player
Browse files Browse the repository at this point in the history
  • Loading branch information
willemolding committed Dec 27, 2023
1 parent 7f82cf4 commit a247e94
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ VITE_PUBLIC_MASTER_ADDRESS=0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa31613
VITE_PUBLIC_MASTER_PRIVATE_KEY=0x1800000000300000180000000000030000000000003006001800006600
VITE_PUBLIC_WORLD_ADDRESS=0x730cbe05cf01c05145b5bcd1c729bcb43de61ab6cdc62ee7be536d669a1ee7c
VITE_PUBLIC_NODE_URL = http://localhost:5050
VITE_PUBLIC_TORII = http://127.0.0.1:8080/graphql
VITE_PUBLIC_TORII = http://0.0.0.0:8080/graphql
4 changes: 0 additions & 4 deletions client/src/dojo/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ export function createSystemCalls(
{ retryInterval: 100 }
)

// setComponentsFromEvents(contractComponents,
// getEvents(receipt)
// );

console.log(receipt)

notify('Game Created!',true)
Expand Down
21 changes: 16 additions & 5 deletions client/src/ui/loginComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ClickWrapper } from "./clickWrapper";
import { Phase } from "./phaseManager";
import { useDojo } from "../hooks/useDojo";
import { truncateString } from "../utils";
import { Account, num } from "starknet";
import { padHexAddress } from "../utils";

interface LoginPageProps {
setUIState: React.Dispatch<Phase>;
Expand All @@ -16,19 +18,28 @@ export const LoginComponent: React.FC<LoginPageProps> = ({ setUIState }) => {
const {
account: { account, create, isDeploying, clear,select,list },
networkLayer: {
systemCalls: { create_game }
systemCalls: { create_game },
network: { graphSdk }
},
} = useDojo();

useEffect(() => {
const fetchPlayerGames = async () => {
const response = await graphSdk().getPlayersGames({ address: padHexAddress(account.address) });
console.log(response.data);
}

fetchPlayerGames();
}, [graphSdk, account]);

//create the client game comp for the start of the loading
const createGameClient = async () => {
setUIState(Phase.LOADING);
}

const newGame = async () => {
//create a new game
const newGame = async (account: Account) => {
//create a new game by sending a transaction
const game = await create_game(account);
console.log(game);
}


Expand Down Expand Up @@ -58,7 +69,7 @@ export const LoginComponent: React.FC<LoginPageProps> = ({ setUIState }) => {
Login as {truncateString(account.address,5)}
</div>

<div className="global-button-style" style={{ fontSize: "2.4cqw", padding: "5px 10px", fontFamily: "OL", fontWeight: "100" }} onClick={() => { newGame()}}>
<div className="global-button-style" style={{ fontSize: "2.4cqw", padding: "5px 10px", fontFamily: "OL", fontWeight: "100" }} onClick={() => { newGame(account)}}>
Create Game
</div>

Expand Down
7 changes: 7 additions & 0 deletions client/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ export function truncateString(inputString: string, prefixLength: number): strin

return `${prefix}...${suffix}`;
}

export function padHexAddress(hexAddress: string): string {
// convert a hex encoded address to a 64 byte long hex string by removing the leading 0x, padding with 0 and then readding the prefix
const hexAddressWithoutPrefix = hexAddress.slice(2);
const paddedHexAddress = hexAddressWithoutPrefix.padStart(64, '0');
return `0x${paddedHexAddress}`;
}
8 changes: 3 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ start_client:
start_devnet:
katana --disable-fee --seed=0

# migrates, authorizes, then start the indexer. Requires a devnet running on localhost:5050
# Requires a devnet running on localhost:5050
start_indexer:
#!/usr/bin/env bash
set -euxo pipefail
just build_contracts
WORLD_ADDRESS=$(just migrate | grep "at address" | grep -oE9 '(0x[a-fA-F0-9]{63})')
just set_auth
cd contracts && torii --world ${WORLD_ADDRESS}
WORLD_ADDRESS=$(cat ./contracts/target/dev/manifest.json | jq -r '.world.address')
torii --world ${WORLD_ADDRESS} --rpc $RPC_URL

0 comments on commit a247e94

Please sign in to comment.