From d1272778298a9a14259124d29aa31986e0bbda58 Mon Sep 17 00:00:00 2001 From: Ayanami Date: Fri, 17 Jun 2022 18:52:48 +0900 Subject: [PATCH] Add Kaikas browser wallet support (#54) --- connectors/kaikas.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 connectors/kaikas.ts diff --git a/connectors/kaikas.ts b/connectors/kaikas.ts new file mode 100644 index 0000000..67f7c38 --- /dev/null +++ b/connectors/kaikas.ts @@ -0,0 +1,27 @@ +import LockConnector from '../src/connector'; + +export default class Connector extends LockConnector { + async connect() { + let provider; + if (window['klaytn']) { + provider = window['klaytn']; + try { + await window['klaytn'].enable(); + } catch (e) { + console.error(e); + // Return when the error is Error: User denied account authorization + if (e.code === -32603) return; + } + } else if (window['caver']) { + provider = window['caver'].currentProvider; + } + return provider; + } + + async isLoggedIn() { + if (!window['klaytn']) return false; + if (window['klaytn'].selectedAddress) return true; + await new Promise((r) => setTimeout(r, 400)); + return !!window['klaytn'].selectedAddress; + } +}