Skip to content

Commit

Permalink
add arb
Browse files Browse the repository at this point in the history
  • Loading branch information
TiyoSheng committed Dec 14, 2023
1 parent 36dc0ba commit 60ac60e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 32 deletions.
6 changes: 4 additions & 2 deletions packages/client/src/config/chain.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export const BLOCK_TIME = {
17001: 2500,
31337: 1200,
33784: 1200
33784: 1200,
421613: 1600
}

export const TRANSFER_GAS = {
17001: '0.01',
31337: '2',
33784: '2'
33784: '2',
421613: '0.05'
}

3 changes: 3 additions & 0 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export function createSystemCalls(
} catch (error) {
console.log('selectUserNft', error);
message.error(error.cause.reason || error.cause.details);
return {
type: 'error'
}
}
}

Expand Down
64 changes: 57 additions & 7 deletions packages/client/src/pages/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import {BLOCK_TIME} from '@/config/chain';
import discordImg from '@/assets/img/discord.png';
import { TALK_MAIN } from '@/config/talk';
import { getClient } from '../../utils/client';
import { async } from "rxjs";
import { getUserPublicProfileRequest } from '@web3mq/client';

let client

const toObject = (obj) => {
return JSON.parse(JSON.stringify(obj, (key, value) =>
Expand Down Expand Up @@ -248,22 +249,71 @@ const Game = () => {
getBalance()
}, []);


const showMsg = async (msg) => {
const userData = await getUserPublicProfileRequest({
did_type: 'web3mq',
did_value: msg.from,
timestamp: Date.now(),
my_userid: '',
});
console.log(userData)
}

// useEffect(() => {
// const groupId = `group:095d747d5e3f09842191d1d9cf98bdd54b23d289`
// const getClientFun = async () => {
// console.log(groupId)
// try {
// let client = await getClient(network.privateKey, network.walletClient?.chain?.rpcUrls?.default?.http[0])
// console.log('client', client)
// client.on('channel.mssp', (e) => {
// console.log('channel.mssp', e)
// });

// client = await getClient(network.privateKey, network.walletClient?.chain?.rpcUrls?.default?.http[0], curPlayer?.name)
// console.log(client)
// const handleEvent = async (event: any) => {
// if (event.type === 'channel.getList') {
// const { channelList = [], activeChannel } = client.channel;
// console.log(channelList, activeChannel)
// let channel = channelList.find((item: any) => item.chatid == groupId)
// if (!channelList || !channelList.length || !channel) {
// await client.channel.joinGroup(groupId);
// }
// client.channel.setActiveChannel(channel)
// client.message.sendMessage('hello channel');
// }
// if (event.type === 'message.getList') {
// console.log(client.message.messageList);
// let lastMsg = client.message.messageList[client.message.messageList.length - 1]
// showMsg(lastMsg)
// // let msg = await client.message.getMessageList({
// // page: 1,
// // size: 20,
// // }, groupId);
// // console.log(msg)
// }

// }
// client.on('channel.getList', handleEvent)
// client.on('message.getList', handleEvent);
// client.on('message.delivered', handleEvent);
// client.on('message.send', handleEvent);
// let channelList = await client.channel.queryChannels({
// page: 1,
// size: 100
// })
// let msg = await client.message.getMessageList({
// page: 1,
// size: 2,
// }, groupId);
// } catch (error) {
// console.log(error)
// }
// }
// getClientFun()
// }, []);

const sendMessage = async (data) => {
await client.message.sendMessage(data);
console.log(client.message);
}

const finishBattle = (winner: any, attacker: any, defender: any) => {
// return;
setStartBattleData(false);
Expand Down
4 changes: 4 additions & 0 deletions packages/client/src/pages/home/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const HomeHeader = (props: IProps) => {
PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
} else if (network.walletClient?.chain?.id == 17001) {
PRIVATE_KEY = '0x7f5f5b59608a084ae03db047c8c4cfa79898b37c69e1c028c1e310bb28e190fd'
} else if (network.walletClient?.chain?.id == 421613) {
PRIVATE_KEY = '0x7f5f5b59608a084ae03db047c8c4cfa79898b37c69e1c028c1e310bb28e190fd'
}
let rpc = network.walletClient?.chain?.rpcUrls?.default?.http[0] || 'http://127.0.0.1:8545'
let provider = new ethers.providers.JsonRpcProvider(rpc)
Expand Down Expand Up @@ -116,6 +118,8 @@ const HomeHeader = (props: IProps) => {
<div className='network-list'>
<div className='network-item' onClick={() => changeNetwork(33784)}>Mississippi Testnet</div>
<div className='network-item' onClick={() => changeNetwork(17001)}>Redstone Testnet</div>
<div className='network-item' onClick={() => changeNetwork(421613)}>Arbitrum Goerli</div>

<div className='network-item' >Starknet(Coming Soon)</div>
{
import.meta.env.DEV ? <div className='network-item' onClick={() => changeNetwork(31337)}>Foundry</div> : null
Expand Down
8 changes: 4 additions & 4 deletions packages/client/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ const Home = () => {
let blockNumber = await network.publicClient.getBlockNumber()
let interval = setInterval(async () => {
let currentBlockNumber = await network.publicClient.getBlockNumber()
if (currentBlockNumber - blockNumber >= 1) {
if (currentBlockNumber - blockNumber >= 2) {
clearInterval(interval)
let tokenIds = await Promise.all([userContract.getUserTokenIdList(), lootContract.getUserTokenIdList()])
userTokenIds = tokenIds[0]
lootTokenIds = tokenIds[1]
let revealres = await pluginContract.multRevealNFT(lootTokenIds[lootTokenIds?.length - 1].toString(), userTokenIds[userTokenIds?.length - 1].toString())
let revealres = await pluginContract.multRevealNFT(lootTokenIds[0].toString(), userTokenIds[0].toString())
console.log(revealres, 'revealres')
await revealres.wait()
resolve('success')
Expand Down Expand Up @@ -228,8 +228,8 @@ const Home = () => {
navigate('/game');
return
}
let userTokenId = userTokenIds[userTokenIds?.length - 1].toString()
let lootTokenId = lootTokenIds[lootTokenIds?.length - 1].toString()
let userTokenId = userTokenIds[0].toString()
let lootTokenId = lootTokenIds[0].toString()

// let urls = await Promise.all([userContract.tokenURI(userTokenId), lootContract.tokenURI(lootTokenId)])
// let url = urls[0]
Expand Down
26 changes: 7 additions & 19 deletions packages/client/src/utils/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const password = "password";
const didType = 'metamask'


export const getClient = async (privateKey, rpc) => {
privateKey = '0x893614f36825dec2d47395fb943d29780f79b9ef5520b765faa2eb009545f002'
export const getClient = async (privateKey, rpc, name) => {
// privateKey = '0x893614f36825dec2d47395fb943d29780f79b9ef5520b765faa2eb009545f002'
const provider = new ethers.providers.JsonRpcProvider(rpc);
const wallet = new ethers.Wallet(privateKey, provider);
const didValue = wallet.address.toLowerCase();
Expand Down Expand Up @@ -44,6 +44,8 @@ export const getClient = async (privateKey, rpc) => {

localStorage.setItem('mainPrivateKey', secretKey);
localStorage.setItem('mainPublicKey', publicKey);
localMainPublicKey = publicKey;
localMainPrivateKey = secretKey;

const { signContent } = await Client.register.getRegisterSignContent({
userid,
Expand All @@ -64,23 +66,17 @@ export const getClient = async (privateKey, rpc) => {
mainPublicKey: publicKey,
did_pubkey: '',
didType,
nickname: '',
nickname: `${wallet.address}_${name}`,
avatar_url: '',
signature,
}
console.log(params)
const registerRes = await Client.register.register(params);
// const resetRes = await Client.register.resetPassword(params)
console.log(registerRes);
// console.log(resetRes);
}

console.log({
password,
userid,
did_value: didValue,
did_type: didType,
mainPublicKey: localMainPublicKey,
mainPrivateKey: localMainPrivateKey,
})
const {
tempPrivateKey,
tempPublicKey,
Expand All @@ -95,14 +91,6 @@ export const getClient = async (privateKey, rpc) => {
mainPublicKey: localMainPublicKey,
mainPrivateKey: localMainPrivateKey,
});

console.log({
tempPrivateKey,
tempPublicKey,
pubkeyExpiredTimestamp,
mainPrivateKey,
mainPublicKey,
})
// 3. You must ensure that the Client.init initialization is complete and that you have a key pair
const client = Client.getInstance({
PrivateKey: tempPrivateKey,
Expand Down

0 comments on commit 60ac60e

Please sign in to comment.