From 3f8cd41cc7effd8acd31691bf18ae05c24942b30 Mon Sep 17 00:00:00 2001 From: MartinSchere Date: Sun, 11 Feb 2024 14:31:17 +0100 Subject: [PATCH] chore: add more wallets --- src/index.ts | 4 ++-- src/store/index.ts | 20 +++++++++++++++++++- src/typescript/cip30.ts | 4 ++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index ed6a150..057a229 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,9 +46,9 @@ const useCardanoWallet = ({ if (autoConnect && typeof localStorage !== 'undefined') { const connectedWalletName = localStorage.getItem( localStorageKey - ) as WalletName; + ) as WalletName | null; - if (!Object.values(WalletName).includes(connectedWalletName)) { + if (!connectedWalletName) { return; } diff --git a/src/store/index.ts b/src/store/index.ts index ccb7143..ae0f201 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -11,6 +11,8 @@ export type State = { isConnecting: boolean; isRefetchingBalance: boolean; + detectedWallets: WalletName[]; + address: null | string; /** @@ -35,6 +37,7 @@ export type State = { const defaults = { isConnecting: false, isConnected: false, + detectedWallets: [], address: null, lovelaceBalance: null, api: null, @@ -46,7 +49,6 @@ const defaults = { export const useStore = create()((set, get) => ({ ...defaults, - disconnect: () => { set(defaults); }, @@ -73,6 +75,22 @@ export const useStore = create()((set, get) => ({ ); }, + getDetectedWallets: async () => { + if (typeof window === 'undefined' || !(window as any).cardano) { + return; + } + + const ns = (window as any).cardano; + + set( + produce((draft: State) => { + draft.detectedWallets = Object.keys(ns).filter(ns => + Object.keys(WalletName).includes(ns) + ) as WalletName[]; + }) + ); + }, + connect: async (walletName: WalletName, localStorageKey: string) => { set( produce((draft: State) => { diff --git a/src/typescript/cip30.ts b/src/typescript/cip30.ts index 7373243..6518124 100644 --- a/src/typescript/cip30.ts +++ b/src/typescript/cip30.ts @@ -173,6 +173,10 @@ export enum WalletName { ETERNL = 'eternl', FLINT = 'flint', BEGIN = 'begin', + GERO = 'gero', + TYPHON = 'typhoncip30', + LACE = 'lace', + VESPR = 'vespr', } export interface WalletApi {