From ca86a21dbc5b69e2242ff760f1b72df7ae999d9b Mon Sep 17 00:00:00 2001 From: gmachnio Date: Wed, 30 Oct 2024 20:25:05 +0100 Subject: [PATCH] [TF-1658] dismiss addingVC --- .../Flow/TokensPlainFlowController.swift | 91 +++++++++---------- 1 file changed, 43 insertions(+), 48 deletions(-) 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) {