From 9e339edbb3cfeccef4ed0d22eeb838bb00ce8f35 Mon Sep 17 00:00:00 2001 From: Tiyo Date: Tue, 31 Oct 2023 21:14:48 +0800 Subject: [PATCH] update: add init user --- packages/client/src/mud/createSystemCalls.ts | 13 ++++++++++++- packages/client/src/pages/home/index.tsx | 10 +++++++++- packages/client/src/pages/home/styles.scss | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/client/src/mud/createSystemCalls.ts b/packages/client/src/mud/createSystemCalls.ts index a3138483..138c2c05 100644 --- a/packages/client/src/mud/createSystemCalls.ts +++ b/packages/client/src/mud/createSystemCalls.ts @@ -152,6 +152,16 @@ export function createSystemCalls( } } + const initUserInfo = async () => { + try { + const tx = await worldContract.write.initUserInfo(); + await waitForTransaction(tx); + return tx + } catch (error) { + message.error(error.cause.reason); + } + } + const getBattlePlayerHp = async (battleId: any, addr: any) => { const data = await worldContract.read.getBattlePlayerHp([battleId, addr]); return data @@ -172,6 +182,7 @@ export function createSystemCalls( revealBox, CreateBox, getBattlePlayerHp, - setInfo + setInfo, + initUserInfo }; } diff --git a/packages/client/src/pages/home/index.tsx b/packages/client/src/pages/home/index.tsx index 88b9f486..e2635913 100644 --- a/packages/client/src/pages/home/index.tsx +++ b/packages/client/src/pages/home/index.tsx @@ -28,7 +28,7 @@ const Home = () => { const [messageApi, contextHolder] = message.useMessage(); const { components: { GlobalConfig }, - systemCalls: { selectUserNft, joinBattlefield, selectLootNFT, setInfo }, + systemCalls: { selectUserNft, joinBattlefield, selectLootNFT, setInfo, initUserInfo }, network } = useMUD(); @@ -253,6 +253,13 @@ const Home = () => { localStorage.setItem('mi_user_address', network.walletClient.account.address) } + const initUserInfoFun = async () => { + await initUserInfo() + localStorage.removeItem('curPlayer'); + localStorage.removeItem('worldContractAddress'); + message.success('init success') + } + return (
{contextHolder} @@ -265,6 +272,7 @@ const Home = () => { step === 'play' && (
+
) } diff --git a/packages/client/src/pages/home/styles.scss b/packages/client/src/pages/home/styles.scss index 827b3df1..07e856af 100644 --- a/packages/client/src/pages/home/styles.scss +++ b/packages/client/src/pages/home/styles.scss @@ -17,6 +17,10 @@ bottom: 25%; font-size: 16px; transform: translate3d(-50%, 0, 0); + & ~ .play-btn { + margin-top: 100px; + bottom: calc(25% - 100px); + } } }