UNPKG

@daimo/pay

Version:

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

43 lines (40 loc) 2.16 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 } = context; const wallet = useWallet(pendingConnectorId ?? ""); // If cannot be scanned, display injector flow, which if extension is not installed will show CTA to install it const isQrCode = !wallet?.isInstalled; const [status, setStatus] = useState(isQrCode ? states.QRCODE : states.INJECTOR); useEffect(() => { // if no provider, change to qrcode const checkProvider = async () => { const res = await wallet?.connector?.getProvider(); if (!res) { setStatus(states.QRCODE); setTimeout(context.triggerResize, 10); // delay required here for modal to resize } }; if (status === states.INJECTOR) checkProvider(); }, []); // eslint-disable-line react-hooks/exhaustive-deps if (!wallet) return jsx(Alert, { children: "Connector not found" }); return (jsxs(AnimatePresence, { children: [status === states.QRCODE && (jsx(motion.div, { initial: "initial", animate: "animate", exit: "exit", variants: contentVariants, children: jsx(ConnectWithQRCode, {}) }, states.QRCODE)), status === states.INJECTOR && (jsx(motion.div, { initial: "initial", animate: "animate", exit: "exit", variants: contentVariants, children: jsx(ConnectWithInjector, { switchConnectMethod: () => { setStatus(states.QRCODE); } }) }, states.INJECTOR))] })); }; export { ConnectUsing as default }; //# sourceMappingURL=ConnectUsing.js.map