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