diff --git a/Modules/feature-startup/Sources/DI/FeatureStartupAssembly.swift b/Modules/feature-startup/Sources/DI/FeatureStartupAssembly.swift index fa322de9..32c49872 100644 --- a/Modules/feature-startup/Sources/DI/FeatureStartupAssembly.swift +++ b/Modules/feature-startup/Sources/DI/FeatureStartupAssembly.swift @@ -15,6 +15,7 @@ */ import Swinject import logic_core +import logic_business import feature_common public final class FeatureStartupAssembly: Assembly { @@ -25,7 +26,9 @@ public final class FeatureStartupAssembly: Assembly { container.register(StartupInteractor.self) { r in StartupInteractorImpl( walletKitController: r.force(WalletKitController.self), - quickPinInteractor: r.force(QuickPinInteractor.self) + quickPinInteractor: r.force(QuickPinInteractor.self), + keyChainController: r.force(KeyChainController.self), + prefsController: r.force(PrefsController.self) ) } .inObjectScope(ObjectScope.transient) diff --git a/Modules/feature-startup/Sources/Interactor/StartupInteractor.swift b/Modules/feature-startup/Sources/Interactor/StartupInteractor.swift index 07f368ef..282d1bbc 100644 --- a/Modules/feature-startup/Sources/Interactor/StartupInteractor.swift +++ b/Modules/feature-startup/Sources/Interactor/StartupInteractor.swift @@ -27,6 +27,8 @@ final class StartupInteractorImpl: StartupInteractor { private let walletKitController: WalletKitController private let quickPinInteractor: QuickPinInteractor + private let keyChainController: KeyChainController + private let prefsController: PrefsController private var hasDocuments: Bool { return !walletKitController.fetchAllDocuments().isEmpty @@ -34,13 +36,18 @@ final class StartupInteractorImpl: StartupInteractor { init( walletKitController: WalletKitController, - quickPinInteractor: QuickPinInteractor + quickPinInteractor: QuickPinInteractor, + keyChainController: KeyChainController, + prefsController: PrefsController ) { self.walletKitController = walletKitController self.quickPinInteractor = quickPinInteractor + self.keyChainController = keyChainController + self.prefsController = prefsController } public func initialize(with splashAnimationDuration: TimeInterval) async -> AppRoute { + await manageStorageForFirstRun() try? await walletKitController.loadDocuments() try? await Task.sleep(nanoseconds: splashAnimationDuration.nanoseconds) if quickPinInteractor.hasPin() { @@ -63,4 +70,12 @@ final class StartupInteractorImpl: StartupInteractor { return .quickPin(config: QuickPinUiConfig(flow: .set)) } } + + private func manageStorageForFirstRun() async { + if !prefsController.getBool(forKey: .runAtLeastOnce) { + await walletKitController.clearAllDocuments() + keyChainController.clear() + prefsController.setValue(true, forKey: .runAtLeastOnce) + } + } } diff --git a/Wallet/AppDelegate.swift b/Wallet/AppDelegate.swift index 14a0fb76..a4c866b6 100644 --- a/Wallet/AppDelegate.swift +++ b/Wallet/AppDelegate.swift @@ -19,9 +19,6 @@ import logic_assembly class AppDelegate: UIResponder, UIApplicationDelegate { - private lazy var prefsController: PrefsController = DIGraph.resolver.force(PrefsController.self) - private lazy var keyChainController: KeyChainController = DIGraph.resolver.force(KeyChainController.self) - private lazy var walletKitController: WalletKitController = DIGraph.resolver.force(WalletKitController.self) private lazy var analyticsController: AnalyticsController = DIGraph.resolver.force(AnalyticsController.self) func application( @@ -32,9 +29,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Initialize Reporting initializeReporting() - // Check firt run and clear keychain from previous installations - manageStorage() - return true } @@ -51,18 +45,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate { private func initializeReporting() { analyticsController.initialize() } - - private func manageStorage() { - if !prefsController.getBool(forKey: .runAtLeastOnce) { - clearDocuments() - keyChainController.clear() - prefsController.setValue(true, forKey: .runAtLeastOnce) - } - } - - private func clearDocuments() { - Task { - await walletKitController.clearAllDocuments() - } - } }