Skip to content

Commit

Permalink
chore: add more wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchere committed Feb 11, 2024
1 parent 6e1be19 commit 3f8cd41
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
20 changes: 19 additions & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type State = {
isConnecting: boolean;
isRefetchingBalance: boolean;

detectedWallets: WalletName[];

address: null | string;

/**
Expand All @@ -35,6 +37,7 @@ export type State = {
const defaults = {
isConnecting: false,
isConnected: false,
detectedWallets: [],
address: null,
lovelaceBalance: null,
api: null,
Expand All @@ -46,7 +49,6 @@ const defaults = {

export const useStore = create<State>()((set, get) => ({
...defaults,

disconnect: () => {
set(defaults);
},
Expand All @@ -73,6 +75,22 @@ export const useStore = create<State>()((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) => {
Expand Down
4 changes: 4 additions & 0 deletions src/typescript/cip30.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export enum WalletName {
ETERNL = 'eternl',
FLINT = 'flint',
BEGIN = 'begin',
GERO = 'gero',
TYPHON = 'typhoncip30',
LACE = 'lace',
VESPR = 'vespr',
}

export interface WalletApi {
Expand Down

0 comments on commit 3f8cd41

Please sign in to comment.