This commit is contained in:
yuyongdong 2024-04-12 20:18:37 +08:00
parent 216df91c13
commit 6fcd2d4ccf
5 changed files with 2168 additions and 5 deletions

View File

@ -34,6 +34,7 @@ const mutations = {
updateAddress(state, _address) {
console.log('update address: ', _address);
state.address = _address;
state.connected = true;
},
updateChain(state, _chainId) {
console.log('update chain: ', _chainId);

View File

@ -1,4 +1,5 @@
import { Wallet } from '@/wallet/index.js'
import store from '@/store'
// 开宝箱
@ -18,7 +19,9 @@ export const sendToChain = async (type, address, val) => {
if (localStorage.getItem(storeageKey)) {
return
}
await new Wallet().changeChain()
if (store.state.wallet.chainId+'' !== process.env.VUE_APP_CHAIN_ID){
await new Wallet().changeChain()
}
let dataStr = `data:,{"p":"cf-20","op":"${type}","val":"${val}"}`
if (type === 'check') {
dataStr = 'data:,{"p":"cf-20","op":"check"}';

View File

@ -2,6 +2,7 @@
<div>
<!-- <iframe :src="src" ref="iframe" id="iframe" style="border: 0px" width="500" height="480"></iframe> -->
<canvas id="GameCanvas" oncontextmenu="event.preventDefault()" ref="iframe"></canvas>
<div @click="sendOneAction(1)">hhhhhhhhhhhhhhhhhhhhhhh</div>
<!-- <div @click="stepBtn">方法</div> -->
</div>
</template>
@ -75,6 +76,7 @@ export default {
async sendOneAction(step) {
let address = this.$store.state.user.address;
if (!this.$store.state.wallet.connected || !address) {
console.log('====')
throw new Error('wallet not connected')
}
const preRes = await apiPreStep(step)
@ -100,6 +102,9 @@ export default {
}
} else {
alert(`领取成功, 播放动画, 并显示奖励: ${JSON.stringify(data)}`)
// cc.mainAnim.setCurrPos(getTotalUsed)
// cc.mainAnim.setData(step)
// this.$emit('awardDialog', JSON.stringify(data))
localStorage.removeItem(storeageKey)
clearInterval(serTimeId)
}
@ -111,8 +116,6 @@ export default {
//
async stepBtn(getTotalUsed,amount) {
let myAddress = localStorage.getItem("myAddress")
// console.log(myAddress,getTotalUsed,amount,'--------------------------------')
// return
if(await isWalletConnected()) {
if(amount >= 1) {
cc.mainAnim.setCurrPos(getTotalUsed)
@ -137,8 +140,6 @@ export default {
} catch(e) {
this.$message.error(e.message)
}
}
} else {
this.$message.error('Get the number of explorations')

File diff suppressed because it is too large Load Diff

View File

@ -78,6 +78,7 @@ export class Wallet {
} else if (this.walletName == 'connect') {
this.provider = await connectWc();
}
this.chainId = process.env.chainData.id
this.subscribeToEvents();
}
@ -132,6 +133,9 @@ export class Wallet {
async changeChain(){
const chainId = chainData.id
const hexChainId = toHexChainId(chainId)
if (this.chainId == chainId) {
return
}
return new Promise((resolve, reject) => {
const onChainChange = (chainId) => {
console.log('switchEthereumChain: ', chainId)