Merge branch 'new-CounterFire' of http://git.kingsome.cn/huangjinming/CounterFireGames into new-CounterFire-0724

This commit is contained in:
yuyongdong 2024-08-01 15:40:19 +08:00
commit b70988c946
3 changed files with 58 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import {isTokenExpired, genRefreshToken, cfgChainId, switchEthereumChain} from "
import {ImtblMarket} from "@/components/chain/Market";
import { ALL_PROVIDERS } from "@/configs/configchain";
import {Locker} from "@/components/chain/contract/Locker";
import {GameItemMall} from "@/components/chain/contract/GameItemMall";
import ConfirmDialog from "@/components/Dialogs/confirmDialog.vue";
import { Widgets } from "./Widgets";
@ -28,6 +29,7 @@ export class BlockChain {
this.initWallet();
this.market = new ImtblMarket(this)
this.locker = new Locker(this)
this.mall = new GameItemMall(this)
this.widgets = new Widgets(this)
BlockChain.instance = this;

View File

@ -0,0 +1,50 @@
import { apiPreRecharge } from '@/utils/marketplace'
export class GameItemMall {
constructor(_chainInstance) {
this.bc = _chainInstance
}
async sendTransaction(provider, {from, to, data}) {
const txHash = await provider.provider.request({
method: 'eth_sendTransaction',
params: [{
from,
to,
data
}]
})
console.log(txHash)
const res = await provider.waitForTransaction(txHash)
if (res.status == 0) {
throw new Error('transaction failed')
}
return txHash
}
async execBuyItem(itemId) {
await this.bc.checkPassportLogin();
const chainId = parseInt(import.meta.env.VUE_APP_NET_ID);
const { provider, address } = await this.bc.selectAddress({targetChainId: chainId})
const preDatas = {
net_id: address,
goods_id: itemId,
account_address: address,
}
const { errocode, errmsg, calls } = await apiPreRecharge(preDatas)
if (errocode) {
throw new Error(errmsg)
}
if (!calls || calls.length == 0) {
throw new Error('no calls')
}
let resutls = []
for (let i = 0; i < calls.length; i++) {
const { to, data } = calls[i].trans_req
let hash = await this.sendTransaction(provider, {from: address, to, data})
resutls.push(hash)
}
return resutls
}
}

View File

@ -177,3 +177,9 @@ export const apiRechargeHistory = async (account_address) => {
const url = `${API_BASE}/api/recharge/history/${net_id}/${account_address}`
return httpPost(url, {})
}
// 充值-购买
export const apiPreRecharge = async (data) => {
const url = `${API_BASE}/api/recharge/buy`
return httpPost(url, data)
}