import { useEffect, useState } from "react"; import { SocialItemProps, WalletItemProps } from "../type"; import { cn } from "../utils"; import { isIOS as detectIsIOS, isPcBrowser } from "../utils/device"; import Divider from "./Divider"; import Form from "./Form"; import SocialLogin from "./SocialLogin"; import WalletSelector from "./WalletSelector"; interface IProps { socialOptions?: SocialItemProps[]; walletOptions?: WalletItemProps[]; onClickInputArrow?: (email: string) => void; onClickMainButton: (email: string) => void; onClickSocialItem?: (socialItem: SocialItemProps, index: number) => void; onClickWalletItem?: (wallet: WalletItemProps, index: number) => void; defaultSelect?: string; show?: boolean; showEmail?: boolean; connected?: boolean; loadingIconKey?: string; btnStyle?: { textColor?: string; bgColor?: string; }; socialsFirst?: boolean; } const ConnectMain = ({ socialOptions = [], walletOptions = [], onClickInputArrow, onClickMainButton, onClickSocialItem, onClickWalletItem, show = true, showEmail = true, connected = false, loadingIconKey, btnStyle, socialsFirst = true, }: IProps) => { const [isFocus, setIsFocus] = useState(false); const [showConnectors, setShowConnectors] = useState(true); const [isIOS, setIsIOS] = useState(false); const showSocialLogin = !!socialOptions?.length; useEffect(() => { // if is not focused or is pc, then show connectors setShowConnectors(!isFocus || isPcBrowser()); }, [isFocus]); useEffect(() => { // detect if is IOS setIsIOS(detectIsIOS()); }, []); const handleSocialLogin = (socialItem: SocialItemProps, index: number) => { onClickSocialItem?.(socialItem, index); }; const handleWalletSelect = (wallet: WalletItemProps, index: number) => { onClickWalletItem?.(wallet, index); }; return (
{!socialsFirst && !!walletOptions?.length && ( )}
{showEmail && (
)} {showSocialLogin && ( )}
{showSocialLogin && (
)}
{socialsFirst && !!walletOptions?.length && ( <> )} ); }; export default ConnectMain;