Skip to content

Commit

Permalink
update: add init user
Browse files Browse the repository at this point in the history
  • Loading branch information
TiyoSheng committed Oct 31, 2023
1 parent 26a0a83 commit 9e339ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
13 changes: 12 additions & 1 deletion packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -172,6 +182,7 @@ export function createSystemCalls(
revealBox,
CreateBox,
getBattlePlayerHp,
setInfo
setInfo,
initUserInfo
};
}
10 changes: 9 additions & 1 deletion packages/client/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 (
<div className="mi-home-page">
{contextHolder}
Expand All @@ -265,6 +272,7 @@ const Home = () => {
step === 'play' && (
<section className="mi-section">
<button className="play-btn mi-btn" onClick={play}>PLAY NOW</button>
<button className="play-btn mi-btn" onClick={initUserInfoFun}>INIT USER</button>
</section>
)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/client/src/pages/home/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
bottom: 25%;
font-size: 16px;
transform: translate3d(-50%, 0, 0);
& ~ .play-btn {
margin-top: 100px;
bottom: calc(25% - 100px);
}
}
}

Expand Down

0 comments on commit 9e339ed

Please sign in to comment.