Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/wallet/wdk/src/sequence/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,7 @@ export class Wallets implements WalletsInterface {
this.shared.databases.manager.del(wallet),
this.shared.modules.devices.remove(walletEntry.device),
])
await this._cleanupWalletData(wallet)
return undefined as any
}

Expand Down Expand Up @@ -1251,6 +1252,31 @@ export class Wallets implements WalletsInterface {
await this.completeConfigurationUpdate(requestId)
await this.shared.databases.manager.del(request.wallet)
await this.shared.modules.devices.remove(walletEntry.device)
await this._cleanupWalletData(request.wallet)
}

private async _cleanupWalletData(wallet: Address.Address): Promise<void> {
const [sigs, txns, msgs, recovery] = await Promise.all([
this.shared.databases.signatures.list(),
this.shared.databases.transactions.list(),
this.shared.databases.messages.list(),
this.shared.databases.recovery.list(),
])
Comment on lines +1259 to +1264
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make wallet DB cleanup best-effort during logout

_cleanupWalletData runs list()/del() calls in fail-fast Promise.all blocks without handling errors, so any IndexedDB failure (e.g., transient open/transaction errors) will reject logout/completeLogout after the manager entry and device have already been removed. In that state the caller sees logout as failed, but retries can no longer proceed because the wallet record is gone, leaving a partial and hard-to-recover flow. This cleanup should be non-blocking (or individually guarded) like the auth-key cleanup path.

Useful? React with 👍 / 👎.


await Promise.all([
...sigs.filter((s) => Address.isEqual(s.wallet, wallet)).map((s) => this.shared.databases.signatures.del(s.id)),
...txns.filter((t) => Address.isEqual(t.wallet, wallet)).map((t) => this.shared.databases.transactions.del(t.id)),
...msgs.filter((m) => Address.isEqual(m.wallet, wallet)).map((m) => this.shared.databases.messages.del(m.id)),
...recovery.filter((r) => Address.isEqual(r.wallet, wallet)).map((r) => this.shared.databases.recovery.del(r.id)),
])

try {
const { loginTopology } = await this.getConfigurationParts(wallet)
const loginSigners = Config.getSigners(loginTopology)
await Promise.all(loginSigners.signers.map((s) => this.shared.databases.authKeys.delBySigner(s.toString())))
} catch {
// Don't fail logout if config lookup fails (e.g. offline)
}
}

async getConfiguration(wallet: Address.Address) {
Expand Down
Loading