@web3auth/modal
Version:
Multi chain wallet aggregator for web3Auth
33 lines (30 loc) • 880 B
JavaScript
import { WalletServicesPluginError } from '@web3auth/no-modal';
import { useState, useCallback } from 'react';
import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
const useReceive = () => {
const {
plugin,
ready
} = useWalletServicesPlugin();
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const showReceive = useCallback(async showReceiveParams => {
setLoading(true);
setError(null);
try {
if (!plugin) throw WalletServicesPluginError.notInitialized();
if (!ready) throw WalletServicesPluginError.walletPluginNotConnected();
await plugin.showReceive(showReceiveParams);
} catch (error) {
setError(error);
} finally {
setLoading(false);
}
}, [plugin, ready]);
return {
loading,
error,
showReceive
};
};
export { useReceive };