import { ArrowLeftOutlined, ArrowRightOutlined, CopyOutlined, DisconnectOutlined, } from "@ant-design/icons"; import { AboutPetraWeb, type AboutPetraWebEducationScreen, type AdapterNotDetectedWallet, type AdapterWallet, AptosPrivacyPolicy, groupAndSortWallets, isInstallRequired, truncateAddress, useWallet, WalletItem, type WalletSortingOptions, } from "@aptos-labs/wallet-adapter-react"; import { Button, Collapse, Divider, Dropdown, Flex, type MenuProps, Modal, type ModalProps, message, Typography, } from "antd"; import { type Dispatch, type SetStateAction, useEffect, useState } from "react"; import "./styles.css"; const { Text } = Typography; interface WalletSelectorProps extends WalletSortingOptions { isModalOpen?: boolean; setModalOpen?: Dispatch>; } export function WalletSelector({ isModalOpen, setModalOpen, ...walletSortingOptions }: WalletSelectorProps) { const [walletSelectorModalOpen, setWalletSelectorModalOpen] = useState(false); useEffect(() => { // If the component is being used as a controlled component, // sync the external and internal modal state. if (isModalOpen !== undefined) { setWalletSelectorModalOpen(isModalOpen); } }, [isModalOpen]); const { account, connected, disconnect, wallets = [], notDetectedWallets = [], } = useWallet(); const { petraWebWallets, availableWallets, installableWallets } = groupAndSortWallets( [...wallets, ...notDetectedWallets], walletSortingOptions, ); const hasPetraWebWallets = !!petraWebWallets.length; const onWalletButtonClick = () => { if (connected) { disconnect(); } else { setWalletSelectorModalOpen(true); } }; const handleCopyAddress = () => { if (account?.address) { navigator.clipboard.writeText(account.address.toString()); message.success("Address copied to clipboard"); } }; const handleDisconnect = () => { disconnect(); }; const dropdownItems: MenuProps["items"] = [ { key: "copy", label: "Copy Address", icon: , onClick: handleCopyAddress, }, { key: "disconnect", label: "Disconnect", icon: , onClick: handleDisconnect, }, ]; const closeModal = () => { setWalletSelectorModalOpen(false); if (setModalOpen) { setModalOpen(false); } }; const buttonText = account?.ansName || truncateAddress(account?.address?.toString()) || "Unknown"; const modalProps: ModalProps = { centered: true, open: walletSelectorModalOpen, onCancel: closeModal, footer: null, zIndex: 9999, className: "wallet-selector-modal", }; const renderEducationScreens = (screen: AboutPetraWebEducationScreen) => (
{screen.screenIndicators.map((ScreenIndicator, i) => (
))}
); return ( <> {connected ? ( ) : ( )} {hasPetraWebWallets ? ( <> Log in or sign up with Social + Petra Web ) : ( "Connect Wallet" )} } > {!connected && ( <> {hasPetraWebWallets && ( {petraWebWallets.map((wallet) => ( ))}

Learn more about{" "} Petra Web

{" "} .

Or
)} {availableWallets.map((wallet) => ( ))} {!!installableWallets.length && ( {installableWallets.map((wallet) => ( ))} ), }, ]} /> )} )}
); } interface WalletRowProps { wallet: AdapterWallet | AdapterNotDetectedWallet; onConnect?: () => void; } function WalletRow({ wallet, onConnect }: WalletRowProps) { return (
{wallet.name}
{isInstallRequired(wallet) ? ( ) : ( )}
); } function PetraWebWalletRow({ wallet, onConnect }: WalletRowProps) { return ( ); }