diff --git a/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt b/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt index c13372cbe4..5a1e8b107f 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt @@ -531,26 +531,34 @@ class LoginViewModel @AssistedInject constructor( } currentJob = viewModelScope.launch { - try { - val state = awaitState() - safeLoginWizard.resetPasswordMailConfirmed(state.resetPasswordNewPassword!!) - } catch (failure: Throwable) { + val state = awaitState() + + if (state.resetPasswordNewPassword == null) setState { copy( - asyncResetMailConfirmed = Fail(failure) + asyncResetPassword = Uninitialized, + asyncResetMailConfirmed = Fail(Throwable("Developer error - New password not set")) + ) + } else { + try { + safeLoginWizard.resetPasswordMailConfirmed(state.resetPasswordNewPassword) + } catch (failure: Throwable) { + setState { + copy( + asyncResetMailConfirmed = Fail(failure) + ) + } + return@launch + } + setState { + copy( + asyncResetMailConfirmed = Success(Unit), + resetPasswordEmail = null, + resetPasswordNewPassword = null ) } - return@launch + _viewEvents.post(LoginViewEvents.OnResetPasswordMailConfirmationSuccess) } - setState { - copy( - asyncResetMailConfirmed = Success(Unit), - resetPasswordEmail = null, - resetPasswordNewPassword = null - ) - } - - _viewEvents.post(LoginViewEvents.OnResetPasswordMailConfirmationSuccess) } } }