Skip to content

Commit a5ad576

Browse files
authored
Added WalletState[] return to connect and dicsonnect hooks within the React Package (#1217)
1 parent 1abe6b6 commit a5ad576

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

packages/react/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ import { useConnectWallet } from '@web3-onboard/react'
119119

120120
type UseConnectWallet = (): [
121121
{ wallet: WalletState | null; connecting: boolean },
122-
(options: ConnectOptions) => Promise<void>,
123-
(wallet: DisconnectOptions) => Promise<void>,
122+
(options: ConnectOptions) => Promise<WalletState[]>,
123+
(wallet: DisconnectOptions) => Promise<WalletState[]>,
124124
(addresses?: string[]) => Promise<void>,
125125
(wallets: WalletInit[]) => void,
126126
(wallet: WalletState, address?: string) => void
@@ -150,8 +150,8 @@ const [
150150
wallet, // the wallet that has been connected or null if not yet connected
151151
connecting // boolean indicating if connection is in progress
152152
},
153-
connect, // function to call to initiate user to connect wallet
154-
disconnect, // function to call with wallet<DisconnectOptions> to disconnect wallet
153+
connect, // function to call to initiate user to connect wallet, returns a list of WalletState objects (connected wallets)
154+
disconnect, // function to call with wallet<DisconnectOptions> to disconnect wallet, returns a list of WalletState objects (connected wallets)
155155
updateBalances, // function to be called with an optional array of wallet addresses connected through Onboard to update balance or empty/no params to update all connected wallets
156156
setWalletModules, // function to be called with an array of wallet modules to conditionally allow connection of wallet types i.e. setWalletModules([ledger, trezor, injected])
157157
setPrimaryWallet // function that can set the primary wallet and/or primary account within that wallet. The wallet that is set needs to be passed in for the first parameter and if you would like to set the primary account, the address of that account also needs to be passed in

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/react",
3-
"version": "2.2.6-alpha.1",
3+
"version": "2.2.6-alpha.2",
44
"description": "A collection of React hooks for integrating Web3-Onboard in to React and Next.js projects. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",

packages/react/src/hooks/useConnectWallet.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { useAppState } from './useAppState'
1111

1212
export const useConnectWallet = (): [
1313
{ wallet: WalletState | null; connecting: boolean },
14-
(options?: ConnectOptions) => Promise<void>,
15-
(wallet: DisconnectOptions) => Promise<void>,
14+
(options?: ConnectOptions) => Promise<WalletState[]>,
15+
(wallet: DisconnectOptions) => Promise<WalletState[]>,
1616
(addresses?: string[]) => Promise<void>,
1717
(wallets: WalletInit[]) => void,
1818
(wallet: WalletState, address?: string) => void
@@ -29,17 +29,21 @@ export const useConnectWallet = (): [
2929
const connect = useCallback(async (options?: ConnectOptions) => {
3030
setConnecting(true)
3131

32-
await connectWallet(options)
32+
const walletState = await connectWallet(options)
3333

3434
setConnecting(false)
35+
36+
return walletState
3537
}, [])
3638

3739
const disconnect = useCallback(async ({ label }: DisconnectOptions) => {
3840
setConnecting(true)
3941

40-
await disconnectWallet({ label })
42+
const walletState = await disconnectWallet({ label })
4143

4244
setConnecting(false)
45+
46+
return walletState
4347
}, [])
4448

4549
const updateBalances = web3Onboard.state.actions.updateBalances

0 commit comments

Comments
 (0)