Skip to content

Commit

Permalink
Merge pull request #144 from niscy-eudiw/main
Browse files Browse the repository at this point in the history
Perform the first boot storage management sync into the StartupIntera…
  • Loading branch information
stzouvaras authored Jul 31, 2024
2 parents 5ae8584 + 526605b commit 3045c44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
import Swinject
import logic_core
import logic_business
import feature_common

public final class FeatureStartupAssembly: Assembly {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,27 @@ 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
}

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() {
Expand All @@ -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)
}
}
}
20 changes: 0 additions & 20 deletions Wallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -32,9 +29,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Initialize Reporting
initializeReporting()

// Check firt run and clear keychain from previous installations
manageStorage()

return true
}

Expand All @@ -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()
}
}
}

0 comments on commit 3045c44

Please sign in to comment.