From b5a3203ac1426beb79ca84368d8c4ca37303bc88 Mon Sep 17 00:00:00 2001 From: Wan <495709+wa0x6e@users.noreply.github.com> Date: Sat, 27 Jul 2024 20:14:02 +0900 Subject: [PATCH] fix: skip authentication on locked metamask (#114) * fix: fix deprecated usage of `selectedAddress` * chore: bump version * fix: do not return provider on locked wallet * fix: handle error when the requestPermission is request is pending * v0.2.5 --------- Co-authored-by: ChaituVR --- connectors/injected.ts | 14 +++++++++++++- package.json | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/connectors/injected.ts b/connectors/injected.ts index d60596d..f6c02c2 100644 --- a/connectors/injected.ts +++ b/connectors/injected.ts @@ -7,8 +7,20 @@ export default class Connector extends LockConnector { provider = window['ethereum']; try { await window['ethereum'].request({ method: 'eth_requestAccounts' }) - } catch (e) { + } catch (e: any) { console.error(e); + if (e.message = "Already processing eth_requestAccounts. Please wait.") { + try { + await provider.request({ + method: "wallet_requestPermissions", + params: [{ eth_accounts: {} }], + }); + } catch (e: any) { + console.error(e); + if (e.code === 4001 || -32002) return; + } + } + if (e.code === 4001) return; } } else if (window['web3']) { diff --git a/package.json b/package.json index b2d6a7f..c46c997 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@snapshot-labs/lock", - "version": "0.2.4", + "version": "0.2.5", "repository": "snapshot-labs/lock", "license": "MIT", "main": "dist/lock.cjs.js",