From 7eab23e6f86ee9ecdc0d55218b76f742095c092a Mon Sep 17 00:00:00 2001 From: cebgcontract <99630598+cebgcontract@users.noreply.github.com> Date: Thu, 28 Apr 2022 20:48:47 +0800 Subject: [PATCH] =?UTF-8?q?metamask=E7=99=BB=E5=BD=95=E6=97=B6,=20?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E9=92=B1=E5=8C=85=E6=9C=AA=E7=99=BB=E5=BD=95?= =?UTF-8?q?,=20=E5=88=99=E6=8F=90=E7=A4=BA=E5=85=88=E5=8E=BB=E9=92=B1?= =?UTF-8?q?=E5=8C=85=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chain/blockchain.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/chain/blockchain.ts b/src/chain/blockchain.ts index de42e76..b5ca101 100644 --- a/src/chain/blockchain.ts +++ b/src/chain/blockchain.ts @@ -215,8 +215,17 @@ export class Blockchain { provider = window.ethereum try { await provider.request({ method: 'eth_requestAccounts' }) - } catch (error) { - throw new Error('User Rejected') + } catch (error: any) { + 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) { provider = window.web3.currentProvider