修正任务进行过程中的一些bug
This commit is contained in:
parent
445a136a1d
commit
af38ce6d6a
@ -1,5 +1,6 @@
|
|||||||
# API
|
# API
|
||||||
VUE_APP_API_URL = 'http://192.168.100.22:3006/api'
|
# VUE_APP_API_URL = 'http://192.168.100.22:3006/api'
|
||||||
|
VUE_APP_API_URL = 'http://127.0.0.1:3006/api'
|
||||||
VUE_APP_WL_URL = 'https://nftwl.counterfire.games/wl_test'
|
VUE_APP_WL_URL = 'https://nftwl.counterfire.games/wl_test'
|
||||||
VUE_APP_CONFIG_URL = 'https://sepolia.infura.io/v3/b6bf7d3508c941499b10025c0776eaf8'
|
VUE_APP_CONFIG_URL = 'https://sepolia.infura.io/v3/b6bf7d3508c941499b10025c0776eaf8'
|
||||||
|
|
||||||
@ -10,3 +11,5 @@ VUE_APP_AES_PASS = 'f0cbc08f7afcaa3baeae386860141d072b6840e1'
|
|||||||
VUE_APP_NFT_URL = '0x59e751c2037B710090035B6ea928e0cce80aC03f'
|
VUE_APP_NFT_URL = '0x59e751c2037B710090035B6ea928e0cce80aC03f'
|
||||||
# BEB合约
|
# BEB合约
|
||||||
VUE_APP_BEB_URL = '0x1304E6AA241eE3C9ea44Db9e593e85Ae76eC41F1'
|
VUE_APP_BEB_URL = '0x1304E6AA241eE3C9ea44Db9e593e85Ae76eC41F1'
|
||||||
|
|
||||||
|
VUE_APP_CHAIN_ID = '5611'
|
||||||
|
@ -10,3 +10,5 @@ VUE_APP_AES_PASS = 'f0cbc08f7afcaa3baeae386860141d072b6840e1'
|
|||||||
VUE_APP_NFT_URL = '0x59e751c2037B710090035B6ea928e0cce80aC03f'
|
VUE_APP_NFT_URL = '0x59e751c2037B710090035B6ea928e0cce80aC03f'
|
||||||
# BEB合约
|
# BEB合约
|
||||||
VUE_APP_BEB_URL = '0x1304E6AA241eE3C9ea44Db9e593e85Ae76eC41F1'
|
VUE_APP_BEB_URL = '0x1304E6AA241eE3C9ea44Db9e593e85Ae76eC41F1'
|
||||||
|
|
||||||
|
VUE_APP_CHAIN_ID = '5611'
|
@ -100,7 +100,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
// 链接钱包
|
// 链接钱包
|
||||||
async getLinkWallet(val) {
|
async getLinkWallet(val) {
|
||||||
await addNetwork(val)
|
// await addNetwork(val)
|
||||||
// return
|
// return
|
||||||
if(localStorage.getItem('walletName')) {
|
if(localStorage.getItem('walletName')) {
|
||||||
let res = await linkWallet(val)
|
let res = await linkWallet(val)
|
||||||
|
@ -11,4 +11,13 @@ export const parseTokenData = (token) =>{
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* number to hex string
|
||||||
|
* @param {number} chainId
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
export function toHexChainId(chainId) {
|
||||||
|
return '0x' + chainId.toString(16)
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
const API_BASE = 'http://192.168.100.22:3006'
|
const API_BASE = process.env.VUE_APP_API_URL.replace('/api', '');
|
||||||
import CryptoJS from 'crypto-js'
|
import CryptoJS from 'crypto-js'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
|
@ -492,7 +492,7 @@ import LinkBtn from "./../../components/linkButton/linkBtnView.vue";
|
|||||||
import WalletDialog from "./../../components/walletDialog/index.vue";
|
import WalletDialog from "./../../components/walletDialog/index.vue";
|
||||||
import Web3 from "web3";
|
import Web3 from "web3";
|
||||||
import { getToken } from './../../utils/cookies.js'
|
import { getToken } from './../../utils/cookies.js'
|
||||||
import { getWalletAddress, isWalletConnected } from "./../../wallet/index.js";
|
import { getWalletAddress, isWalletConnected, linkWallet } from "./../../wallet/index.js";
|
||||||
import {
|
import {
|
||||||
apiGameStat,
|
apiGameStat,
|
||||||
apiBeginActivity,
|
apiBeginActivity,
|
||||||
@ -618,6 +618,10 @@ export default {
|
|||||||
this.myInviteCount = this.userData.inviteCount
|
this.myInviteCount = this.userData.inviteCount
|
||||||
this.myEnhanceCount = this.userData.enhanceCount
|
this.myEnhanceCount = this.userData.enhanceCount
|
||||||
this.myAddress = localStorage.getItem("myAddress")
|
this.myAddress = localStorage.getItem("myAddress")
|
||||||
|
let walletName = localStorage.getItem("walletName")
|
||||||
|
if (walletName) {
|
||||||
|
linkWallet(walletName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// if (this.$route.params.name != "undefined") {
|
// if (this.$route.params.name != "undefined") {
|
||||||
// this.helpDialogVisible = true;
|
// this.helpDialogVisible = true;
|
||||||
@ -722,18 +726,44 @@ export default {
|
|||||||
// 领取任务奖励
|
// 领取任务奖励
|
||||||
async getTaskClaim(id) {
|
async getTaskClaim(id) {
|
||||||
let address = localStorage.getItem("myAddress")
|
let address = localStorage.getItem("myAddress")
|
||||||
|
const storeageKey = `${address}_claimTask_${id}`
|
||||||
if(await isWalletConnected()) {
|
if(await isWalletConnected()) {
|
||||||
if(address) {
|
if(address) {
|
||||||
let walletRes = await sendClaimTask(address, id)
|
if (!localStorage.getItem(storeageKey)) {
|
||||||
if (walletRes) {
|
try {
|
||||||
let serTimeId = setInterval(async () => {
|
const chainRes = await sendClaimTask(address, id)
|
||||||
let res = await apiTaskClaim(id)
|
console.log(chainRes)
|
||||||
if(res.data.status == 3) {
|
if (chainRes && chainRes.transactionHash) {
|
||||||
this.getActivitrStatue(id)
|
localStorage.setItem(storeageKey, chainRes.transactionHash)
|
||||||
clearInterval(serTimeId)
|
|
||||||
}
|
}
|
||||||
}, 2000)
|
} catch (err) {
|
||||||
|
this.$message.error(`error send chain request`)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
let serTimeId = setInterval(async () => {
|
||||||
|
try {
|
||||||
|
let { errcode, errmsg, data } = await apiTaskClaim(id)
|
||||||
|
if (errcode) {
|
||||||
|
if (errcode === 12) {
|
||||||
|
// 已领取, 给个提示就可以了
|
||||||
|
this.$message.error(errmsg)
|
||||||
|
this.getActivitrStatue(id)
|
||||||
|
clearInterval(serTimeId)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(data?.status == 3) {
|
||||||
|
alert(`领取成功, 获得积分: ${data.score}`)
|
||||||
|
this.getActivitrStatue(id)
|
||||||
|
clearInterval(serTimeId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
this.$message.error(`claim task reward error: ${err}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 3000)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.walletDialogVisible = true
|
this.walletDialogVisible = true
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,57 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import {hexToBase58} from './../utils/webapi.js'
|
|
||||||
|
import { toHexChainId } from '@/utils/utils'
|
||||||
|
|
||||||
|
|
||||||
// Wallet Connect初始化
|
// Wallet Connect初始化
|
||||||
// import { EthereumProvider } from '@walletconnect/ethereum-provider'
|
import { EthereumProvider } from '@walletconnect/ethereum-provider'
|
||||||
// const provider = await EthereumProvider.init({
|
|
||||||
// projectId: 'e7743d46923911fa8850619b7a7f6d9d', // required
|
const chains = [
|
||||||
// chains: ['421614'], // required
|
{
|
||||||
// showQrModal: true, // requires @walletconnect/modal
|
name: 'opBNB Testnet',
|
||||||
// optionalChains: ['421614'],
|
type: 'Testnet',
|
||||||
// // optionalMethods: ['eth_signTypedData', 'eth_signTypedData_v4'],
|
rpc: 'https://opbnb-testnet-rpc.bnbchain.org',
|
||||||
// metadata: {
|
id: 5611,
|
||||||
// name: 'Counter Fire',
|
symbol: 'tBNB',
|
||||||
// description: 'Counter Fire',
|
explorerurl: 'https://opbnb-testnet.bscscan.com',
|
||||||
// url: 'http://192.168.100.216:8030/',
|
},
|
||||||
// icons: ['https://www.counterfire.games/favicon.ico'],
|
{
|
||||||
// },
|
name: 'opBNB Mainnet',
|
||||||
// });
|
type: 'Mainnet',
|
||||||
// 链接Wallet Connect钱包
|
rpc: 'https://opbnb-rpc.publicnode.com',
|
||||||
export async function getConnect() {
|
id: 204,
|
||||||
await provider.connect()
|
symbol: 'BNB',
|
||||||
let result = await provider.request({ method: 'eth_requestAccounts' })
|
explorerurl: 'https://mainnet.opbnbscan.com',
|
||||||
return result
|
},
|
||||||
|
]
|
||||||
|
const chain_define = parseInt(process.env.VUE_APP_CHAIN_ID)
|
||||||
|
const chainData = chains.find((chain) => chain.id === chain_define)
|
||||||
|
|
||||||
|
if (!chainData) {
|
||||||
|
throw new Error('chain not supported')
|
||||||
}
|
}
|
||||||
|
|
||||||
const chainData = {
|
const connectWc = async() => {
|
||||||
name: 'Arbitrum Sepolia',
|
const wc = await EthereumProvider.init({
|
||||||
type: 'Testnet',
|
projectId: 'e7743d46923911fa8850619b7a7f6d9d', // required
|
||||||
rpc: 'https://arb-sepolia.g.alchemy.com/v2/mHoYM0SyjeizxvdjShcdOHiCrXOM_mlg|https://arb-sepolia.g.alchemy.com/v2/EKR1je8ZGia332kkemNc4mtXQuFskIq3',
|
chains: [chain_define+''], // required
|
||||||
id: 421614,
|
showQrModal: true, // requires @walletconnect/modal
|
||||||
network: 'ARB_SEPOLIA',
|
optionalChains: [chain_define+''],
|
||||||
symbol: 'ETH',
|
// optionalMethods: ['eth_signTypedData', 'eth_signTypedData_v4'],
|
||||||
explorerurl: 'https://sepolia.arbiscan.io',
|
metadata: {
|
||||||
|
name: 'Counter Fire',
|
||||||
|
description: 'Counter Fire',
|
||||||
|
url: 'http://192.168.100.216:8030/',
|
||||||
|
icons: ['https://www.counterfire.games/favicon.ico'],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return wc
|
||||||
}
|
}
|
||||||
|
let provider = null
|
||||||
|
|
||||||
export async function getWalletAddress() {
|
export async function getWalletAddress() {
|
||||||
const web3js = window.ethereum
|
|
||||||
const web3 = await web3js.request({
|
const web3 = await provider.request({
|
||||||
method: 'eth_accounts'
|
method: 'eth_accounts'
|
||||||
})
|
})
|
||||||
if (web3 !== 'undefined') {
|
if (web3 !== 'undefined') {
|
||||||
@ -46,7 +61,7 @@ export async function getWalletAddress() {
|
|||||||
return await web3[0]
|
return await web3[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// 签到
|
// 签到
|
||||||
@ -79,9 +94,9 @@ export const dailyCheckIn = async() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 开箱子
|
// 开箱子
|
||||||
export const changeChain = async(provider) => {
|
export const changeChain = async() => {
|
||||||
const chainId = chainData.id
|
const chainId = chainData.id
|
||||||
const hexChainId = hexToBase58(chainId)
|
const hexChainId = toHexChainId(chainId)
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const onChainChange = (chainId) => {
|
const onChainChange = (chainId) => {
|
||||||
console.log('switchEthereumChain: ', chainId)
|
console.log('switchEthereumChain: ', chainId)
|
||||||
@ -130,39 +145,24 @@ export const changeChain = async(provider) => {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// 链接钱包
|
// 链接钱包
|
||||||
export const linkWallet = async(name) => {
|
export const linkWallet = async(name) => {
|
||||||
if(name == "ethereum") {
|
if(name == "ethereum") {
|
||||||
const web3js = window.ethereum
|
provider = window.ethereum
|
||||||
if (typeof web3js !== "undefined") {
|
|
||||||
let res = await ethereum.request({ method: "eth_requestAccounts" })
|
|
||||||
// this.getAddress = res[0]
|
|
||||||
// localStorage.setItem('walletName', name)
|
|
||||||
// localStorage.setItem('address', res[0])
|
|
||||||
return res[0]
|
|
||||||
}
|
|
||||||
} else if(name == "okxwallet") {
|
} else if(name == "okxwallet") {
|
||||||
let res = await okxwallet.request({ method: "eth_requestAccounts" });
|
provider = window.okxwallet
|
||||||
// this.getAddress = res[0]
|
|
||||||
// localStorage.setItem('walletName', name)
|
|
||||||
// localStorage.setItem('address', res[0])
|
|
||||||
return res[0]
|
|
||||||
} else if(name == "connect") {
|
} else if(name == "connect") {
|
||||||
let res = await getConnect()
|
provider = await connectWc()
|
||||||
console.log(res[0],'getConnect---------------------------------------')
|
|
||||||
// this.getAddress = res[0]
|
|
||||||
// localStorage.setItem('walletName', name)
|
|
||||||
// localStorage.setItem('address', res[0])
|
|
||||||
return res[0]
|
|
||||||
}
|
}
|
||||||
location.reload()
|
let res = await provider.request({ method: "eth_requestAccounts" })
|
||||||
|
return res[0]
|
||||||
|
// location.reload()
|
||||||
};
|
};
|
||||||
|
|
||||||
// 断开链接
|
// 断开链接
|
||||||
export async function disconnectLink(name) {
|
export async function disconnectLink(name) {
|
||||||
if(name == 'ethereum') {
|
if(name == 'ethereum') {
|
||||||
await window.ethereum.request({
|
await provider.request({
|
||||||
"method": "wallet_revokePermissions",
|
"method": "wallet_revokePermissions",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
@ -171,7 +171,7 @@ export async function disconnectLink(name) {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
} else if(name == 'okxwallet') {
|
} else if(name == 'okxwallet') {
|
||||||
await okxwallet.request({
|
await provider.request({
|
||||||
"method": "wallet_disconnect",
|
"method": "wallet_disconnect",
|
||||||
})
|
})
|
||||||
} else if(name == 'connect') {
|
} else if(name == 'connect') {
|
||||||
@ -182,10 +182,10 @@ export async function disconnectLink(name) {
|
|||||||
|
|
||||||
// 查看钱包
|
// 查看钱包
|
||||||
export async function isWalletConnected() {
|
export async function isWalletConnected() {
|
||||||
const ethereum = window.web3;
|
|
||||||
if (typeof ethereum !== 'undefined') {
|
if (provider) {
|
||||||
// let res = await window.ethereum.request({ "method": "eth_accounts" })
|
// let res = await window.ethereum.request({ "method": "eth_accounts" })
|
||||||
let res = await window.okxwallet.request({ method: "eth_accounts" });
|
let res = await provider.request({ method: "eth_accounts" });
|
||||||
if(res[0] == undefined) {
|
if(res[0] == undefined) {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
@ -198,52 +198,5 @@ export async function isWalletConnected() {
|
|||||||
|
|
||||||
// 添加网络
|
// 添加网络
|
||||||
export async function addNetwork(name) {
|
export async function addNetwork(name) {
|
||||||
if(name == 'ethereum') {
|
changeChain()
|
||||||
// const chainId = await ethereum.request({ method: 'eth_chainId' })
|
|
||||||
// console.log(chainId,'------------------')
|
|
||||||
// return
|
|
||||||
try{
|
|
||||||
let res = await window.ethereum.request({
|
|
||||||
method: 'wallet_addEthereumChain',
|
|
||||||
params: [{
|
|
||||||
chainId: '0x15eb',
|
|
||||||
// chainId: '5611',
|
|
||||||
chainName: 'opBNB Testnet',
|
|
||||||
rpcUrls: ['https://opbnb-testnet-rpc.bnbchain.org'],
|
|
||||||
iconUrls: ['https://xdaichain.com/fake/example/url/xdai.png'],
|
|
||||||
blockExplorerUrls: ['https://opbnb-testnet.bscscan.com'],
|
|
||||||
nativeCurrency: {
|
|
||||||
name: "tBNB",
|
|
||||||
symbol: "tBNB",
|
|
||||||
decimals: 18
|
|
||||||
},
|
|
||||||
},]
|
|
||||||
})
|
|
||||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// let res = await window.ethereum.request({
|
|
||||||
// method: 'wallet_addEthereumChain',
|
|
||||||
// params: [{
|
|
||||||
// chainId: '0x38',
|
|
||||||
// chainName: 'opBNB Testnet',
|
|
||||||
// rpcUrls: ['https://opbnb-rpc.publicnode.com'],
|
|
||||||
// iconUrls: ['https://xdaichain.com/fake/example/url/xdai.png'],
|
|
||||||
// blockExplorerUrls: ['https://mainnet.opbnbscan.com'],
|
|
||||||
// nativeCurrency: {
|
|
||||||
// name: "BNB",
|
|
||||||
// symbol: "BNB",
|
|
||||||
// decimals: 18
|
|
||||||
// },
|
|
||||||
// },]
|
|
||||||
// })
|
|
||||||
return await res
|
|
||||||
} catch(e) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else if(name == 'okxwallet') {
|
|
||||||
await okxwallet.request({
|
|
||||||
"method": "wallet_disconnect",
|
|
||||||
})
|
|
||||||
} else if(name == 'connect') {
|
|
||||||
await provider.request({method: 'eth_requestDisconnect'})
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user