diff --git a/ElementX/Sources/Screens/Authentication/ServerConfirmationScreen/ServerConfirmationScreenViewModel.swift b/ElementX/Sources/Screens/Authentication/ServerConfirmationScreen/ServerConfirmationScreenViewModel.swift index 5faba284a..cc1380228 100644 --- a/ElementX/Sources/Screens/Authentication/ServerConfirmationScreen/ServerConfirmationScreenViewModel.swift +++ b/ElementX/Sources/Screens/Authentication/ServerConfirmationScreen/ServerConfirmationScreenViewModel.swift @@ -58,8 +58,12 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType, Task { state.window = window } case .confirm: switch state.mode { - case .confirmation: Task { await confirmServer() } - case .picker: Task { await pickServer() } + case .confirmation: + startLoading() + Task { await confirmServer() } + case .picker: + startLoading() + Task { await pickServer() } } case .changeServer: actionsSubject.send(.changeServer) @@ -69,6 +73,9 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType, // MARK: - Private private func confirmServer() async { + defer { stopLoading() } + startLoading() + let homeserver = authenticationService.homeserver.value // If the login mode is unknown, the service hasn't been configured and we need to do it now. @@ -78,11 +85,6 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType, return } - // Note: We don't show the spinner until now as it isn't needed if the service is already - // configured and we're about to use password based login - startLoading() - defer { stopLoading() } - switch await authenticationService.configure(for: homeserver.address, flow: authenticationFlow) { case .success: await fetchLoginURLIfNeededAndContinue() @@ -107,6 +109,9 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType, } private func pickServer() async { + defer { stopLoading() } + startLoading() + guard let accountProvider = state.bindings.pickerSelection else { fatalError("It shouldn't be possible to confirm without a selection.") } @@ -118,11 +123,6 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType, return } - // Note: We don't show the spinner until now as it isn't needed if the service is already - // configured and we're about to use password based login - startLoading() - defer { stopLoading() } - switch await authenticationService.configure(for: accountProvider, flow: authenticationFlow) { case .success: await fetchLoginURLIfNeededAndContinue()