Skip to content

Commit

Permalink
Check if saved seed phrase is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Radiokot committed Jul 29, 2024
1 parent eb4dc83 commit 41752fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class AuthenticationRepository(
}

fun getSeedPhase() = runCatching {
sharedPreferences.seedPhrase
checkNotNull(sharedPreferences.seedPhrase.takeIf(String::isNotBlank)) {
"The phrase must not be blank"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ class ExportPassPhraseViewModel(

init {
viewModelScope.launch {
authenticationRepository.getSeedPhase().onSuccess { result ->
_state.update {
when {
result.isNullOrBlank() -> ExportSeedPhraseState.Error(IllegalStateException("No seed phrase found"))
else -> ExportSeedPhraseState.Success(result.split(String.SPACE))
authenticationRepository.getSeedPhase()
.onSuccess { phrase ->
_state.update {
ExportSeedPhraseState.Success(phrase.split(String.SPACE))
}
}
.onFailure {
_state.update {
ExportSeedPhraseState.Error(
IllegalStateException("No seed phrase found")
)
}
}
}
}
}
}
Expand Down

0 comments on commit 41752fb

Please sign in to comment.