'use strict';

var noModal = require('@web3auth/no-modal');
var vue = require('vue');
var useWalletServicesPlugin = require('./useWalletServicesPlugin.js');

const useFunding = () => {
  const {
    plugin,
    ready
  } = useWalletServicesPlugin.useWalletServicesPlugin();
  const loading = vue.ref(false);
  const error = vue.ref(null);
  const showFunding = async showFundingParams => {
    loading.value = true;
    error.value = null;
    try {
      if (!plugin) throw noModal.WalletServicesPluginError.notInitialized();
      if (!ready) throw noModal.WalletServicesPluginError.walletPluginNotConnected();
      await plugin.value.showFunding(showFundingParams);
    } catch (err) {
      error.value = err;
    } finally {
      loading.value = false;
    }
  };
  return {
    loading,
    error,
    showFunding
  };
};

exports.useFunding = useFunding;
