From 0672798d6402b2bfd2c83faf19aef0f929027c79 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Mon, 22 Jul 2024 13:44:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E9=93=BE=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chain/BlockChain.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/chain/BlockChain.js b/src/components/chain/BlockChain.js index fa7ddbf..02f85e1 100644 --- a/src/components/chain/BlockChain.js +++ b/src/components/chain/BlockChain.js @@ -209,6 +209,8 @@ export class BlockChain { async logout() { if (this.store.walletType != 3 && this.passportProvider) { new PassportWallet().logout(); + } else if (this.store.walletType == 3 && this.eoaWallet) { + await this.eoaWallet.logout(); } this.store.reset(); this.store.$persist(); @@ -239,16 +241,20 @@ export class BlockChain { console.log(`current chain: ${chainId}, want: ${targetChainId}`) chainId = await switchEthereumChain(provider.provider, targetChainId); } - + let eoaAddress; if (this.store.walletType == 3) { const { provider, accounts } = await this.eoaWallet.web3Provider(); this.eoaProvider = provider; + eoaAddress = accounts[0]; } else { const { provider, accounts } = await this.wallet.web3Provider(); this.web3Provider = provider; this.eoaProvider = provider; + eoaAddress = accounts[0]; + } + if (this.store.eoaAddress !== eoaAddress) { + throw new Error('eoa address changed') } - } async checkPassportLogin() { From 65bc26ed3fd2dda006e5951ee19e1298a219095f Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:15:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0waitForTransaction?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chain/contract/Locker.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/chain/contract/Locker.js b/src/components/chain/contract/Locker.js index 67b4f06..51b351b 100644 --- a/src/components/chain/contract/Locker.js +++ b/src/components/chain/contract/Locker.js @@ -29,14 +29,20 @@ export class Locker { const addressApproval = await nftContract.getApproved(tokenId) if ((addressApproval || "").toLowerCase() != lockAddress.toLowerCase()) { const resApproval = await nftContract.approve(lockAddress, tokenId); - await provider.waitForTransaction(resApproval.hash) + const res = await provider.waitForTransaction(resApproval.hash) + if (res.status == 0) { + throw new Error('approval failed') + } console.debug('approve', resApproval.hash) } } const contract = new ethers.Contract(lockAddress, lockAbi, provider.getSigner()) const res = await contract.lock(nft, address, tokenIds) - await provider.waitForTransaction(res.hash) + const resConfirm = await provider.waitForTransaction(res.hash) + if (resConfirm.status == 0) { + throw new Error('lock failed') + } return res.hash } @@ -66,7 +72,10 @@ export class Locker { }] }) console.log(txHash) - await provider.waitForTransaction(txHash) + const res = await provider.waitForTransaction(txHash) + if (res.status == 0) { + throw new Error('transaction failed') + } return txHash } async execUnlock(provider, chainId, nft, tokenIds) {