diff --git a/app/src/main/java/com/rosetta/messenger/ui/auth/UnlockScreen.kt b/app/src/main/java/com/rosetta/messenger/ui/auth/UnlockScreen.kt index 24a0a44..d05c33c 100644 --- a/app/src/main/java/com/rosetta/messenger/ui/auth/UnlockScreen.kt +++ b/app/src/main/java/com/rosetta/messenger/ui/auth/UnlockScreen.kt @@ -93,16 +93,21 @@ fun UnlockScreen( ) } - // Select account - prioritize: selectedAccountId > lastLoggedPublicKey > currentPublicKey > first account + // Select account - prioritize: selectedAccountId > lastLoggedPublicKey > first account val lastLoggedKey = accountManager.getLastLoggedPublicKey() - val currentKey = accountManager.currentPublicKey.first() - val targetPublicKey = selectedAccountId ?: lastLoggedKey ?: currentKey - Log.d("UnlockScreen", "selectedAccountId=$selectedAccountId, lastLoggedKey=$lastLoggedKey, currentKey=$currentKey, targetPublicKey=$targetPublicKey") - Log.d("UnlockScreen", "accounts=${accounts.map { it.publicKey }}") + Log.d("UnlockScreen", "Loading accounts. selectedAccountId=$selectedAccountId, lastLoggedKey=$lastLoggedKey") + Log.d("UnlockScreen", "Available accounts: ${accounts.map { "${it.name}:${it.publicKey.take(8)}" }}") - selectedAccount = accounts.find { it.publicKey == targetPublicKey } ?: accounts.firstOrNull() - Log.d("UnlockScreen", "selectedAccount=${selectedAccount?.publicKey}") + // Find the target account + val targetAccount = when { + selectedAccountId != null -> accounts.find { it.publicKey == selectedAccountId } + lastLoggedKey != null -> accounts.find { it.publicKey == lastLoggedKey } + else -> null + } + + selectedAccount = targetAccount ?: accounts.firstOrNull() + Log.d("UnlockScreen", "Selected account: ${selectedAccount?.name}:${selectedAccount?.publicKey?.take(8)}") } // Filter accounts by search