Handle back navigation Recovery backup -> Firstform
Also create BootstrapStep.GetBackupSecretForMigration.useKey() to reduce code duplication
This commit is contained in:
parent
3aaa425714
commit
8e7166662b
@ -169,10 +169,7 @@ class BootstrapBottomSheet : VectorBaseBottomSheetDialogFragment() {
|
||||
showFragment(BootstrapConclusionFragment::class, Bundle())
|
||||
}
|
||||
is BootstrapStep.GetBackupSecretForMigration -> {
|
||||
val isKey = when (state.step) {
|
||||
is BootstrapStep.GetBackupSecretPassForMigration -> state.step.useKey
|
||||
else -> true
|
||||
}
|
||||
val isKey = state.step.useKey()
|
||||
val drawableRes = if (isKey) R.drawable.ic_security_key_24dp else R.drawable.ic_security_phrase_24dp
|
||||
bootstrapIcon.isVisible = true
|
||||
bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(
|
||||
|
@ -86,17 +86,12 @@ class BootstrapMigrateBackupFragment @Inject constructor(
|
||||
}
|
||||
|
||||
private fun submit() = withState(sharedViewModel) { state ->
|
||||
if (state.step !is BootstrapStep.GetBackupSecretForMigration) {
|
||||
return@withState
|
||||
}
|
||||
val isEnteringKey =
|
||||
when (state.step) {
|
||||
is BootstrapStep.GetBackupSecretPassForMigration -> state.step.useKey
|
||||
else -> true
|
||||
}
|
||||
val getBackupSecretForMigration = state.step as? BootstrapStep.GetBackupSecretForMigration ?: return@withState
|
||||
|
||||
val isEnteringKey = getBackupSecretForMigration.useKey()
|
||||
|
||||
val secret = bootstrapMigrateEditText.text?.toString()
|
||||
if (secret.isNullOrBlank()) {
|
||||
if (secret.isNullOrEmpty()) {
|
||||
val errRes = if (isEnteringKey) R.string.recovery_key_empty_error_message else R.string.passphrase_empty_error_message
|
||||
bootstrapRecoveryKeyEnterTil.error = getString(errRes)
|
||||
} else if (isEnteringKey && !isValidRecoveryKey(secret)) {
|
||||
@ -112,15 +107,9 @@ class BootstrapMigrateBackupFragment @Inject constructor(
|
||||
}
|
||||
|
||||
override fun invalidate() = withState(sharedViewModel) { state ->
|
||||
if (state.step !is BootstrapStep.GetBackupSecretForMigration) {
|
||||
return@withState
|
||||
}
|
||||
val getBackupSecretForMigration = state.step as? BootstrapStep.GetBackupSecretForMigration ?: return@withState
|
||||
|
||||
val isEnteringKey =
|
||||
when (state.step) {
|
||||
is BootstrapStep.GetBackupSecretPassForMigration -> state.step.useKey
|
||||
else -> true
|
||||
}
|
||||
val isEnteringKey = getBackupSecretForMigration.useKey()
|
||||
|
||||
if (isEnteringKey) {
|
||||
bootstrapMigrateShowPassword.isVisible = false
|
||||
|
@ -458,13 +458,18 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||
)
|
||||
}
|
||||
} else {
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap())
|
||||
setState {
|
||||
copy(
|
||||
step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist),
|
||||
// Also reset the passphrase
|
||||
passphrase = null,
|
||||
passphraseRepeat = null,
|
||||
// Also reset the key
|
||||
migrationRecoveryKey = null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is BootstrapStep.GetBackupSecretKeyForMigration -> {
|
||||
// do we let you cancel from here?
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap())
|
||||
}
|
||||
is BootstrapStep.SetupPassphrase -> {
|
||||
setState {
|
||||
copy(
|
||||
@ -500,7 +505,16 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap())
|
||||
}
|
||||
is BootstrapStep.GetBackupSecretForMigration -> {
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap())
|
||||
setState {
|
||||
copy(
|
||||
step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist),
|
||||
// Also reset the passphrase
|
||||
passphrase = null,
|
||||
passphraseRepeat = null,
|
||||
// Also reset the key
|
||||
migrationRecoveryKey = null
|
||||
)
|
||||
}
|
||||
}
|
||||
}.exhaustive
|
||||
}
|
||||
|
@ -104,3 +104,10 @@ sealed class BootstrapStep {
|
||||
data class SaveRecoveryKey(val isSaved: Boolean) : BootstrapStep()
|
||||
object DoneSuccess : BootstrapStep()
|
||||
}
|
||||
|
||||
fun BootstrapStep.GetBackupSecretForMigration.useKey(): Boolean {
|
||||
return when (this) {
|
||||
is BootstrapStep.GetBackupSecretPassForMigration -> useKey
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user