feat: Refactor account selection logic in UnlockScreen to prioritize last logged public key and improve logging

This commit is contained in:
k1ngsterr1
2026-01-09 04:02:15 +05:00
parent b6786cea05
commit ecebaaf066

View File

@@ -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