UNPKG

@web3auth/modal

Version:

Multi chain wallet aggregator for web3Auth

35 lines (31 loc) 902 B
'use strict'; var noModal = require('@web3auth/no-modal'); var react = require('react'); var useWalletServicesPlugin = require('./useWalletServicesPlugin.js'); const useSwap = () => { const { plugin, ready } = useWalletServicesPlugin.useWalletServicesPlugin(); const [loading, setLoading] = react.useState(false); const [error, setError] = react.useState(null); const showSwap = react.useCallback(async showSwapParams => { setLoading(true); setError(null); try { if (!plugin) throw noModal.WalletServicesPluginError.notInitialized(); if (!ready) throw noModal.WalletServicesPluginError.walletPluginNotConnected(); await plugin.showSwap(showSwapParams); } catch (error) { setError(error); } finally { setLoading(false); } }, [plugin, ready]); return { loading, error, showSwap }; }; exports.useSwap = useSwap;