diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-10-04 12:36:41 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-10-05 10:01:55 +0200 |
| commit | c42ea0b0c99dfde5cb7980cc3ce13539d6f87306 (patch) | |
| tree | b19445dfa47140a9844bed23946fd6127ea02235 /ios | |
| parent | 3d59d84b8e2e25749150816a5a0e2b441a19a3a4 (diff) | |
| download | mullvadvpn-c42ea0b0c99dfde5cb7980cc3ce13539d6f87306.tar.xz mullvadvpn-c42ea0b0c99dfde5cb7980cc3ce13539d6f87306.zip | |
Account: adapt to new Account.logout() interface
Diffstat (limited to 'ios')
| -rw-r--r-- | ios/MullvadVPN/AccountViewController.swift | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/ios/MullvadVPN/AccountViewController.swift b/ios/MullvadVPN/AccountViewController.swift index 485a2b8bf3..7b76042bd4 100644 --- a/ios/MullvadVPN/AccountViewController.swift +++ b/ios/MullvadVPN/AccountViewController.swift @@ -286,45 +286,53 @@ class AccountViewController: UIViewController, AppStorePaymentObserver, AccountO let alertController = UIAlertController( title: nil, message: message, - preferredStyle: .alert) + preferredStyle: .alert + ) alertPresenter.enqueue(alertController, presentingController: self) { - Account.shared.logout { (result) in - DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { - alertController.dismiss(animated: true) { - switch result { - case .failure(let error): - self.logger.error(chainedError: error, message: "Failed to log out") - - let errorAlertController = UIAlertController( - title: NSLocalizedString( - "LOGOUT_FAILURE_ALERT_TITLE", - tableName: "Account", - value: "Failed to log out", - comment: "Title for logout failure alert" - ), - message: error.errorChainDescription, - preferredStyle: .alert - ) - errorAlertController.addAction( - UIAlertAction(title: NSLocalizedString( - "LOGOUT_FAILURE_ALERT_OK_ACTION", - tableName: "Account", - value: "OK", - comment: "Message for logout failure alert" - ), style: .cancel) - ) - self.alertPresenter.enqueue(errorAlertController, presentingController: self) - - case .success: - self.delegate?.accountViewControllerDidLogout(self) + Account.shared.logout() + .receive(on: .main, after: .seconds(1), timerType: .deadline) + .then { result in + return Promise { resolver in + alertController.dismiss(animated: true) { + resolver.resolve(value: result) } } } - } + .onSuccess { _ in + self.delegate?.accountViewControllerDidLogout(self) + } + .onFailure { error in + self.logger.error(chainedError: error, message: "Failed to log out") + + self.showLogoutFailure(error) + } + .observe { _ in } } } + private func showLogoutFailure(_ error: Account.Error) { + let errorAlertController = UIAlertController( + title: NSLocalizedString( + "LOGOUT_FAILURE_ALERT_TITLE", + tableName: "Account", + value: "Failed to log out", + comment: "Title for logout failure alert" + ), + message: error.errorChainDescription, + preferredStyle: .alert + ) + errorAlertController.addAction( + UIAlertAction(title: NSLocalizedString( + "LOGOUT_FAILURE_ALERT_OK_ACTION", + tableName: "Account", + value: "OK", + comment: "Message for logout failure alert" + ), style: .cancel) + ) + alertPresenter.enqueue(errorAlertController, presentingController: self) + } + // MARK: - AccountObserver func account(_ account: Account, didUpdateExpiry expiry: Date) { |
