Fix account state bugs

This commit is contained in:
Jon Staab
2026-03-27 11:42:18 -07:00
parent 72b7a8db45
commit e750185176
2 changed files with 24 additions and 10 deletions
+20 -3
View File
@@ -66,9 +66,26 @@ registerCommonAccountTypes(accountManager)
export const [account, setAccount] = createSignal<IAccount | undefined>()
export const [identity, setIdentity] = createSignal<Identity | undefined>()
export const [identity, { refetch: refetchIdentity, mutate: setIdentity }] = createResource(
() => account()?.pubkey,
pubkey => {
if (pubkey) return getIdentity()
}
)
;(() => {
try {
accountManager.fromJSON(JSON.parse(localStorage.getItem("caravel.accounts")))
} catch {
// pass
}
const active = localStorage.getItem("caravel.accounts.active")
if (active) {
accountManager.setActive(active)
}
accountManager.active$.subscribe(account => {
setAccount(account)
@@ -76,11 +93,11 @@ export const [identity, setIdentity] = createSignal<Identity | undefined>()
if (account) {
localStorage.setItem("caravel.accounts.active", account.id)
getIdentity().then(setIdentity)
} else {
localStorage.removeItem("caravel.accounts.active")
setIdentity(undefined)
}
refetchIdentity()
})
})()