- Connect your wallet to start your Counter Fire journey
+ {{subTitle || 'Connect your wallet to start your Counter Fire journey'}}
{
let list = ALL_PROVIDERS.map((item) => {
const Provider = allProviders[item.id];
const installed = new Provider().installed;
+ const initData = props.initData;
+ let current = null;
+ if (initData) {
+ current = initData[item.id];
+ }
+
+ const tip = installed ? current?.tip || item.tip || '' : "Click to Install";
return {
id: item.id,
name: item.name,
logo: item.logo,
installed,
downloadUrl: item.downloadUrl,
- tip: installed ? item.tip || "" : "Click to Install",
+ tip,
};
});
@@ -60,9 +70,10 @@ const currentDatas = computed(() => {
async function selectWallet(id) {
const Provider = allProviders[id];
- const { provider, accounts } = await new Provider().web3Provider();
+ const walletInstance = new Provider()
+ const { provider, accounts } = await walletInstance.web3Provider();
console.log(accounts)
- hideModal({errcode: 0, provider, wallet: id, accounts});
+ hideModal({errcode: 0, provider, wallet: id, walletInstance, accounts});
}
@@ -76,8 +87,9 @@ async function cardClicked(id) {
return;
}
window.open(data.downloadUrl, '_blank');
- }
- await selectWallet(id);
+ } else {
+ await selectWallet(id);
+ }
}
function cancelSelect() {
diff --git a/src/components/chain/contract/Locker.js b/src/components/chain/contract/Locker.js
index 8f7061f..b867146 100644
--- a/src/components/chain/contract/Locker.js
+++ b/src/components/chain/contract/Locker.js
@@ -42,23 +42,9 @@ export class Locker {
await this.bc.web3Provider.waitForTransaction(res.hash)
return res.hash
}
- // 游戏内资产上链, 用于解锁或铸造
- // 创世英雄, 普通英雄, 金砖
- async unlockOrMintGameNft(nft, tokenIds) {
- console.log('unlock nft', nft, tokenIds)
- await this.bc.checkPassportLogin();
- await this.bc.checkAndChangeChain();
- const preDatas = {
- net_id: import.meta.env.VUE_APP_NET_ID,
- contract_address: nft,
- tokens: tokenIds.map(tokenId => {return { tokenId }}),
- }
- const { errcode, errmsg, trans_req } = await apiUnlockOrMint(preDatas)
- if (errcode) {
- throw new Error(errmsg)
- }
- const { to, data } = trans_req
- const web3Provider = this.bc.passportProvider || this.bc.web3Provider
+
+ async sendUnlockOrMint(provider, {to, data}) {
+
const txHash = await web3Provider.request({
method: 'eth_sendTransaction',
params: [{
@@ -69,4 +55,43 @@ export class Locker {
console.log(txHash)
return txHash
}
+
+ // 游戏内资产上链, 用于解锁或铸造
+ // 创世英雄, 普通英雄, 金砖
+ // imtbl上unlock必须使用passport的provider
+ async unlockOrMintGameNft(nft, tokenIds) {
+ console.log('unlock nft', nft, tokenIds)
+ await this.bc.checkPassportLogin();
+ await this.bc.checkAndChangeChain();
+ const preDatas = {
+ net_id: import.meta.env.VUE_APP_NET_ID,
+ contract_address: nft,
+ tokens: tokenIds.map(tokenId => {return { tokenId }}),
+ }
+ const passportToken = await this.bc.passportToken()
+ const { errcode, errmsg, trans_req } = await apiUnlockOrMint(preDatas, passportToken)
+ if (errcode) {
+ throw new Error(errmsg)
+ }
+ const web3Provider = this.bc.passportProvider || this.bc.web3Provider
+ return this.sendUnlockOrMint(web3Provider, trans_req)
+ }
+ // 游戏内资产上链, 只用于mint
+ // 该方法会显示一个确认弹窗, 由用户选择mint到哪个地址
+ async mintNft(nft, tokenIds) {
+ console.log('mint nft', nft, 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 }}),
+ }
+ const passportToken = await this.bc.passportToken()
+ const { errcode, errmsg, trans_req } = await apiUnlockOrMint(preDatas, passportToken)
+ if (errcode) {
+ throw new Error(errmsg)
+ }
+ return this.sendUnlockOrMint(provider, trans_req)
+ }
}
diff --git a/src/utils/marketplace.js b/src/utils/marketplace.js
index edc9251..b5fe5b9 100644
--- a/src/utils/marketplace.js
+++ b/src/utils/marketplace.js
@@ -7,8 +7,8 @@ const net_id = import.meta.env.VUE_APP_NET_ID
const toJson = res => res.json();
-const httpPost = async (url, data) => {
- const token = await new BlockChain().token();
+const httpPost = async (url, data, token) => {
+ token = token || await new BlockChain().token();
let headers = {"Content-Type": "application/json"};
// let token = token;
if (token) {
@@ -22,8 +22,8 @@ const httpPost = async (url, data) => {
}
-const httpGet = async (url, data) => {
- const token = await new BlockChain().token();
+const httpGet = async (url, data, token) => {
+ token = token || await new BlockChain().token();
let headers = {"Content-Type": "application/json"};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
@@ -106,7 +106,7 @@ export const nftDetail = async(address, tokenId) => {
return httpGet(url, {})
}
-export const apiUnlockOrMint = async (data) => {
+export const apiUnlockOrMint = async (data, token) => {
const url = `${API_BASE}/api/nft/stacking/unlock`
- return httpPost(url, data)
+ return httpPost(url, data, token)
}