UNPKG

@web3auth/no-modal

Version:
34 lines (31 loc) 857 B
import { useState, useCallback } from 'react'; import { useWeb3AuthInner } from './useWeb3AuthInner.js'; import { WalletInitializationError } from '../../base/errors/index.js'; const useWallets = () => { const { web3Auth } = useWeb3AuthInner(); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [wallets, setWallets] = useState([]); const syncWallets = useCallback(async () => { if (!web3Auth) throw WalletInitializationError.notReady(); setLoading(true); setError(null); try { const result = await web3Auth.getConnectedAccountsWithProviders(); setWallets(result); } catch (err) { setError(err); } finally { setLoading(false); } }, [web3Auth]); return { loading, error, wallets, syncWallets }; }; export { useWallets };