import React, { useMemo, useState } from 'react' import { styled } from '@linaria/react' import { useWalletModal } from '@rainbow-me/kit-modal' import type { UseWalletModalOptions } from '@rainbow-me/kit-modal' import { useENS } from '@rainbow-me/kit-hooks' import { JsonRpcProvider } from '@ethersproject/providers' import type { UseENSOptions } from '@rainbow-me/kit-hooks' import { Pill } from './Pill' import { Badge } from './Badge' import { WalletDropdown, WalletDropdownProps } from './WalletDropdown' import { css } from '@linaria/core' const Container = styled.div` position: relative; width: max-content; ` export interface ProfileProps { modalOptions: UseWalletModalOptions copyAddress?: boolean | ((props: { address: string }) => JSX.Element) ENSProvider?: JsonRpcProvider ipfsGatewayUrl?: string classNames?: Partial<{ pill: string menu: string container: string }> button?: ({ connect, disconnect, isConnected, isConnecting }: { connect: () => void disconnect: () => void isConnected: boolean isConnecting: boolean }) => JSX.Element dropdown?: (props: WalletDropdownProps) => JSX.Element ensOptions?: Partial } const ConnectButton = ({ connect }: { connect: () => void }) => connect()}>Connect const DropdownIcon = () => ( ) export const Profile = ({ modalOptions, copyAddress: CopyAddressComponent, ENSProvider, ipfsGatewayUrl = 'ipfs.infura-ipfs.io', classNames, button: ButtonComponent = ConnectButton, dropdown: DropdownComponent = WalletDropdown, ensOptions }: ProfileProps) => { const { state: { isConnected, isConnecting, disconnect, connect }, Modal, provider, address: accountAddress, chainId } = useWalletModal(modalOptions) const { records, domain } = useENS({ provider: ENSProvider, chainId, domain: accountAddress, fetchOptions: { cache: 'force-cache' }, ...ensOptions }) const address = useMemo(() => domain || accountAddress, [domain, accountAddress]) const [isExpanded, setExpandedState] = useState(false) return ( {isConnected ? ( <> setExpandedState(!isExpanded)} className={classNames?.pill || ''} > {isExpanded && ( )} ) : ( <> {isConnecting && } )} ) }