Show a more appropriate error when user enter a wrong backup passphrase

This commit is contained in:
Benoit Marty 2020-06-26 15:07:34 +02:00 committed by Valere
parent 8c5ec2c57f
commit 6131c10d31
2 changed files with 39 additions and 28 deletions

View File

@ -44,11 +44,11 @@ class BackupToQuadSMigrationTask @Inject constructor(
sealed class Result {
object Success : Result()
abstract class Failure(val error: String?) : Result()
abstract class Failure(val throwable: Throwable?) : Result()
object InvalidRecoverySecret : Failure(null)
object NoKeyBackupVersion : Failure(null)
object IllegalParams : Failure(null)
class ErrorFailure(throwable: Throwable) : Failure(throwable.localizedMessage)
class ErrorFailure(throwable: Throwable) : Failure(throwable)
}
data class Params(

View File

@ -35,6 +35,7 @@ import im.vector.matrix.android.internal.crypto.keysbackup.util.extractCurveKeyF
import im.vector.matrix.android.internal.crypto.model.rest.UserPasswordAuth
import im.vector.matrix.android.internal.util.awaitCallback
import im.vector.riotx.R
import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.exhaustive
import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.core.platform.WaitingViewData
@ -48,6 +49,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
@Assisted initialState: BootstrapViewState,
@Assisted val args: BootstrapBottomSheet.Args,
private val stringProvider: StringProvider,
private val errorFormatter: ErrorFormatter,
private val session: Session,
private val bootstrapTask: BootstrapCrossSigningTask,
private val migrationTask: BackupToQuadSMigrationTask,
@ -301,7 +303,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
}
}
private fun startMigrationFlow(prevState: BootstrapStep, passphrase: String?, recoveryKey: String?) {
private fun startMigrationFlow(previousStep: BootstrapStep, passphrase: String?, recoveryKey: String?) {//TODO Rename param
setState {
copy(step = BootstrapStep.Initializing)
}
@ -316,7 +318,8 @@ class BootstrapSharedViewModel @AssistedInject constructor(
}
}
migrationTask.invoke(this, BackupToQuadSMigrationTask.Params(passphrase, recoveryKey, progressListener)) {
if (it is BackupToQuadSMigrationTask.Result.Success) {
when (it) {
is BackupToQuadSMigrationTask.Result.Success -> {
setState {
copy(
passphrase = passphrase,
@ -334,20 +337,18 @@ class BootstrapSharedViewModel @AssistedInject constructor(
} else {
startInitializeFlow(userPassword)
}
} else {
}
is BackupToQuadSMigrationTask.Result.Failure -> {
_viewEvents.post(
BootstrapViewEvents.ModalError(
(it as? BackupToQuadSMigrationTask.Result.Failure)?.error
?: stringProvider.getString(R.string.matrix_error
)
)
BootstrapViewEvents.ModalError(it.toHumanReadable())
)
setState {
copy(
step = prevState
step = previousStep
)
}
}
}.exhaustive
}
}
}
@ -519,6 +520,16 @@ class BootstrapSharedViewModel @AssistedInject constructor(
}.exhaustive
}
private fun BackupToQuadSMigrationTask.Result.Failure.toHumanReadable(): String {
return when (this) {
is BackupToQuadSMigrationTask.Result.InvalidRecoverySecret -> stringProvider.getString(R.string.keys_backup_passphrase_error_decrypt)
is BackupToQuadSMigrationTask.Result.ErrorFailure -> errorFormatter.toHumanReadable(throwable)
// is BackupToQuadSMigrationTask.Result.NoKeyBackupVersion,
// is BackupToQuadSMigrationTask.Result.IllegalParams,
else -> stringProvider.getString(R.string.unexpected_error)
}
}
// ======================================
// Companion, view model assisted creation
// ======================================