Skip to content

Commit

Permalink
Hiding clients that failed to initialise from the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
robdmoore committed Aug 25, 2023
1 parent 7ba14c6 commit 01d091b
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,35 @@ export default function useWallet() {
}

const supportedClients = Object.keys(clients) as PROVIDER_ID[]

setProviders(
supportedClients.map((id) => {
return {
...allClients[id],
accounts: getAccountsByProvider(id),
isActive: activeAccount?.providerId === id,
isConnected: connectedAccounts.some((accounts) => accounts.providerId === id),
connect: () => connect(id),
disconnect: () => disconnect(id),
reconnect: () => reconnect(id),
setActiveProvider: () => setActive(id),
setActiveAccount: (account: string) => selectActiveAccount(id, account)
}
})
supportedClients
// Femove any clients that didn't initialise
.filter((id) => !!clients?.[id])
.map((id) => {
return {
...allClients[id],
// Override static details with any instance details
...clients[id],
accounts: getAccountsByProvider(id),
isActive: activeAccount?.providerId === id,
isConnected: connectedAccounts.some((accounts) => accounts.providerId === id),
connect: () => connect(id),
disconnect: () => disconnect(id),
reconnect: () => reconnect(id),
setActiveProvider: () => setActive(id),
setActiveAccount: (account: string) => selectActiveAccount(id, account)
}
})
)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [clients, connectedAccounts, connectedActiveAccounts, activeAccount])

const getClient = (id?: PROVIDER_ID): WalletClient => {
if (!id) throw new Error('Provier ID is missing.')
if (!id) throw new Error('Provider ID is missing.')

const walletClient = clients?.[id]

if (!walletClient) throw new Error('Client not found for ID')
if (!walletClient) throw new Error(`Client not found for ID: ${id}`)

return walletClient
}
Expand Down

0 comments on commit 01d091b

Please sign in to comment.