diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 73937d9..2af43ab 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -19,10 +19,7 @@ import { identity } from "./lib/hooks"
function Layout(props: { children?: any }) {
const location = useLocation()
- const usesAppShell = () => {
- const path = location.pathname
- return path.startsWith("/relays") || path.startsWith("/account") || path.startsWith("/admin")
- }
+ const usesAppShell = () => location.pathname.match(/^\/(relays|account|admin)/)
createEffect(() => {
// Reinitialize Preline components on route change
@@ -32,7 +29,7 @@ function Layout(props: { children?: any }) {
return (
-
{props.children}}>
+ {props.children}}>
{props.children}
@@ -45,11 +42,11 @@ export default function App() {
const navigate = useNavigate()
createEffect(() => {
- if (!condition()) navigate("/", { replace: true })
+ if (!identity.loading && !condition()) navigate("/", { replace: true })
})
return (
-
+
)
diff --git a/frontend/src/lib/hooks.ts b/frontend/src/lib/hooks.ts
index 173fd43..68f7a01 100644
--- a/frontend/src/lib/hooks.ts
+++ b/frontend/src/lib/hooks.ts
@@ -66,9 +66,26 @@ registerCommonAccountTypes(accountManager)
export const [account, setAccount] = createSignal()
-export const [identity, setIdentity] = createSignal()
+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()
if (account) {
localStorage.setItem("caravel.accounts.active", account.id)
- getIdentity().then(setIdentity)
} else {
localStorage.removeItem("caravel.accounts.active")
- setIdentity(undefined)
}
+
+ refetchIdentity()
})
})()