UNPKG

@web3auth/modal

Version:

Multi chain wallet aggregator for web3Auth

33 lines (30 loc) 887 B
import { WalletServicesPluginError } from '@web3auth/no-modal'; import { useState, useCallback } from 'react'; import { useWalletServicesPlugin } from './useWalletServicesPlugin.js'; const useWalletUI = () => { const { plugin, ready } = useWalletServicesPlugin(); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const showWalletUI = useCallback(async showWalletUiParams => { setLoading(true); setError(null); try { if (!plugin) throw WalletServicesPluginError.notInitialized(); if (!ready) throw WalletServicesPluginError.walletPluginNotConnected(); await plugin.showWalletUi(showWalletUiParams); } catch (error) { setError(error); } finally { setLoading(false); } }, [plugin, ready]); return { loading, error, showWalletUI }; }; export { useWalletUI };