Refactor account retrieval logic in LocalPreferences

- Add a check to verify if an account exists using `containsAccount` before attempting to retrieve it.
- Move `DataStoreAccess.getEncryptedKey` outside the `sharedPrefs` apply block for better structure.
- Ensure the method returns null early if the account is not found.
This commit is contained in:
greenart7c3
2026-01-26 11:09:23 -03:00
parent 61020b672c
commit 1759856236
@@ -442,12 +442,15 @@ object LocalPreferences {
if (accountCache.get(npub) != null) {
return accountCache.get(npub)
}
if (!containsAccount(context, npub)) {
return null
}
val privKey = DataStoreAccess.getEncryptedKey(
context,
npub,
DataStoreAccess.NOSTR_PRIVKEY,
)
sharedPrefs(context, npub).apply {
val privKey = DataStoreAccess.getEncryptedKey(
context,
npub,
DataStoreAccess.NOSTR_PRIVKEY,
)
val pubKey = getString(PrefKeys.NOSTR_PUBKEY.key, null) ?: return null
val name = getString(PrefKeys.ACCOUNT_NAME.key, "") ?: ""
val picture = getString(PrefKeys.PROFILE_URL.key, "") ?: ""