Skip to content

Commit

Permalink
update: add resetUser
Browse files Browse the repository at this point in the history
  • Loading branch information
TiyoSheng committed Dec 1, 2023
1 parent d0e403d commit 6fef9c9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ export function createSystemCalls(
}
}

const initUserInfo = async () => {
const initUserInfo = async (addr) => {
if (wait) return
wait = true
console.log('initUserInfo', new Date().getTime());
try {
const tx = await worldContract.write.initUserInfo();
const tx = await worldContract.write.initUserInfo([addr]);
await waitForTransaction(tx);
console.log('initUserInfo success', new Date().getTime(), tx);
wait = false
Expand Down
39 changes: 36 additions & 3 deletions packages/client/src/pages/test/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import './index.scss';
import { bfs, simplifyMapData } from '@/utils/map';
import useMerkel from '@/hooks/useMerkel';
import { loadMapData } from "@/utils";
import { Switch } from 'antd';
import { Switch, Select } from 'antd';
import { message } from 'antd';
import MAP_CFG from '@/config/map';

Expand Down Expand Up @@ -45,7 +45,7 @@ const Test = () => {

const {
components: { Player, GameConfig, BattleList, BoxList, GlobalConfig, SyncProgress },
systemCalls: { move, joinBattlefield, transfer, battleInvitation, confirmBattle, selectUserNft, revealBattle, openBox, revealBox, getCollections, CreateBox, getBattlePlayerHp, setGmaeOpen },
systemCalls: { move, joinBattlefield, transfer, battleInvitation, confirmBattle, selectUserNft, revealBattle, openBox, revealBox, getCollections, CreateBox, initUserInfo, setGmaeOpen },
network
} = useMUD();

Expand Down Expand Up @@ -166,6 +166,8 @@ const Test = () => {
player.isMe = false
}
player.addr = address
// address 取前6位和后4位
player.label = `${player.name}(${address.substring(address.length-4)})`
return player;
})

Expand Down Expand Up @@ -404,6 +406,20 @@ const Test = () => {
message.success('设置成功');
}

const [userAddr, setUserAddr] = useState('')

const addrChange = (e) => {
console.log(e, 'e')
setUserAddr(e)
}

const resetUser = async () => {
message.loading('重置中...');
await initUserInfo(userAddr)
message.success('重置成功');
setUserAddr('')
}

return (
<div className="content">
<div className="nav">
Expand Down Expand Up @@ -475,6 +491,23 @@ const Test = () => {
</div>
<div className="btn" onClick={setGmaeOpenFun}>确认</div>
</div>
<div className="section">
<div className="title">重置user</div>
<div className="input">
{/* <input type="text" value={userAddr} onChange={addrChange} placeholder='userAddress' /> */}
<Select
showSearch
placeholder="Select a person"
optionFilterProp="children"
onChange={addrChange}
fieldNames={{ label: 'label', value: 'addr' }}
options={players.filter(item => item.state != 0)}
value={userAddr}
style={{width: '100%'}}
/>
</div>
<div className="btn" onClick={resetUser}>确认</div>
</div>
<div className="section">
<div className="title">mintNFT</div>
<div className="input"></div>
Expand All @@ -493,7 +526,7 @@ const Test = () => {
<div className="btn" onClick={revealNFTFun}>确认</div>
</div>
<div className="section">
<div className="title">初始化玩家</div>
<div className="title">selectUserNft</div>
<div className="input">
<select value={revealNFTData} onChange={tokenIdChange}>
{
Expand Down

0 comments on commit 6fef9c9

Please sign in to comment.