Skip to content

Commit 44d9cfd

Browse files
authored
Feature - Add disconnect method to react package (#846)
* Add disconnect function to react package * Add disconnect function to react package
1 parent 1578945 commit 44d9cfd

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/react/src/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export const init = (options: InitOptions): OnboardAPI => {
2020

2121
export const useConnectWallet = (): [
2222
{ wallet: WalletState | null; connecting: boolean },
23-
(options: ConnectOptions) => Promise<void>
23+
(options: ConnectOptions) => Promise<void>,
24+
(wallet: WalletState) => Promise<void>
2425
] => {
2526
if (!web3Onboard) throw new Error('Must initialize before using hooks.')
2627

@@ -41,7 +42,20 @@ export const useConnectWallet = (): [
4142
}
4243
}, [])
4344

44-
return [{ wallet, connecting }, connect]
45+
const disconnect = useCallback(async wallet => {
46+
setConnecting(true)
47+
48+
await (
49+
web3Onboard as OnboardAPI
50+
).disconnectWallet({ label: wallet.label })
51+
52+
setConnectedWallet(null)
53+
54+
setConnecting(false)
55+
56+
}, [])
57+
58+
return [{ wallet, connecting }, connect, disconnect]
4559
}
4660

4761
type SetChainOptions = {

0 commit comments

Comments
 (0)