Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react-v2.2.6-alpha.2] : Enhancement - WalletState[] return to connect and disconnect hooks #1217

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ import { useConnectWallet } from '@web3-onboard/react'

type UseConnectWallet = (): [
{ wallet: WalletState | null; connecting: boolean },
(options: ConnectOptions) => Promise<void>,
(wallet: DisconnectOptions) => Promise<void>,
(options: ConnectOptions) => Promise<WalletState[]>,
(wallet: DisconnectOptions) => Promise<WalletState[]>,
(addresses?: string[]) => Promise<void>,
(wallets: WalletInit[]) => void,
(wallet: WalletState, address?: string) => void
Expand Down Expand Up @@ -150,8 +150,8 @@ const [
wallet, // the wallet that has been connected or null if not yet connected
connecting // boolean indicating if connection is in progress
},
connect, // function to call to initiate user to connect wallet
disconnect, // function to call with wallet<DisconnectOptions> to disconnect wallet
connect, // function to call to initiate user to connect wallet, returns a list of WalletState objects (connected wallets)
disconnect, // function to call with wallet<DisconnectOptions> to disconnect wallet, returns a list of WalletState objects (connected wallets)
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
setWalletModules, // function to be called with an array of wallet modules to conditionally allow connection of wallet types i.e. setWalletModules([ledger, trezor, injected])
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
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/react",
"version": "2.2.6-alpha.1",
"version": "2.2.6-alpha.2",
"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.",
"keywords": [
"Ethereum",
Expand Down
12 changes: 8 additions & 4 deletions packages/react/src/hooks/useConnectWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { useAppState } from './useAppState'

export const useConnectWallet = (): [
{ wallet: WalletState | null; connecting: boolean },
(options?: ConnectOptions) => Promise<void>,
(wallet: DisconnectOptions) => Promise<void>,
(options?: ConnectOptions) => Promise<WalletState[]>,
(wallet: DisconnectOptions) => Promise<WalletState[]>,
(addresses?: string[]) => Promise<void>,
(wallets: WalletInit[]) => void,
(wallet: WalletState, address?: string) => void
Expand All @@ -29,17 +29,21 @@ export const useConnectWallet = (): [
const connect = useCallback(async (options?: ConnectOptions) => {
setConnecting(true)

await connectWallet(options)
const walletState = await connectWallet(options)

setConnecting(false)

return walletState
}, [])

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

await disconnectWallet({ label })
const walletState = await disconnectWallet({ label })

setConnecting(false)

return walletState
}, [])

const updateBalances = web3Onboard.state.actions.updateBalances
Expand Down