Files
raspberry/iOS/Wallet/Sources/Account/Controller/AccountControllerOnboarding.swift
2022-12-08 15:31:06 +03:00

99 lines
3.4 KiB
Swift

//
// AccountControllerOnboarding.swift
// Wallet
//
// Created by Igor Danich on 24.08.2020.
// Copyright © 2020 List. All rights reserved.
//
import UIKit
final class AccountControllerOnboarding: UIViewController {
@IBOutlet private weak var lengthImgView: UIImageView!
@IBOutlet private weak var textField: UITextField!
@IBOutlet private weak var submitBtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
textField.text = kAuthorizationPassword
textField.rightViewMode = .always
textField.isSecureTextEntry = true
update()
updateSecure()
}
private func updateSecure() {
textField.rightView = UIButton.button(
image: textField.isSecureTextEntry ? Asset.commonPasswordShow.image : Asset.commonPasswordHide.image,
action: { [weak self] in
guard let self = self else { return }
self.textField.isSecureTextEntry = !self.textField.isSecureTextEntry
self.updateSecure()
}
)
}
private func update() {
let text = textField.text ?? ""
lengthImgView.image = Accounts().validate(password: text)
? Asset.commonAccessorySuccess.image : Asset.commonAccessoryFailed.image
submitBtn.isEnabled = Accounts().validate(password: text)
}
@IBAction private func onSubmit(_ : AnyObject?) {
let password = textField.text ?? ""
try? Accounts().update(password: password)
Popup.show(
title: L10n.Account.Onboarding.Success.title,
description: L10n.Account.Onboarding.Success.description,
submit: Account.Service.isBiometricksAvailable ? L10n.Account.Onboarding.Success.submit : L10n.Common.Button.ok,
in: self
) { ctrl in
ctrl.dismiss(animated: true)
guard Account.Service.isBiometricksAvailable else { return }
let result: (UIViewController) -> Void = { ctrl in
ctrl.dismiss(animated: true)
Account.Service.checkBiometricks { (success) in
if success {
Account.Service.isBiometricksEnabled = true
Alert.success()
} else {
Alert.error(text: L10n.Account.Onboarding.Bimetricks.error)
}
}
}
if Account.Service.isFaceIdAvailable {
Popup.show(
title: L10n.Account.Onboarding.FaceId.title,
image: Asset.commonFaceId.image,
description: L10n.Account.Onboarding.FaceId.description,
submit: L10n.Account.Onboarding.FaceId.submit,
in: self,
result
)
} else {
Popup.show(
title: L10n.Account.Onboarding.TouchId.title,
image: Asset.commonTouchId.image,
description: L10n.Account.Onboarding.TouchId.description,
submit: L10n.Account.Onboarding.TouchId.submit,
in: self,
result
)
}
}
}
@IBAction func onInfo(_: AnyObject?) {
Alert.hint(text: L10n.Account.Onboarding.Password.hint)
}
}
extension AccountControllerOnboarding: UITextFieldDelegate {
func textFieldDidEndEditing(_ textField: UITextField) {
update()
}
}