import { Button } from '@/components/ui/button' import { Pubkey } from '@/domain' import { isSameAccount } from '@/lib/account' import { cn } from '@/lib/utils' import { useNostr } from '@/providers/NostrProvider' import { TAccountPointer } from '@/types' import { Loader, Trash2 } from 'lucide-react' import { useState } from 'react' import SignerTypeBadge from '../SignerTypeBadge' import { SimpleUserAvatar } from '../UserAvatar' import { SimpleUsername } from '../Username' export default function AccountList({ className, afterSwitch }: { className?: string afterSwitch: () => void }) { const { accounts, account, switchAccount, removeAccount } = useNostr() const [switchingAccount, setSwitchingAccount] = useState(null) return (
{accounts.map((act) => (
{ if (isSameAccount(act, account)) return setSwitchingAccount(act) switchAccount(act) .then(() => afterSwitch()) .finally(() => setSwitchingAccount(null)) }} >
{Pubkey.tryFromString(act.pubkey)?.formatNpub(12) ?? act.pubkey.slice(0, 8)}
{switchingAccount && isSameAccount(act, switchingAccount) && (
)}
))}
) }