Improve error handling and safety when retrieving account seed words

- Update `Account.seedWords()` to use `runCatching` and return an empty string instead of a nullable value on failure.
- Simplify seed word handling in `AccountBackupDialog` and `AccountExportService` by removing null checks.
This commit is contained in:
greenart7c3
2026-01-21 09:00:33 -03:00
parent 0568f5546c
commit 48254b024b
3 changed files with 3 additions and 3 deletions
@@ -120,7 +120,7 @@ class Account(
return signer.signerSync.decrypt(encryptedContent, fromPublicKey)
}
suspend fun seedWords() = DataStoreAccess.getEncryptedKey(Amber.instance, npub, DataStoreAccess.SEED_WORDS)
suspend fun seedWords() = runCatching { DataStoreAccess.getEncryptedKey(Amber.instance, npub, DataStoreAccess.SEED_WORDS) }.getOrNull() ?: ""
suspend fun decryptZapEvent(
data: String,
@@ -121,7 +121,7 @@ object AccountExportService {
*/
private suspend fun accountToExportData(account: Account, password: String): AccountExportData {
val seedWords = account.seedWords()
val encrypedSeedWords = if (seedWords != null && seedWords.isNotBlank()) account.nip44Encrypt(seedWords, account.hexKey) else ""
val encrypedSeedWords = if (seedWords.isNotBlank()) account.nip44Encrypt(seedWords, account.hexKey) else ""
val encryptedNsec = account.nip49Encrypt(password)
return AccountExportData(
@@ -227,7 +227,7 @@ fun AccountBackupScreen(
launch(Dispatchers.IO) {
localAccount = LocalPreferences.loadFromEncryptedStorage(Amber.instance, it.npub)
localAccount?.let { acc ->
seedWords = acc.seedWords() ?: ""
seedWords = acc.seedWords()
}
}
}