fix: auto-clear old bunker accounts that were created with wrong setup

- Old bunker accounts were created before proper method binding
- Add version check to clear nostr-connect accounts once
- Preserves extension accounts
- Users will need to reconnect bunker (one-time migration)
This commit is contained in:
Gigi
2025-10-16 22:45:56 +02:00
parent 7bd11e695e
commit 39c8b3dfe4

View File

@@ -203,13 +203,27 @@ function App() {
try {
const accountsJson = localStorage.getItem('accounts')
if (accountsJson) {
await accounts.fromJSON(JSON.parse(accountsJson))
}
// Restore active account
const activeId = localStorage.getItem('active')
if (activeId && accounts.getAccount(activeId)) {
accounts.setActive(activeId)
const parsed = JSON.parse(accountsJson)
// Clear old bunker accounts (they were created with wrong setup)
const bunkerFixVersion = localStorage.getItem('bunkerFixVersion')
if (bunkerFixVersion !== '1') {
console.log('[bunker] Clearing old bunker accounts (need to reconnect with fixed setup)')
const nonBunkerAccounts = parsed.filter((acc: any) => acc.type !== 'nostr-connect')
if (nonBunkerAccounts.length > 0) {
await accounts.fromJSON(nonBunkerAccounts)
}
localStorage.setItem('bunkerFixVersion', '1')
localStorage.removeItem('active')
} else {
await accounts.fromJSON(parsed)
// Restore active account
const activeId = localStorage.getItem('active')
if (activeId && accounts.getAccount(activeId)) {
accounts.setActive(activeId)
}
}
}
} catch (err) {
console.error('[bunker] Failed to restore accounts:', err)