From 79d746a395e14429e5d38d3a4c4aa28a18d5a44b Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 13 Oct 2020 20:05:25 +0200 Subject: [PATCH] Injecting now AuthenticationService --- ui/BankingiOSApp/BankingiOSApp/SceneDelegate.swift | 10 ++++++---- .../BankingiOSApp/ui/dialogs/AddAccountDialog.swift | 3 ++- .../BankingiOSApp/ui/dialogs/LoginDialog.swift | 4 ++-- .../ui/dialogs/ProtectAppSettingsDialog.swift | 2 +- .../BankingiOSApp/ui/dialogs/SettingsDialog.swift | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/SceneDelegate.swift b/ui/BankingiOSApp/BankingiOSApp/SceneDelegate.swift index 4658befe..ab863982 100644 --- a/ui/BankingiOSApp/BankingiOSApp/SceneDelegate.swift +++ b/ui/BankingiOSApp/BankingiOSApp/SceneDelegate.swift @@ -15,9 +15,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). - setupBankingUi() - - let authenticationService = AuthenticationService() + let authenticationService = setupBankingUi() if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) @@ -36,11 +34,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } } - private func setupBankingUi() { + private func setupBankingUi() -> AuthenticationService { let appDataFolder = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first ?? Bundle.main.resourceURL?.absoluteString ?? "" let persistence = CoreDataBankingPersistence() + let authenticationService = AuthenticationService() self.persistence = persistence let dataFolder = URL(fileURLWithPath: "data", isDirectory: true, relativeTo: URL(fileURLWithPath: appDataFolder)) @@ -48,6 +47,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let presenter = BankingPresenterSwift(dataFolder: dataFolder, router: SwiftUiRouter(), webClient: UrlSessionWebClient(), persistence: persistence, transactionPartySearcher: persistence, bankIconFinder: SwiftBankIconFinder(), serializer: NoOpSerializer(), asyncRunner: DispatchQueueAsyncRunner()) DependencyInjector.register(dependency: presenter) + DependencyInjector.register(dependency: authenticationService) + + return authenticationService } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AddAccountDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AddAccountDialog.swift index 1f797ba2..4cab9b36 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AddAccountDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AddAccountDialog.swift @@ -20,6 +20,8 @@ struct AddAccountDialog: View { @Inject private var presenter: BankingPresenterSwift + @Inject private var authenticationService: AuthenticationService + var body: some View { Form { @@ -107,7 +109,6 @@ struct AddAccountDialog: View { DispatchQueue.main.async { // dispatch async as may EnterTanDialog is still displayed so dismiss() won't dismiss this view self.closeDialog() - let authenticationService = AuthenticationService() if self.presenter.allBanks.count == 1 && authenticationService.authenticationType == .none { UIAlert("Secure data?", "Secure data with password or %@?".localize(authenticationService.supportedBiometricAuthenticationLocalizedName), diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift index 445d9e04..64f16eae 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift @@ -19,7 +19,7 @@ struct LoginDialog: View { private let needsTouchIDToUnlockApp: Bool - init(_ authenticationService: AuthenticationService = AuthenticationService(), allowCancellingLogin: Bool = false, loginReason: LocalizedStringKey? = nil, loginResult: @escaping (Bool) -> Void) { + init(_ authenticationService: AuthenticationService, allowCancellingLogin: Bool = false, loginReason: LocalizedStringKey? = nil, loginResult: @escaping (Bool) -> Void) { self.authenticationService = authenticationService self.allowCancellingLogin = allowCancellingLogin @@ -130,7 +130,7 @@ struct LoginDialog: View { struct LoginDialog_Previews: PreviewProvider { static var previews: some View { - LoginDialog { _ in } + LoginDialog(AuthenticationService()) { _ in } } } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift index edae3a12..465c13df 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift @@ -5,8 +5,8 @@ struct ProtectAppSettingsDialog: View { @Environment(\.presentationMode) var presentation + @Inject private var authenticationService: AuthenticationService - private let authenticationService = AuthenticationService() private var supportedAuthenticationTypes: [AuthenticationType] = [] diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/SettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/SettingsDialog.swift index f1ebb914..f82b3fa7 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/SettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/SettingsDialog.swift @@ -9,6 +9,8 @@ struct SettingsDialog: View { @ObservedObject var data: AppData @Inject var presenter: BankingPresenterSwift + + @Inject private var authenticationService: AuthenticationService @State private var updateAccountsAutomatically: Bool = true @@ -116,8 +118,6 @@ struct SettingsDialog: View { private func navigateToProtectAppSettingsDialog() { - let authenticationService = AuthenticationService() - if authenticationService.needsAuthenticationToUnlockApp == false { SceneDelegate.navigateToView(ProtectAppSettingsDialog()) }