Skip to content

Commit

Permalink
fix: connect
Browse files Browse the repository at this point in the history
change used by unused addresses method for better privacy and avoid empty accounts bug
  • Loading branch information
lucasportella committed Mar 4, 2024
1 parent 31f6327 commit 071cc5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/cardano/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { NoAvailableAccountsError } from '@/errors/no-accounts-available-error';
import { NoProviderAvailableError } from '@/errors/no-provider-available-error';
import { web3Window } from '@/types';
import { availableWallets } from './available-wallets';
import type { CardanoUsedAddress } from './types';
import type { CardanoUnusedAddresses } from './types';

export async function connect(wallet?: string): Promise<CardanoUsedAddress[]> {
export async function connect(wallet?: string): Promise<CardanoUnusedAddresses[]> {
if (!web3Window.cardano)
throw new NotInjectedError()

Expand All @@ -23,13 +23,13 @@ export async function connect(wallet?: string): Promise<CardanoUsedAddress[]> {

try {
const api = await web3Window.cardano[injectedWallet].enable()
const usedAddresses: CardanoUsedAddress[] = await api.getUsedAddresses()
if (usedAddresses.length === 0)
const unusedAddresses: CardanoUnusedAddresses[] = await api.getUnusedAddresses()
if (unusedAddresses.length === 0)
throw new NoAvailableAccountsError()
return usedAddresses
return unusedAddresses
}
catch (error) {
console.log(error)
console.error(error)
return []
}
}
6 changes: 4 additions & 2 deletions src/cardano/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { AvailableWallet } from './available-wallets';
import type { CardanoWallet } from './available-wallets';

export type CardanoProviderProps = Record<AvailableWallet, any>;
export type CardanoProviderProps = Record<'wallet', CardanoWallet>;

export type CardanoUsedAddress = string

export type CardanoUnusedAddresses = string

export interface ApiPromise {
getBalance: (address: string) => Promise<string>
getUsedAddresses: () => Promise<string[]>
Expand Down

0 comments on commit 071cc5c

Please sign in to comment.