diff --git a/TwoFAS/TwoFAS/Root/Modules/Tokens/Flow/TokensPlainFlowController.swift b/TwoFAS/TwoFAS/Root/Modules/Tokens/Flow/TokensPlainFlowController.swift index 58db5e51..0738f36c 100644 --- a/TwoFAS/TwoFAS/Root/Modules/Tokens/Flow/TokensPlainFlowController.swift +++ b/TwoFAS/TwoFAS/Root/Modules/Tokens/Flow/TokensPlainFlowController.swift @@ -64,18 +64,6 @@ final class TokensPlainFlowController: FlowController, TokensNavigationFlowContr private weak var mainSplitViewController: MainSplitViewController? private var galleryViewController: UIViewController? - private var isMainSplitViewControllerReadyToPresentAlert: Bool { - guard let mainSplitViewController else { return false } - - if let presentedViewController = mainSplitViewController.presentedViewController, - presentedViewController is AddingServiceViewController { - presentedViewController.dismiss(animated: false) - return false - } - - return true - } - static func showAsTab( viewController: TokensViewController, in navigationController: UINavigationController @@ -109,6 +97,19 @@ final class TokensPlainFlowController: FlowController, TokensNavigationFlowContr ) { navigationController.setRootViewController(viewController) } + + private func presentAlertOnMainSplitViewController(_ alert: UIAlertController) { + guard let mainSplitViewController else { return } + + if let presentedViewController = mainSplitViewController.presentedViewController, + presentedViewController is AddingServiceViewController { + presentedViewController.dismiss(animated: false) { + mainSplitViewController.present(alert, animated: true) + } + } else { + mainSplitViewController.present(alert, animated: true) + } + } } extension TokensPlainFlowController: TokensPlainFlowControlling { @@ -239,51 +240,45 @@ extension TokensPlainFlowController: TokensPlainFlowControlling { // MARK: - Link actions func toDuplicatedCode(forceAdd: @escaping Callback, cancel: @escaping Callback) { - if isMainSplitViewControllerReadyToPresentAlert { - let alert = UIAlertController( - title: T.Commons.warning, - message: T.Tokens.serviceAlreadyExists, - preferredStyle: .alert - ) - alert.addAction(UIAlertAction(title: T.Commons.yes, style: .destructive, handler: { [weak self] _ in - self?.parent?.tokensSwitchToTokensTab() - forceAdd() - })) - alert.addAction(UIAlertAction(title: T.Commons.no, style: .cancel, handler: { _ in - cancel() - })) + let alert = UIAlertController( + title: T.Commons.warning, + message: T.Tokens.serviceAlreadyExists, + preferredStyle: .alert + ) + alert.addAction(UIAlertAction(title: T.Commons.yes, style: .destructive, handler: { [weak self] _ in + self?.parent?.tokensSwitchToTokensTab() + forceAdd() + })) + alert.addAction(UIAlertAction(title: T.Commons.no, style: .cancel, handler: { _ in + cancel() + })) - mainSplitViewController!.present(alert, animated: true) - } + presentAlertOnMainSplitViewController(alert) } func toShowShouldAddCode(with descriptionText: String?) { - if isMainSplitViewControllerReadyToPresentAlert { - let msg = T.Notifications.addCodeQuestionTitle(descriptionText ?? T.Browser.unkownName) - let alert = UIAlertController(title: T.Notifications.addingCode, message: msg, preferredStyle: .alert) - - alert.addAction(UIAlertAction(title: T.Commons.cancel, style: .cancel) { [weak self] _ in - self?.viewController.presenter.handleClearStoredCode() - }) - alert.addAction(UIAlertAction(title: T.Commons.add, style: .default) { [weak self] _ in - self?.viewController.presenter.handleAddStoredCode() - }) + let msg = T.Notifications.addCodeQuestionTitle(descriptionText ?? T.Browser.unkownName) + let alert = UIAlertController(title: T.Notifications.addingCode, message: msg, preferredStyle: .alert) + + alert.addAction(UIAlertAction(title: T.Commons.cancel, style: .cancel) { [weak self] _ in + self?.viewController.presenter.handleClearStoredCode() + }) + alert.addAction(UIAlertAction(title: T.Commons.add, style: .default) { [weak self] _ in + self?.viewController.presenter.handleAddStoredCode() + }) - mainSplitViewController!.present(alert, animated: true) - } + presentAlertOnMainSplitViewController(alert) } func toIncorrectCode() { - if isMainSplitViewControllerReadyToPresentAlert { - let alert = UIAlertController( - title: T.Commons.warning, - message: T.Tokens.thisQrCodeIsInavlid, - preferredStyle: .alert - ) - alert.addAction(UIAlertAction(title: T.Commons.cancel, style: .cancel, handler: { _ in })) + let alert = UIAlertController( + title: T.Commons.warning, + message: T.Tokens.thisQrCodeIsInavlid, + preferredStyle: .alert + ) + alert.addAction(UIAlertAction(title: T.Commons.cancel, style: .cancel, handler: { _ in })) - mainSplitViewController!.present(alert, animated: true) - } + presentAlertOnMainSplitViewController(alert) } func toSendLogs(auditID: UUID) {