Skip to content

Commit

Permalink
feat: add ability to throw connection errors (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero authored Mar 20, 2024
1 parent c906d9b commit 53689eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export default function useWallet() {
accounts: getAccountsByProvider(id),
isActive: activeAccount?.providerId === id,
isConnected: connectedAccounts.some((accounts) => accounts.providerId === id),
connect: (arg) => connect(id, arg),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
connect: (arg?: any, throws?: boolean) => connect(id, arg, throws),
disconnect: () => disconnect(id),
reconnect: () => reconnect(id),
setActiveProvider: () => setActive(id),
Expand Down Expand Up @@ -114,7 +115,7 @@ export default function useWallet() {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const connect = async (id: PROVIDER_ID, arg?: any) => {
const connect = async (id: PROVIDER_ID, arg?: any, throws = false) => {
try {
const walletClient = getClient(id)
const walletInfo = await walletClient?.connect(() => clearAccounts(id), arg)
Expand All @@ -123,6 +124,9 @@ export default function useWallet() {
addAccounts(walletInfo.accounts)
} catch (e) {
console.error(e)
if (throws) {
throw e
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type Provider = {
isActive: boolean
isConnected: boolean
// eslint-disable-next-line @typescript-eslint/no-explicit-any
connect: (arg?: any) => Promise<void>
connect: (arg?: any, throws?: boolean) => Promise<void>
disconnect: () => Promise<void>
reconnect: () => Promise<void>
setActiveProvider: () => void
Expand Down

0 comments on commit 53689eb

Please sign in to comment.