UNPKG

@web3auth/no-modal

Version:
31 lines (28 loc) 716 B
import { ref } from 'vue'; import { useWeb3AuthInner } from './useWeb3AuthInner.js'; import { WalletInitializationError } from '../../base/errors/index.js'; const useSwitchChain = () => { const { web3Auth } = useWeb3AuthInner(); const loading = ref(false); const error = ref(null); const switchChain = async chainParams => { try { if (!web3Auth.value) throw WalletInitializationError.notReady(); error.value = null; loading.value = true; await web3Auth.value.switchChain(chainParams); } catch (err) { error.value = err; } finally { loading.value = false; } }; return { loading, error, switchChain }; }; export { useSwitchChain };