UNPKG

@daimo/pay

Version:

Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.

71 lines (68 loc) 2.26 kB
import { jsx, jsxs } from 'react/jsx-runtime'; import { AnimatePresence, motion } from 'framer-motion'; import { useState, useEffect } from 'react'; import { usePayContext } from '../../hooks/usePayContext.js'; import { useWallet } from '../../wallets/useWallets.js'; import ConnectWithInjector from './ConnectWithInjector/index.js'; import ConnectWithQRCode from './ConnectWithQRCode.js'; import Alert from '../Common/Alert/index.js'; import { contentVariants } from '../Common/Modal/index.js'; const states = { QRCODE: "qrcode", INJECTOR: "injector" }; const ConnectUsing = () => { const context = usePayContext(); const { pendingConnectorId, paymentState } = context; const walletFromConnectors = useWallet(pendingConnectorId ?? ""); const wallet = walletFromConnectors || paymentState.selectedWallet; const connector = wallet?.connector; const [status, setStatus] = useState( connector == null ? states.QRCODE : states.INJECTOR ); useEffect(() => { const checkProvider = async () => { if (!wallet || connector == null) return; const provider = await connector.getProvider?.(); if (!provider) { setStatus(states.QRCODE); setTimeout(context.triggerResize, 10); } }; if (status === states.INJECTOR) checkProvider(); }, []); if (!wallet) return /* @__PURE__ */ jsx(Alert, { children: "Connector not found" }); return /* @__PURE__ */ jsxs(AnimatePresence, { children: [ status === states.QRCODE && /* @__PURE__ */ jsx( motion.div, { initial: "initial", animate: "animate", exit: "exit", variants: contentVariants, children: /* @__PURE__ */ jsx(ConnectWithQRCode, {}) }, states.QRCODE ), status === states.INJECTOR && /* @__PURE__ */ jsx( motion.div, { initial: "initial", animate: "animate", exit: "exit", variants: contentVariants, children: /* @__PURE__ */ jsx( ConnectWithInjector, { switchConnectMethod: () => { setStatus(states.QRCODE); } } ) }, states.INJECTOR ) ] }); }; export { ConnectUsing as default }; //# sourceMappingURL=ConnectUsing.js.map