Merge branch 'new-CounterFire' of http://git.kingsome.cn/huangjinming/CounterFireGames into new-CounterFire
This commit is contained in:
commit
9847e3cc21
5
.env.dev
5
.env.dev
@ -16,4 +16,7 @@ VUE_APP_MARKET_CURRENCY='0xFd42bfb03212dA7e1A4608a44d7658641D99CF34'
|
|||||||
VUE_APP_MAKEFEE_ADDRESS='0x50A8e60041A206AcaA5F844a1104896224be6F39'
|
VUE_APP_MAKEFEE_ADDRESS='0x50A8e60041A206AcaA5F844a1104896224be6F39'
|
||||||
VUE_APP_LOCKER_ADDRESS='0xC8607507451059CfAe6Ca4D07EC6f631ce8ef9f9'
|
VUE_APP_LOCKER_ADDRESS='0xC8607507451059CfAe6Ca4D07EC6f631ce8ef9f9'
|
||||||
VUE_APP_EXPLORER_URL='https://explorer.testnet.immutable.com'
|
VUE_APP_EXPLORER_URL='https://explorer.testnet.immutable.com'
|
||||||
VUE_APP_PRODUCTION=sandbox
|
VUE_APP_PRODUCTION=sandbox
|
||||||
|
|
||||||
|
VUE_APP_NET_ID_MAIN='11155111'
|
||||||
|
VUE_APP_LOCKER_ADDRESS_MAIN='0x7F2b4DB626d878778e178B4F0C7bA3a2870C6dd0'
|
@ -16,4 +16,7 @@ VUE_APP_MARKET_CURRENCY='0xFd42bfb03212dA7e1A4608a44d7658641D99CF34'
|
|||||||
VUE_APP_MAKEFEE_ADDRESS='0x50A8e60041A206AcaA5F844a1104896224be6F39'
|
VUE_APP_MAKEFEE_ADDRESS='0x50A8e60041A206AcaA5F844a1104896224be6F39'
|
||||||
VUE_APP_LOCKER_ADDRESS='0xC8607507451059CfAe6Ca4D07EC6f631ce8ef9f9'
|
VUE_APP_LOCKER_ADDRESS='0xC8607507451059CfAe6Ca4D07EC6f631ce8ef9f9'
|
||||||
VUE_APP_EXPLORER_URL='https://explorer.testnet.immutable.com'
|
VUE_APP_EXPLORER_URL='https://explorer.testnet.immutable.com'
|
||||||
VUE_APP_PRODUCTION=sandbox
|
VUE_APP_PRODUCTION=sandbox
|
||||||
|
|
||||||
|
VUE_APP_NET_ID_MAIN='11155111'
|
||||||
|
VUE_APP_LOCKER_ADDRESS_MAIN='0x7F2b4DB626d878778e178B4F0C7bA3a2870C6dd0'
|
@ -71,6 +71,9 @@ export class BlockChain {
|
|||||||
if (this.store.walletType == 3) {
|
if (this.store.walletType == 3) {
|
||||||
this.store.passportAddress = accounts[0];
|
this.store.passportAddress = accounts[0];
|
||||||
this.passportProvider = provider;
|
this.passportProvider = provider;
|
||||||
|
} else {
|
||||||
|
this.store.eoaAddress = accounts[0];
|
||||||
|
this.eoaProvider = provider;
|
||||||
}
|
}
|
||||||
this.store.$persist();
|
this.store.$persist();
|
||||||
this.market.updateProvider(provider);
|
this.market.updateProvider(provider);
|
||||||
@ -110,7 +113,9 @@ export class BlockChain {
|
|||||||
throw new Error(result.errmsg);
|
throw new Error(result.errmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 用于eoa登录后, 添加passport地址
|
||||||
|
*/
|
||||||
async appendPassport() {
|
async appendPassport() {
|
||||||
if (this.store.walletType == 3) {
|
if (this.store.walletType == 3) {
|
||||||
return;
|
return;
|
||||||
@ -121,6 +126,28 @@ export class BlockChain {
|
|||||||
this.store.passportAddress = accounts[0];
|
this.store.passportAddress = accounts[0];
|
||||||
this.store.$persist();
|
this.store.$persist();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 用于passport登录后, 添加eoa地址
|
||||||
|
*/
|
||||||
|
async appendEoa() {
|
||||||
|
if (this.store.walletType != 3) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const rewardModal = createModal(WalletSelectModel, {
|
||||||
|
title: title || 'Select Address',
|
||||||
|
message: subTitle || 'Please select the address you want to use',
|
||||||
|
initData: { 1: 'MetaMask', 2: 'OKX Wallet', 3: 'Passport' },
|
||||||
|
disabled: [3]
|
||||||
|
});
|
||||||
|
const { errcode, errmsg, walletInstance, provider, accounts } = await rewardModal.show();
|
||||||
|
if (errcode) {
|
||||||
|
console.log(`select address result : ${errmsg}`);
|
||||||
|
throw new Error(errmsg);
|
||||||
|
}
|
||||||
|
this.eoaProvider = provider;
|
||||||
|
this.store.eoaAddress = accounts[0];
|
||||||
|
this.store.$persist();
|
||||||
|
}
|
||||||
|
|
||||||
async token() {
|
async token() {
|
||||||
const suffix = (this.store.walletType == 2 || this.store.walletType == 1) ? '.cf' : ''
|
const suffix = (this.store.walletType == 2 || this.store.walletType == 1) ? '.cf' : ''
|
||||||
@ -135,6 +162,19 @@ export class BlockChain {
|
|||||||
|
|
||||||
return token+suffix
|
return token+suffix
|
||||||
}
|
}
|
||||||
|
// 检查是否已登录aoa
|
||||||
|
get eoaLogined() {
|
||||||
|
return this.store.walletType != 3 || !!this.store.eoaAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查passport是否已登录
|
||||||
|
*/
|
||||||
|
get passportLogined() {
|
||||||
|
return this.store.walletType == 3 || !!this.store.passportAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果是用passport登录的, 直接返回store中的token, 否则调用passport的getAccessToken
|
* 如果是用passport登录的, 直接返回store中的token, 否则调用passport的getAccessToken
|
||||||
* @returns
|
* @returns
|
||||||
@ -144,7 +184,7 @@ export class BlockChain {
|
|||||||
return this.token()
|
return this.token()
|
||||||
}
|
}
|
||||||
if (!this.passportProvider) {
|
if (!this.passportProvider) {
|
||||||
return ''
|
throw new Error('need login to Passport')
|
||||||
}
|
}
|
||||||
const res = await new PassportWallet().getAccessToken();
|
const res = await new PassportWallet().getAccessToken();
|
||||||
return res.token
|
return res.token
|
||||||
|
@ -41,7 +41,8 @@ const props = defineProps({
|
|||||||
close: Function,
|
close: Function,
|
||||||
title: ref(String),
|
title: ref(String),
|
||||||
subTitle: ref(String),
|
subTitle: ref(String),
|
||||||
initData: Object
|
initData: Object,
|
||||||
|
disabled: Array
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentDatas = computed(() => {
|
const currentDatas = computed(() => {
|
||||||
@ -64,7 +65,8 @@ const currentDatas = computed(() => {
|
|||||||
tip,
|
tip,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
const disabled = props.disabled || [];
|
||||||
|
list = list.filter((item) => !disabled.includes(item.id));
|
||||||
return list;
|
return list;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ const erc721Abi = [
|
|||||||
'function getApproved(uint256 tokenId) public view returns (address)'
|
'function getApproved(uint256 tokenId) public view returns (address)'
|
||||||
]
|
]
|
||||||
|
|
||||||
const lockAddress = import.meta.env.VUE_APP_LOCKER_ADDRESS
|
const lockAddressImtbl = import.meta.env.VUE_APP_LOCKER_ADDRESS
|
||||||
|
const lockAddressMain = import.meta.env.VUE_APP_LOCKER_ADDRESS_MAIN
|
||||||
|
|
||||||
export class Locker {
|
export class Locker {
|
||||||
|
|
||||||
@ -20,28 +21,39 @@ export class Locker {
|
|||||||
this.bc = _chainInstance
|
this.bc = _chainInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
async lock(nft, tokenIds) {
|
async execLock(provider, lockAddress, nft, tokenIds) {
|
||||||
// call single method with abi and address
|
const nftContract = new ethers.Contract(nft, erc721Abi, provider.getSigner())
|
||||||
console.log('lock nft', nft, tokenIds)
|
|
||||||
await this.bc.checkPassportLogin();
|
|
||||||
await this.bc.checkAndChangeChain();
|
|
||||||
const nftContract = new ethers.Contract(nft, erc721Abi, this.bc.web3Provider.getSigner())
|
|
||||||
const address = this.bc.store.passportAddress
|
const address = this.bc.store.passportAddress
|
||||||
console.log('lock', nft, address, tokenIds)
|
console.log('lock', nft, address, tokenIds)
|
||||||
for (let tokenId of tokenIds) {
|
for (let tokenId of tokenIds) {
|
||||||
const addressApproval = await nftContract.getApproved(tokenId)
|
const addressApproval = await nftContract.getApproved(tokenId)
|
||||||
if ((addressApproval || "").toLowerCase() != lockAddress.toLowerCase()) {
|
if ((addressApproval || "").toLowerCase() != lockAddress.toLowerCase()) {
|
||||||
const resApproval = await nftContract.approve(lockAddress, tokenId);
|
const resApproval = await nftContract.approve(lockAddress, tokenId);
|
||||||
await this.bc.web3Provider.waitForTransaction(resApproval.hash)
|
await provider.waitForTransaction(resApproval.hash)
|
||||||
console.debug('approve', resApproval.hash)
|
console.debug('approve', resApproval.hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const contract = new ethers.Contract(lockAddress, lockAbi, this.bc.web3Provider.getSigner())
|
const contract = new ethers.Contract(lockAddress, lockAbi, provider.getSigner())
|
||||||
const res = await contract.lock(nft, address, tokenIds)
|
const res = await contract.lock(nft, address, tokenIds)
|
||||||
await this.bc.web3Provider.waitForTransaction(res.hash)
|
await provider.waitForTransaction(res.hash)
|
||||||
return res.hash
|
return res.hash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async lock(nft, tokenIds) {
|
||||||
|
console.log('lock nft', nft, tokenIds)
|
||||||
|
await this.bc.checkPassportLogin();
|
||||||
|
await this.bc.checkAndChangeChain();
|
||||||
|
return this.execLock(this.bc.web3Provider, lockAddressImtbl, nft, tokenIds)
|
||||||
|
}
|
||||||
|
|
||||||
|
async lockMain(nft, tokenIds) {
|
||||||
|
console.log('lock nft on main', nft, tokenIds)
|
||||||
|
const chainId = parseInt(import.meta.env.VUE_APP_NET_ID_MAIN);
|
||||||
|
await this.bc.checkPassportLogin();
|
||||||
|
await this.bc.checkAndChangeChain(chainId);
|
||||||
|
return this.execLock(this.bc.eoaProvider, lockAddressMain, nft, tokenIds)
|
||||||
|
}
|
||||||
|
|
||||||
async sendUnlockOrMint(provider, {from, to, data}) {
|
async sendUnlockOrMint(provider, {from, to, data}) {
|
||||||
|
|
||||||
@ -57,19 +69,9 @@ export class Locker {
|
|||||||
await provider.waitForTransaction(txHash)
|
await provider.waitForTransaction(txHash)
|
||||||
return txHash
|
return txHash
|
||||||
}
|
}
|
||||||
|
async execUnlock(chainId, nft, tokenIds) {
|
||||||
// 游戏内资产上链, 用于解锁或铸造
|
|
||||||
// 创世英雄, 普通英雄, 金砖
|
|
||||||
// imtbl上unlock必须使用passport的provider
|
|
||||||
async unlockOrMintGameNft(nft, tokenIds) {
|
|
||||||
console.log('unlock nft', nft, tokenIds)
|
|
||||||
const blockChain = new BlockChain()
|
|
||||||
const { provider, address } = await this.bc.selectAddress({})
|
|
||||||
await this.bc.checkPassportLogin();
|
|
||||||
await this.bc.checkAndChangeChain();
|
|
||||||
const preDatas = {
|
const preDatas = {
|
||||||
net_id: import.meta.env.VUE_APP_NET_ID,
|
net_id: chainId,
|
||||||
to: address,
|
|
||||||
contract_address: nft,
|
contract_address: nft,
|
||||||
tokens: tokenIds.map(token_id => {return { token_id }}),
|
tokens: tokenIds.map(token_id => {return { token_id }}),
|
||||||
}
|
}
|
||||||
@ -81,22 +83,48 @@ export class Locker {
|
|||||||
const web3Provider = this.bc.passportProvider || this.bc.web3Provider
|
const web3Provider = this.bc.passportProvider || this.bc.web3Provider
|
||||||
return this.sendUnlockOrMint(web3Provider, trans_req)
|
return this.sendUnlockOrMint(web3Provider, trans_req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// imbtl上游戏内资产上链, 用于解锁或铸造
|
||||||
|
// 创世英雄, 普通英雄, 金砖
|
||||||
|
// 必须使用passport的provider
|
||||||
|
async unlockOrMintGameNft(nft, tokenIds) {
|
||||||
|
console.log('unlock nft', nft, tokenIds)
|
||||||
|
await this.bc.checkPassportLogin();
|
||||||
|
await this.bc.checkAndChangeChain();
|
||||||
|
const chainId = import.meta.env.VUE_APP_NET_ID;
|
||||||
|
return this.execUnlock(chainId, nft, tokenIds)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ethereum上解锁
|
||||||
|
* @param {*} nft
|
||||||
|
* @param {*} tokenIds
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async unlockMain(nft, tokenIds) {
|
||||||
|
console.log('unlock nft on main', nft, tokenIds)
|
||||||
|
const chainId = parseInt(import.meta.env.VUE_APP_NET_ID_MAIN);
|
||||||
|
await this.bc.checkPassportLogin();
|
||||||
|
await this.bc.checkAndChangeChain(chainId);
|
||||||
|
// const address = this.bc.store.eoaAddress
|
||||||
|
return this.execUnlock(chainId, nft, tokenIds)
|
||||||
|
}
|
||||||
|
|
||||||
// 游戏内资产上链, 只用于mint
|
// 游戏内资产上链, 只用于mint
|
||||||
// 该方法会显示一个确认弹窗, 由用户选择mint到哪个地址
|
// 该方法会显示一个确认弹窗, 由用户选择mint到哪个地址
|
||||||
async mintNft(tokenIds) {
|
async mintNft(tokenIds) {
|
||||||
console.log('mint hero', tokenIds)
|
console.log('mint hero', tokenIds)
|
||||||
const blockChain = new BlockChain()
|
const { provider, address } = await this.bc.selectAddress({})
|
||||||
const { provider, address } = await blockChain.selectAddress({})
|
|
||||||
const preDatas = {
|
const preDatas = {
|
||||||
to: address,
|
to: address,
|
||||||
hero_uniids: tokenIds,
|
hero_uniids: tokenIds,
|
||||||
}
|
}
|
||||||
const passportToken = await blockChain.passportToken()
|
const passportToken = await this.bc.passportToken()
|
||||||
const { errcode, errmsg, trans_req } = await apiMintNft(preDatas, passportToken)
|
const { errcode, errmsg, trans_req } = await apiMintNft(preDatas, passportToken)
|
||||||
if (errcode) {
|
if (errcode) {
|
||||||
throw new Error(errmsg)
|
throw new Error(errmsg)
|
||||||
}
|
}
|
||||||
trans_req.from = address
|
trans_req.from = address
|
||||||
return this.sendUnlockOrMint(blockChain.web3Provider, trans_req)
|
return this.sendUnlockOrMint(this.bc.web3Provider, trans_req)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ export const walletStore = defineStore(
|
|||||||
const token = ref();
|
const token = ref();
|
||||||
const refreshToken = ref();
|
const refreshToken = ref();
|
||||||
const passportAddress = ref();
|
const passportAddress = ref();
|
||||||
|
const eoaAddress = ref();
|
||||||
|
|
||||||
|
|
||||||
const showAddress = computed(() => {
|
const showAddress = computed(() => {
|
||||||
@ -26,6 +27,7 @@ export const walletStore = defineStore(
|
|||||||
token.value = '';
|
token.value = '';
|
||||||
passportAddress.value = '';
|
passportAddress.value = '';
|
||||||
refreshToken.value = '';
|
refreshToken.value = '';
|
||||||
|
eoaAddress.value = '';
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
walletType,
|
walletType,
|
||||||
@ -35,6 +37,7 @@ export const walletStore = defineStore(
|
|||||||
token,
|
token,
|
||||||
refreshToken,
|
refreshToken,
|
||||||
showAddress,
|
showAddress,
|
||||||
|
eoaAddress,
|
||||||
reset,
|
reset,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user