'use client' import * as React from 'react' import { SvgCheckCircle } from '@chainlink/blocks-icons' import { useIsMobile } from '../../hooks' import { cn } from '../../utils' import { Button, buttonVariants } from '../Button' import { LoadingSpinner } from '../Input/icons' import { MobileMenuSheetContent } from '../PageHeader/MobileMenuSheetContent' import { Popover, PopoverContent, PopoverTrigger } from '../Popover' import { Sheet, SheetTrigger } from '../Sheet' import { Tag } from '../Tag' import { Typography } from '../Typography' const padding = 'px-4 py-6 md:px-6 md:py-6' const ConnectWalletModeContext = React.createContext<'popover' | 'sheet'>( 'popover', ) const ConnectWalletModal = ( props: React.ComponentPropsWithoutRef & { defaultOpen?: boolean }, ) => { const isMobile = useIsMobile() const mode = isMobile ? 'sheet' : 'popover' const Root = isMobile ? Sheet : Popover const { defaultOpen = false, children, ...rest } = props return ( {children} ) } type ConnectWalletModalTriggerProps = React.ComponentPropsWithoutRef< typeof PopoverTrigger > & Pick< React.ComponentPropsWithoutRef, 'variant' | 'size' | 'width' | 'loading' > const ConnectWalletModalTrigger = ({ className, children, variant = 'primary', size = 'default', width = 'responsive', loading = false, ...props }: ConnectWalletModalTriggerProps) => { const mode = React.useContext(ConnectWalletModeContext) return mode === 'sheet' ? ( {children} ) : ( {children} ) } ConnectWalletModalTrigger.displayName = 'ConnectWalletModalTrigger' type ConnectWalletModalContentProps = React.ComponentPropsWithoutRef< typeof PopoverContent > & { ref?: React.Ref> } const ConnectWalletModalContent = ({ className, children, side = 'bottom', align = 'end', sideOffset = 8, ...props }: ConnectWalletModalContentProps) => { const mode = React.useContext(ConnectWalletModeContext) if (mode === 'sheet') { return ( {children} ) } return ( {children} ) } ConnectWalletModalContent.displayName = 'ConnectWalletModalContent' type SelectionProps = React.HTMLAttributes & { isSelected?: boolean isLoading?: boolean ref?: React.Ref } const ConnectWalletModalSelection = ({ className, children, isSelected, isLoading, ref, ...props }: SelectionProps) => { const childrenArray = React.Children.toArray(children) const childIndicatesSelected = childrenArray.some( (child) => React.isValidElement(child) && child.props?.isSelected, ) const childIndicatesLoading = childrenArray.some( (child) => React.isValidElement(child) && child.props?.isLoading, ) const finalIsSelected = isSelected ?? childIndicatesSelected const finalIsLoading = isLoading ?? childIndicatesLoading return (
{children}
) } ConnectWalletModalSelection.displayName = 'ConnectWalletModalSelection' type ConnectWalletModalHeaderProps = React.HTMLAttributes & { ref?: React.Ref } const ConnectWalletModalHeader = ({ className, children, ref, ...props }: ConnectWalletModalHeaderProps) => { const mode = React.useContext(ConnectWalletModeContext) return (
{children}
) } ConnectWalletModalHeader.displayName = 'ConnectWalletModalHeader' type ConnectWalletModalDisclaimerProps = React.HTMLAttributes & { ref?: React.Ref } const ConnectWalletModalDisclaimer = ({ className, children, ref, ...props }: ConnectWalletModalDisclaimerProps) => { return (
{children}
) } ConnectWalletModalDisclaimer.displayName = 'ConnectWalletModalDisclaimer' type ConnectWalletModalSelectionItemProps = React.ComponentPropsWithoutRef< typeof Button > & { state?: | 'default' | 'detected' | 'recent' | 'disabled' | 'loading' | 'selected' // Base64 string, usually svg/png walletIcon?: string isSelected?: boolean isLoading?: boolean onSelect?: () => void ref?: React.Ref> } const ConnectWalletModalSelectionItem = ({ state = 'default', walletIcon = '', className, children, onSelect, isSelected, isLoading, ref, ...props }: ConnectWalletModalSelectionItemProps) => { const resolvedState = isLoading ? 'loading' : isSelected ? 'selected' : state return ( ) } ConnectWalletModalSelectionItem.displayName = 'ConnectWalletModalSelectionItem' export { ConnectWalletModal, ConnectWalletModalHeader, ConnectWalletModalTrigger, ConnectWalletModalContent, ConnectWalletModalSelection, ConnectWalletModalDisclaimer, ConnectWalletModalSelectionItem, }