Handle back navigation SetupPassphrase -> Firstform

This commit is contained in:
Benoit Marty 2020-06-26 13:07:09 +02:00 committed by Valere
parent a66010a1d8
commit 3aaa425714

View File

@ -54,6 +54,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
private val reAuthHelper: ReAuthHelper private val reAuthHelper: ReAuthHelper
) : VectorViewModel<BootstrapViewState, BootstrapActions, BootstrapViewEvents>(initialState) { ) : VectorViewModel<BootstrapViewState, BootstrapActions, BootstrapViewEvents>(initialState) {
private var doesKeyBackupExist: Boolean = false
private var isBackupCreatedFromPassphrase: Boolean = false private var isBackupCreatedFromPassphrase: Boolean = false
private val zxcvbn = Zxcvbn() private val zxcvbn = Zxcvbn()
@ -77,8 +78,9 @@ class BootstrapSharedViewModel @AssistedInject constructor(
} }
if (version == null) { if (version == null) {
// we just resume plain bootstrap // we just resume plain bootstrap
doesKeyBackupExist = false
setState { setState {
copy(step = BootstrapStep.FirstForm(keyBackUpExist = false)) copy(step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist))
} }
} else { } else {
// we need to get existing backup passphrase/key and convert to SSSS // we need to get existing backup passphrase/key and convert to SSSS
@ -89,9 +91,10 @@ class BootstrapSharedViewModel @AssistedInject constructor(
// strange case... just finish? // strange case... just finish?
_viewEvents.post(BootstrapViewEvents.Dismiss) _viewEvents.post(BootstrapViewEvents.Dismiss)
} else { } else {
doesKeyBackupExist = true
isBackupCreatedFromPassphrase = keyVersion.getAuthDataAsMegolmBackupAuthData()?.privateKeySalt != null isBackupCreatedFromPassphrase = keyVersion.getAuthDataAsMegolmBackupAuthData()?.privateKeySalt != null
setState { setState {
copy(step = BootstrapStep.FirstForm(keyBackUpExist = true)) copy(step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist))
} }
} }
} }
@ -463,14 +466,20 @@ class BootstrapSharedViewModel @AssistedInject constructor(
_viewEvents.post(BootstrapViewEvents.SkipBootstrap()) _viewEvents.post(BootstrapViewEvents.SkipBootstrap())
} }
is BootstrapStep.SetupPassphrase -> { is BootstrapStep.SetupPassphrase -> {
// do we let you cancel from here? setState {
_viewEvents.post(BootstrapViewEvents.SkipBootstrap()) copy(
step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist),
// Also reset the passphrase
passphrase = null,
passphraseRepeat = null
)
}
} }
is BootstrapStep.ConfirmPassphrase -> { is BootstrapStep.ConfirmPassphrase -> {
setState { setState {
copy( copy(
step = BootstrapStep.SetupPassphrase( step = BootstrapStep.SetupPassphrase(
isPasswordVisible = (state.step as? BootstrapStep.ConfirmPassphrase)?.isPasswordVisible ?: false isPasswordVisible = state.step.isPasswordVisible
) )
) )
} }