import { Badge } from '@/components/ui/badge' import { isSameAccount } from '@/lib/account' import { formatPubkey } from '@/lib/pubkey' import { cn } from '@/lib/utils' import { useNostr } from '@/providers/NostrProvider' import { TAccountPointer, TSignerType } from '@/types' import { Loader } from 'lucide-react' import { useState } from 'react' import { SimpleUserAvatar } from '../UserAvatar' import { SimpleUsername } from '../Username' export default function AccountList({ afterSwitch }: { afterSwitch: () => void }) { const { accounts, account, switchAccount } = useNostr() const [switchingAccount, setSwitchingAccount] = useState(null) return (
{accounts.map((act) => (
{ if (isSameAccount(act, account)) return setSwitchingAccount(act) switchAccount(act) .then(() => afterSwitch()) .finally(() => setSwitchingAccount(null)) }} >
{formatPubkey(act.pubkey)}
{switchingAccount && isSameAccount(act, switchingAccount) && (
)}
))}
) } function SignerTypeBadge({ signerType }: { signerType: TSignerType }) { if (signerType === 'nip-07') { return NIP-07 } else if (signerType === 'bunker') { return Bunker } else if (signerType === 'ncryptsec') { return NCRYPTSEC } else { return NSEC } }