// NOTE: This file is stable and usually should not be modified. // It is important that all functionality in this file is preserved, and should only be modified if explicitly requested. import { ChevronDown, LogOut, UserIcon, UserPlus, Wallet } from 'lucide-react'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu.tsx'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar.tsx'; import { WalletModal } from '@/components/WalletModal'; import { clearDmDecryptCache } from '@/lib/dmDecryptCache'; import { clearTranslationMemory } from '@/lib/translation'; import { useLoggedInAccounts, type Account } from '@/hooks/useLoggedInAccounts'; import { genUserName } from '@/lib/genUserName'; import { useTranslation } from '@/contexts/language'; interface AccountSwitcherProps { onAddAccountClick: () => void; } export function AccountSwitcher({ onAddAccountClick }: AccountSwitcherProps) { const { currentUser, otherUsers, setLogin, removeLogin } = useLoggedInAccounts(); const { t } = useTranslation(); if (!currentUser) return null; const getDisplayName = (account: Account): string => { return account.metadata?.name ?? genUserName(account.pubkey); } const getNip05 = (account: Account): string | undefined => { return account.metadata?.nip05; } return (
{t('settingsUi.accountSwitcher.switchAccount')}
{otherUsers.map((user) => ( setLogin(user.id)} className='flex items-center gap-2 cursor-pointer p-2 rounded-md' > {getDisplayName(user)?.charAt(0) || }

{getDisplayName(user)}

{getNip05(user) && (

{getNip05(user)}

)}
{user.id === currentUser.id &&
}
))} e.preventDefault()} > {t('settingsUi.accountSwitcher.walletSettings')} {t('settingsUi.accountSwitcher.addAccount')} { // Drop this account's plaintext DM cache (device-local) on logout so // another account on the same device can't read it from IndexedDB. void clearDmDecryptCache(currentUser.id).catch(() => {}); clearTranslationMemory(); removeLogin(currentUser.id); }} className='flex items-center gap-2 cursor-pointer p-2 rounded-md text-red-500' > {t('settingsUi.accountSwitcher.logout')}
); }