优化切换链流程

This commit is contained in:
CounterFire2023 2024-07-22 13:44:00 +08:00
parent c33b30580c
commit 0672798d64

View File

@ -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() {