fix: abort dangling fetches and handle localStorage exceptions

- useNostr.ts: wrap auto-restore login fetch with AbortController,
  abort on logout to cancel in-flight request
- useWallet.ts: wrap localStorage.setItem/removeItem calls in try/catch
  for Safari private browsing quota exceptions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-08 20:43:34 +00:00
co-authored by Claude Opus 4.6
parent d98b264935
commit edd08fde59
2 changed files with 9 additions and 4 deletions
+6 -4
View File
@@ -16,8 +16,10 @@ function loadStored<T>(key: string): T | null {
} catch { return null }
}
function store(key: string, value: unknown) {
if (value == null) localStorage.removeItem(key)
else localStorage.setItem(key, JSON.stringify(value))
try {
if (value == null) localStorage.removeItem(key)
else localStorage.setItem(key, JSON.stringify(value))
} catch { /* Safari private browsing quota exception */ }
}
const isWalletConnected = ref(!!loadStored<string>('bf_wallet_method'))
@@ -73,7 +75,7 @@ export function useWallet() {
}
// Store NWC string locally for client-side payment sending
localStorage.setItem('bf_nwc_url', connectionString)
try { localStorage.setItem('bf_nwc_url', connectionString) } catch { /* quota */ }
walletMethod.value = 'nwc'
isWalletConnected.value = true
store('bf_wallet_method', 'nwc')
@@ -120,7 +122,7 @@ export function useWallet() {
paymentStatus.value = 'idle'
pendingPayment.value = null
store('bf_wallet_method', null)
localStorage.removeItem('bf_nwc_url')
try { localStorage.removeItem('bf_nwc_url') } catch { /* quota */ }
}
async function checkWalletStatus(): Promise<void> {