From 629cf42e112522a9e1487ce20dc3c51a16dff6cd Mon Sep 17 00:00:00 2001 From: Willem Olding Date: Wed, 27 Dec 2023 16:47:04 +1100 Subject: [PATCH] add examples of wiring up system actions --- client/src/dojo/createSystemCalls.ts | 28 +++++++++++++++++++--------- client/src/ui/pages/gamePage.tsx | 10 ++++++++-- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/client/src/dojo/createSystemCalls.ts b/client/src/dojo/createSystemCalls.ts index 8db9317..8ff3e4f 100644 --- a/client/src/dojo/createSystemCalls.ts +++ b/client/src/dojo/createSystemCalls.ts @@ -1,11 +1,6 @@ import { SetupNetworkResult } from "./setupNetwork"; -import { ClientComponents } from "./createClientComponents"; - import { toast } from 'react-toastify'; - -import { Account, num } from "starknet"; - -//HERE +import { Account } from "starknet"; export type SystemCalls = ReturnType; @@ -70,6 +65,21 @@ export function createSystemCalls( } }; + const interact = async (account: Account, gameId: number, itemId: number) => { + try { + const tx = await execute(account, "spellcrafter_system", "interact", [gameId, itemId]); + const receipt = await account.waitForTransaction( + tx.transaction_hash, + { retryInterval: 100 } + ) + console.log(receipt) + notify('Successfully foraged!', true) + } catch (e) { + console.log(e) + notify(`Error foraging ${e}`, false) + } + }; + const summon = async (account: Account, gameId: number, familiarType: number) => { try { const tx = await execute(account, "spellcrafter_system", "summon", [gameId, familiarType]); @@ -117,7 +127,7 @@ export function createSystemCalls( const reapAction = async (account: Account, gameId: number, entityId: number) => { try { - const tx = await execute(account, "spellcrafter_system", "sacrifice", [gameId, entityId]); + const tx = await execute(account, "spellcrafter_system", "reap_action", [gameId, entityId]); const receipt = await account.waitForTransaction( tx.transaction_hash, { retryInterval: 100 } @@ -133,7 +143,7 @@ export function createSystemCalls( const wait = async (account: Account, gameId: number) => { try { - const tx = await execute(account, "spellcrafter_system", "sacrifice", [gameId]); + const tx = await execute(account, "spellcrafter_system", "wait", [gameId]); const receipt = await account.waitForTransaction( tx.transaction_hash, { retryInterval: 100 } @@ -146,10 +156,10 @@ export function createSystemCalls( } }; - return { createGame, forage, + interact, summon, send, reapAction, diff --git a/client/src/ui/pages/gamePage.tsx b/client/src/ui/pages/gamePage.tsx index a37a759..bc40df3 100644 --- a/client/src/ui/pages/gamePage.tsx +++ b/client/src/ui/pages/gamePage.tsx @@ -13,7 +13,7 @@ export const GamePage: React.FC = () => { const { account: { account }, networkLayer: { - systemCalls: { forage }, + systemCalls: { forage, interact }, network: { graphSdk } }, } = useDojo(); @@ -28,6 +28,12 @@ export const GamePage: React.FC = () => { await forage(account, parseInt(currentGameId), 0); } + const doInteract = async (account: Account, cardId: number) => { + //create a new game by sending a transaction + if (!currentGameId) return; + await interact(account, parseInt(currentGameId), cardId); + } + useEffect(() => { const fetchGameData = async () => { if(!currentGameId) return; @@ -51,7 +57,7 @@ export const GamePage: React.FC = () => { Forage -
{ doForage(account)}}> +
{ doInteract(account, gameState.cards[0][0])}}> Interact