修改下链流程, 非passport登录须先登录passport后才能下链

This commit is contained in:
CounterFire2023 2024-07-01 18:38:06 +08:00
parent 24b082b839
commit 3aa924fba8
5 changed files with 65 additions and 17 deletions

View File

@ -13,4 +13,4 @@ VUE_APP_MKT_API='https://market-test.kingsome.cn'
VUE_APP_NET_ID='13473'
VUE_APP_MARKET_CURRENCY='0xFd42bfb03212dA7e1A4608a44d7658641D99CF34'
VUE_APP_MAKEFEE_ADDRESS='0x50A8e60041A206AcaA5F844a1104896224be6F39'
VUE_APP_LOCKER_ADDRESS='0x59e751c2037B710090035B6ea928e0cce80aC03f'
VUE_APP_LOCKER_ADDRESS='0xa83e7F65027aE1a8D0687A87dd157394F03456c0'

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 ConfirmDialog from "@/components/Dialogs/confirmDialog.vue";
export const allProviders = {
@ -65,6 +66,10 @@ export class BlockChain {
}
}
this.store.address = accounts[0];
if (this.store.walletType == 3) {
this.store.passportAddress = accounts[0];
this.passportProvider = provider;
}
this.store.$persist();
this.market.updateProvider(provider);
return provider;
@ -93,6 +98,9 @@ export class BlockChain {
this.store.walletType = result.wallet;
this.wallet = new allProviders[result.wallet]();
await this.updateInfo(result)
if (result.wallet !== 3 && this.store.passportAddress) {
await this.appendPassport();
}
return result.provider
} else {
console.log(`select result : ${result.errmsg}`);
@ -100,10 +108,21 @@ export class BlockChain {
}
}
async appendPassport() {
if (this.store.walletType == 3) {
return;
}
let wallet = new PassportWallet();
const { provider, accounts } = await wallet.web3Provider();
this.passportProvider = provider;
this.store.passportAddress = accounts[0];
this.store.$persist();
}
async token() {
const suffix = (this.store.walletType == 2 || this.store.walletType == 1) ? '.cf' : ''
let token = this.store.token;
if (!suffix) {
if (!suffix && this.store.walletType == 3) {
const res = await this.wallet.getAccessToken();
token = res.token
}
@ -112,6 +131,9 @@ export class BlockChain {
}
async logout() {
if (this.store.walletType != 3 && this.passportProvider) {
new PassportWallet().logout();
}
this.store.reset();
this.store.$persist();
await this.wallet.logout();
@ -131,5 +153,23 @@ export class BlockChain {
}
}
async checkPassportLogin() {
let needLogin = false;
if (this.store.walletType != 3) {
if (!this.store.passportAddress) {
needLogin = true;
}
}
if (needLogin) {
const confirmResult = await createModal(ConfirmDialog, {
title: 'Need login to Passport',
message: 'Are you sure you want to login with Passport?'
}).show()
if (confirmResult.errcode) {
console.log('user cancel')
throw new Error('user cancel')
}
await this.appendPassport();
}
}
}

View File

@ -2,7 +2,7 @@
import { ethers } from 'ethers'
const lockAbi = [
'function lock(address nft, uint256[] tokenIds) external'
'function lock(address nft, address to, uint256[] tokenIds) external'
]
const erc721Abi = [
@ -21,8 +21,11 @@ export class Locker {
async lock(nft, tokenIds) {
// call single method with abi and address
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
console.log('lock', nft, address, tokenIds)
for (let tokenId of tokenIds) {
const addressApproval = await nftContract.getApproved(tokenId)
if ((addressApproval || "").toLowerCase() != lockAddress.toLowerCase()) {
@ -31,8 +34,9 @@ export class Locker {
console.debug('approve', resApproval.hash)
}
}
const contract = new ethers.Contract(lockAddress, lockAbi, this.bc.web3Provider.getSigner())
const res = await contract.lock(nft, tokenIds)
const res = await contract.lock(nft, address, tokenIds)
await this.bc.web3Provider.waitForTransaction(res.hash)
return res.hash
}

File diff suppressed because one or more lines are too long

View File

@ -9,6 +9,8 @@ export const walletStore = defineStore(
const chainId = ref();
const token = ref();
const refreshToken = ref();
const passportAddress = ref();
const showAddress = computed(() => {
if (address.value.length > 10) {
@ -22,11 +24,13 @@ export const walletStore = defineStore(
address.value = '';
chainId.value = '';
token.value = '';
passportAddress.value = '';
refreshToken.value = '';
}
return {
walletType,
address,
passportAddress,
chainId,
token,
refreshToken,