82 lines
2.4 KiB
Swift
82 lines
2.4 KiB
Swift
//
|
|
// InheritanceViewShare.swift
|
|
// Wallet
|
|
//
|
|
// Created by Igor on 15.03.2021.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class InheritanceViewShare: CommonViewCustom {
|
|
|
|
@IBOutlet private weak var accountTextField: CommonTextField!
|
|
@IBOutlet private weak var valueTextField: CommonTextField!
|
|
|
|
var share: Inheritance.Model.Share { didSet { reload() } }
|
|
let completion: (Inheritance.Model.Share) -> Void
|
|
var showDelete = false {
|
|
didSet {
|
|
accountTextField.accessoryView = showDelete
|
|
? .button(
|
|
style: .tertiary,
|
|
title: L10n.Common.Button.delete,
|
|
image: Asset.inheritanceDelete.image,
|
|
size: .small
|
|
) { [weak self] in
|
|
guard let self else { return }
|
|
self.completion(self.share)
|
|
}
|
|
: nil
|
|
}
|
|
}
|
|
|
|
init(share: Inheritance.Model.Share, delete: @escaping (Inheritance.Model.Share) -> Void) {
|
|
self.share = share
|
|
self.completion = delete
|
|
super.init(frame: .zero)
|
|
reload()
|
|
}
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
func update(error: String?) {
|
|
if let error = error {
|
|
if valueTextField.isFirstResponder { valueTextField.error = error }
|
|
} else {
|
|
valueTextField.error = nil
|
|
}
|
|
}
|
|
|
|
func reload() {
|
|
accountTextField.value = share.account
|
|
valueTextField.value = share.value?.toString(max: 1) ?? ""
|
|
}
|
|
|
|
override func setup() {
|
|
super.setup()
|
|
accountTextField.action = .autocomplete(
|
|
icon: Asset.commonArrowDown.image,
|
|
title: L10n.Resources.Setup.Account.select,
|
|
service: Account.Service.Contacts()
|
|
) { [weak self] in
|
|
guard let self else { return }
|
|
self.endEditing(true)
|
|
self.share.account = $0.uuid
|
|
}
|
|
valueTextField.keyboardType = .decimalPad
|
|
valueTextField.precision = 1
|
|
valueTextField.suffix = "%"
|
|
valueTextField.delegate = self
|
|
}
|
|
|
|
}
|
|
|
|
extension InheritanceViewShare: CommonTextFieldDelegate {
|
|
func textFieldDidChange(_ textField: CommonTextField) {
|
|
share.value = ["", "0", "0.0", "0.00"].contains(textField.value) ? nil : textField.value.toDouble()
|
|
}
|
|
}
|