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

This commit is contained in:
yuyongdong 2024-07-17 15:18:11 +08:00
commit 0faffa2863
3 changed files with 36 additions and 19 deletions

View File

@ -1,6 +1,6 @@
import { ethers } from 'ethers'
import { apiUnlockOrMint } from '@/utils/marketplace'
import { apiUnlockOrMint, apiMintNft } from '@/utils/marketplace'
const lockAbi = [
'function lock(address nft, address to, uint256[] tokenIds) external',
@ -47,7 +47,7 @@ export class Locker {
async sendUnlockOrMint(provider, {to, data}) {
const txHash = await web3Provider.request({
const txHash = await provider.request({
method: 'eth_sendTransaction',
params: [{
to,
@ -80,17 +80,15 @@ export class Locker {
}
// 游戏内资产上链, 只用于mint
// 该方法会显示一个确认弹窗, 由用户选择mint到哪个地址
async mintNft(nft, tokenIds) {
console.log('mint nft', nft, tokenIds)
const { provider, address } = await this.bc.selectAddress()
async mintNft(tokenIds) {
console.log('mint hero', tokenIds)
const { provider, address } = await this.bc.selectAddress({})
const preDatas = {
net_id: import.meta.env.VUE_APP_NET_ID,
to: address,
contract_address: nft,
tokens: tokenIds.map(tokenId => {return { tokenId }}),
hero_uniids: tokenIds,
}
const passportToken = await this.bc.passportToken()
const { errcode, errmsg, trans_req } = await apiUnlockOrMint(preDatas, passportToken)
const { errcode, errmsg, trans_req } = await apiMintNft(preDatas, passportToken)
if (errcode) {
throw new Error(errmsg)
}

View File

@ -47,8 +47,11 @@
</div>
<div class="metaMask-login" v-if="!localWalletStore.address" @click="immuTableLogin">Login</div>
<div class="metaMask-login-active" v-else @click="showMenu = !showMenu">
<div class="matamask">
<div class="metamask">
<div class="title">{{ localWalletStore.showAddress }}</div>
<svg @click="handleCopy" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M11.35 3.836c-.065.21-.1.433-.1.664 0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75 2.25 2.25 0 0 0-.1-.664m-5.8 0A2.251 2.251 0 0 1 13.5 2.25H15c1.012 0 1.867.668 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V8.25m8.9-4.414c.376.023.75.05 1.124.08 1.131.094 1.976 1.057 1.976 2.192V16.5A2.25 2.25 0 0 1 18 18.75h-2.25m-7.5-10.5H4.875c-.621 0-1.125.504-1.125 1.125v11.25c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V18.75m-7.5-10.5h6.375c.621 0 1.125.504 1.125 1.125v9.375m-8.25-3 1.5 1.5 3-3.75" />
</svg>
</div>
<div class="menu" v-show="showMenu">
<div class="menu-item" @click="immuTableLogout">Logout</div>
@ -62,7 +65,8 @@
</template>
<script setup>
import { ref, reactive, onMounted, computed, watchEffect, getCurrentInstance, watch } from "vue";
import { ref, reactive, onMounted, computed, watchEffect, getCurrentInstance, watch, inject } from "vue";
const message = inject('$message')
const { proxy } = getCurrentInstance();
import { useAppStore } from "@/store/app";
import { hasMetamask } from "@/utils/chain.util";
@ -155,9 +159,9 @@ function click(event) {
//const { copied, copyToClipboard } = useCopyToClipboard(AppModule.accountId);
const { copied, error, reset, copyToClipboard } = useCopyToClipboard();
const message = copied.value
? "Text copied!"
: "Click the button to copy text.";
// const message = copied.value
// ? "Text copied!"
// : "Click the button to copy text.";
@ -190,13 +194,14 @@ function handNavCurent(nav) {
function openThirdPartyLink(url) {
window.open(url, "_blank");
}
const handleCopy = () => {
const accountId = AppModule.accountId;
const handleCopy = (e) => {
e.stopPropagation();
const accountId = localWalletStore.address;
reset();
copyToClipboard(accountId).then(() => {
// if (copied.value) {
// message.success("Copy successful!");
// }
if (copied.value) {
message.success("address copied");
}
});
};
watchEffect(() => {
@ -594,6 +599,14 @@ onMounted( async () => {
a:hover {
background-color: #f5f5f5;
}
.metamask{
display: flex;
svg {
width: 24px;
height: 24px;
margin-left: 6px;
}
}
}
.immutable-cart {
color: #fff;

View File

@ -129,3 +129,9 @@ export const apiUnlockOrMint = async (data, token) => {
const url = `${API_BASE}/api/nft/stacking/unlock`
return httpPost(url, data, token)
}
export const apiMintNft = async (data, token) => {
const url = `${API_BASE}/api/ingame/asset/hero/mint`
return httpPost(url, data, token)
}