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 (