metamask登录时, 如果钱包未登录, 则提示先去钱包登录

This commit is contained in:
cebgcontract 2022-04-28 20:48:47 +08:00
parent 3cce25c465
commit 7eab23e6f8

View File

@ -215,8 +215,17 @@ export class Blockchain {
provider = window.ethereum provider = window.ethereum
try { try {
await provider.request({ method: 'eth_requestAccounts' }) await provider.request({ method: 'eth_requestAccounts' })
} catch (error) { } catch (error: any) {
throw new Error('User Rejected') if (error.code === -32002) {
// const hexChainId = toHexChainId(this.currentChain)
// await provider.request({
// method: 'wallet_switchEthereumChain',
// params: [{ chainId: hexChainId }]
// })
throw new Error('MeatMask not login, Open MeatMask and login first')
} else {
throw new Error('User Rejected')
}
} }
} else if (window.web3) { } else if (window.web3) {
provider = window.web3.currentProvider provider = window.web3.currentProvider