Skip to content

Commit

Permalink
New implementation of Passcode related features
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Sep 27, 2023
1 parent 9b766bd commit fe75e75
Show file tree
Hide file tree
Showing 56 changed files with 2,025 additions and 848 deletions.
441 changes: 279 additions & 162 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 37 additions & 31 deletions UnstoppableWallet/UnstoppableWallet/Core/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import CurrencyKit
import Foundation
import GRDB
import HsToolKit
import LanguageKit
import MarketKit
import PinKit
import StorageKit
import ThemeKit
import LanguageKit

class App {
static var instance: App?
Expand All @@ -20,7 +19,13 @@ class App {
}

let keychainKit: IKeychainKit
let pinKit: PinKit.Kit

let passcodeManager: PasscodeManager
let biometryManager: BiometryManager
let lockManager: LockManager
let lockoutManager: LockoutManager

let blurManager: BlurManager

let currencyKit: CurrencyKit.Kit

Expand Down Expand Up @@ -81,7 +86,7 @@ class App {
let kitCleaner: KitCleaner

let keychainKitDelegate: KeychainKitDelegate
let pinKitDelegate: PinKitDelegate
let lockDelegate = LockDelegate()

let rateAppManager: RateAppManager
let guidesManager: GuidesManager
Expand Down Expand Up @@ -239,8 +244,12 @@ class App {
let favoriteCoinRecordStorage = FavoriteCoinRecordStorage(dbPool: dbPool)
favoritesManager = FavoritesManager(storage: favoriteCoinRecordStorage)

pinKit = PinKit.Kit(secureStorage: keychainKit.secureStorage, localStorage: StorageKit.LocalStorage.default)
let blurManager = BlurManager(pinKit: pinKit)
biometryManager = BiometryManager(localStorage: StorageKit.LocalStorage.default)
passcodeManager = PasscodeManager(biometryManager: biometryManager, secureStorage: keychainKit.secureStorage)
lockManager = LockManager(passcodeManager: passcodeManager, localStorage: StorageKit.LocalStorage.default, delegate: lockDelegate)
lockoutManager = LockoutManager(secureStorage: keychainKit.secureStorage)

blurManager = BlurManager(lockManager: lockManager)

let appVersionRecordStorage = AppVersionRecordStorage(dbPool: dbPool)
let appVersionStorage = AppVersionStorage(storage: appVersionRecordStorage)
Expand All @@ -263,9 +272,6 @@ class App {
keychainKitDelegate = KeychainKitDelegate(accountManager: accountManager, walletManager: walletManager)
keychainKit.set(delegate: keychainKitDelegate)

pinKitDelegate = PinKitDelegate()
pinKit.set(delegate: pinKitDelegate)

rateAppManager = RateAppManager(walletManager: walletManager, adapterManager: adapterManager, localStorage: localStorage)

guidesManager = GuidesManager(networkManager: networkManager)
Expand Down Expand Up @@ -308,36 +314,36 @@ class App {

let chartRepository = ChartIndicatorsRepository(localStorage: localStorage, subscriptionManager: subscriptionManager)
appBackupProvider = AppBackupProvider(
accountManager: accountManager,
accountFactory: accountFactory,
walletManager: walletManager,
favoritesManager: favoritesManager,
evmSyncSourceManager: evmSyncSourceManager,
btcBlockchainManager: btcBlockchainManager,
restoreSettingsManager: restoreSettingsManager,
chartRepository: chartRepository,
localStorage: localStorage,
languageManager: LanguageManager.shared,
currencyKit: currencyKit,
themeManager: themeManager,
launchScreenManager: launchScreenManager,
appIconManager: appIconManager,
balancePrimaryValueManager: balancePrimaryValueManager,
balanceConversionManager: balanceConversionManager,
balanceHiddenManager: balanceHiddenManager,
contactManager: contactManager
accountManager: accountManager,
accountFactory: accountFactory,
walletManager: walletManager,
favoritesManager: favoritesManager,
evmSyncSourceManager: evmSyncSourceManager,
btcBlockchainManager: btcBlockchainManager,
restoreSettingsManager: restoreSettingsManager,
chartRepository: chartRepository,
localStorage: localStorage,
languageManager: LanguageManager.shared,
currencyKit: currencyKit,
themeManager: themeManager,
launchScreenManager: launchScreenManager,
appIconManager: appIconManager,
balancePrimaryValueManager: balancePrimaryValueManager,
balanceConversionManager: balanceConversionManager,
balanceHiddenManager: balanceHiddenManager,
contactManager: contactManager
)
cloudBackupManager = CloudBackupManager(
ubiquityContainerIdentifier: AppConfig.sharedCloudContainer,
appBackupProvider: appBackupProvider,
logger: logger
ubiquityContainerIdentifier: AppConfig.sharedCloudContainer,
appBackupProvider: appBackupProvider,
logger: logger
)

appManager = AppManager(
accountManager: accountManager,
walletManager: walletManager,
adapterManager: adapterManager,
pinKit: pinKit,
lockManager: lockManager,
keychainKit: keychainKit,
blurManager: blurManager,
kitCleaner: kitCleaner,
Expand Down
31 changes: 12 additions & 19 deletions UnstoppableWallet/UnstoppableWallet/Core/Managers/AppManager.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Foundation
import RxSwift
import StorageKit
import PinKit

class AppManager {
private let accountManager: AccountManager
private let walletManager: WalletManager
private let adapterManager: AdapterManager
private let pinKit: PinKit.Kit
private let lockManager: LockManager
private let keychainKit: IKeychainKit
private let blurManager: BlurManager
private let kitCleaner: KitCleaner
Expand All @@ -21,25 +20,25 @@ class AppManager {
private let walletConnectSocketConnectionService: WalletConnectSocketConnectionService
private let nftMetadataSyncer: NftMetadataSyncer

private let didBecomeActiveSubject = PublishSubject<()>()
private let willEnterForegroundSubject = PublishSubject<()>()
private let didBecomeActiveSubject = PublishSubject<Void>()
private let willEnterForegroundSubject = PublishSubject<Void>()

init(accountManager: AccountManager, walletManager: WalletManager, adapterManager: AdapterManager, pinKit: PinKit.Kit,
init(accountManager: AccountManager, walletManager: WalletManager, adapterManager: AdapterManager, lockManager: LockManager,
keychainKit: IKeychainKit, blurManager: BlurManager,
kitCleaner: KitCleaner, debugLogger: DebugLogger?,
appVersionManager: AppVersionManager, rateAppManager: RateAppManager,
logRecordManager: LogRecordManager,
deepLinkManager: DeepLinkManager, evmLabelManager: EvmLabelManager, balanceHiddenManager: BalanceHiddenManager,
walletConnectSocketConnectionService: WalletConnectSocketConnectionService, nftMetadataSyncer: NftMetadataSyncer
) {
walletConnectSocketConnectionService: WalletConnectSocketConnectionService, nftMetadataSyncer: NftMetadataSyncer)
{
self.accountManager = accountManager
self.walletManager = walletManager
self.adapterManager = adapterManager
self.pinKit = pinKit
self.lockManager = lockManager
self.keychainKit = keychainKit
self.blurManager = blurManager
self.kitCleaner = kitCleaner
self.debugBackgroundLogger = debugLogger
debugBackgroundLogger = debugLogger
self.appVersionManager = appVersionManager
self.rateAppManager = rateAppManager
self.logRecordManager = logRecordManager
Expand All @@ -49,18 +48,15 @@ class AppManager {
self.walletConnectSocketConnectionService = walletConnectSocketConnectionService
self.nftMetadataSyncer = nftMetadataSyncer
}

}

extension AppManager {

func didFinishLaunching() {
debugBackgroundLogger?.logFinishLaunching()

keychainKit.handleLaunch()
accountManager.handleLaunch()
walletManager.preloadWallets()
pinKit.didFinishLaunching()
kitCleaner.clear()

rateAppManager.onLaunch()
Expand All @@ -84,7 +80,7 @@ extension AppManager {
func didEnterBackground() {
debugBackgroundLogger?.logEnterBackground()

pinKit.didEnterBackground()
lockManager.didEnterBackground()
walletConnectSocketConnectionService.didEnterBackground()
balanceHiddenManager.didEnterBackground()
}
Expand All @@ -97,7 +93,7 @@ extension AppManager {
willEnterForegroundSubject.onNext(())

keychainKit.handleForeground()
pinKit.willEnterForeground()
lockManager.willEnterForeground()
adapterManager.refresh()
walletConnectSocketConnectionService.willEnterForeground()

Expand All @@ -111,17 +107,14 @@ extension AppManager {
func didReceive(url: URL) -> Bool {
deepLinkManager.handle(url: url)
}

}

extension AppManager: IAppManager {

var didBecomeActiveObservable: Observable<()> {
var didBecomeActiveObservable: Observable<Void> {
didBecomeActiveSubject.asObservable()
}

var willEnterForegroundObservable: Observable<()> {
var willEnterForegroundObservable: Observable<Void> {
willEnterForegroundSubject.asObservable()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Combine
import HsExtensions
import LocalAuthentication
import StorageKit

class BiometryManager {
private let biometricOnKey = "biometric_on_key"

private let localStorage: ILocalStorage
private var tasks = Set<AnyTask>()

@PostPublished var biometryType: BiometryType?
@PostPublished var biometryEnabled: Bool {
didSet {
localStorage.set(value: biometryEnabled, for: biometricOnKey)
}
}

init(localStorage: ILocalStorage) {
self.localStorage = localStorage

biometryEnabled = localStorage.value(for: biometricOnKey) ?? false

refreshBiometry()
}

private func refreshBiometry() {
Task { [weak self] in
var authError: NSError?
let localAuthenticationContext = LAContext()

if localAuthenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
switch localAuthenticationContext.biometryType {
case .faceID: self?.biometryType = .faceId
case .touchID: self?.biometryType = .touchId
default: self?.biometryType = .none
}
} else {
self?.biometryType = .none
}
}.store(in: &tasks)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import UIKit
import UIExtensions
import ThemeKit
import PinKit
import UIExtensions
import UIKit

class BlurManager {
private let coverView = UIView()
private let logoImageView = UIImageView()

private let pinKit: PinKit.Kit
private let lockManager: LockManager
private var shown = false

init(pinKit: PinKit.Kit) {
self.pinKit = pinKit
var isEnabled = true

init(lockManager: LockManager) {
self.lockManager = lockManager

coverView.backgroundColor = .themeTyler

Expand Down Expand Up @@ -61,17 +62,11 @@ class BlurManager {
window?.addSubview(coverView)
shown = true
}

private var unlockShown: Bool {
(UIViewController.visibleController as? PinViewController) != nil
}

}

extension BlurManager {

func willResignActive() {
if !pinKit.isLocked && !unlockShown {
if !lockManager.isLocked, isEnabled {
show()
}
}
Expand All @@ -94,5 +89,4 @@ extension BlurManager {
shown = false
coverView.removeFromSuperview()
}

}
Loading

0 comments on commit fe75e75

Please sign in to comment.