Fix multi-account restore and switch after restart

- restoreSession pre-loads all nsec accounts from keychain into signer
  cache at startup, not just the active one
- switchAccount updates state to target account on failure instead of
  leaving UI stuck on previous account
- AccountSwitcher shows re-login prompt when account has no signer
- store_nsec now logs warnings instead of silently swallowing errors
This commit is contained in:
Jure
2026-03-12 16:14:23 +01:00
parent f33d78ebcf
commit 56cf0bae4d
2 changed files with 61 additions and 17 deletions

View File

@@ -26,7 +26,7 @@ function Avatar({ account, size = "w-6 h-6", textSize = "text-[10px]" }: { accou
}
export function AccountSwitcher() {
const { accounts, pubkey, switchAccount, removeAccount, logout } = useUserStore();
const { accounts, pubkey, loggedIn, switchAccount, removeAccount, logout } = useUserStore();
const { openProfile } = useUIStore();
const [open, setOpen] = useState(false);
const [showAddLogin, setShowAddLogin] = useState(false);
@@ -137,13 +137,21 @@ export function AccountSwitcher() {
{/* Active account row */}
<div className="px-3 py-2">
{!loggedIn && (
<button
onClick={() => setShowAddLogin(true)}
className="w-full mb-1.5 px-2 py-1 text-[10px] border border-accent/40 text-accent hover:bg-accent/10 transition-colors"
>
re-login to sign
</button>
)}
<div className="flex items-center gap-2">
<div
className="flex items-center gap-2 flex-1 min-w-0 cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => openProfile(pubkey)}
>
<Avatar account={current} size="w-8 h-8" textSize="text-[12px]" />
<span className="text-text text-[12px] font-medium truncate flex-1">{displayName(current)}</span>
<span className={`text-[12px] font-medium truncate flex-1 ${loggedIn ? "text-text" : "text-text-muted"}`}>{displayName(current)}</span>
</div>
<button
onClick={() => setOpen((v) => !v)}