Improve address field view

pull/2/head
Michael Scoff 7 years ago
parent aba42e1031
commit 0416abbb63
  1. 38
      Trust/Tokens/ViewControllers/NewTokenViewController.swift
  2. 26
      Trust/Transfer/ViewControllers/SendViewController.swift
  3. 37
      Trust/UI/Form/FieldAppereance.swift

@ -36,20 +36,10 @@ class NewTokenViewController: FormViewController {
title = viewModel.title
let qrButton = UIButton(type: .custom)
qrButton.translatesAutoresizingMaskIntoConstraints = false
qrButton.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
qrButton.setImage(R.image.qr_code_icon(), for: .normal)
qrButton.addTarget(self, action: #selector(openReader), for: .touchUpInside)
let recipientRightView = UIStackView(arrangedSubviews: [
qrButton,
.spacerWidth(1),
])
recipientRightView.translatesAutoresizingMaskIntoConstraints = false
recipientRightView.distribution = .equalSpacing
recipientRightView.spacing = 10
recipientRightView.axis = .horizontal
let recipientRightView = FieldAppereance.addressFieldRightView(
pasteAction: { self.pasteAction() },
qrAction: { self.openReader() }
)
form = Section()
@ -109,6 +99,23 @@ class NewTokenViewController: FormViewController {
present(controller, animated: true, completion: nil)
}
@objc func pasteAction() {
guard let value = UIPasteboard.general.string?.trimmed else {
return displayError(error: SendInputErrors.emptyClipBoard)
}
guard CryptoAddressValidator.isValidAddress(value) else {
return displayError(error: AddressError.invalidAddress)
}
updateContractValue(value: value)
}
private func updateContractValue(value: String) {
contractRow?.value = value
contractRow?.reload()
}
}
extension NewTokenViewController: QRCodeReaderDelegate {
@ -120,7 +127,6 @@ extension NewTokenViewController: QRCodeReaderDelegate {
reader.dismiss(animated: true, completion: nil)
guard let result = QRURLParser.from(string: result) else { return }
contractRow?.value = result.address
contractRow?.reload()
updateContractValue(value: result.address)
}
}

@ -56,7 +56,7 @@ class SendViewController: FormViewController {
private var data = Data()
lazy var currentPair: Pair = {
return Pair(left: viewModel.symbol, right: Config().currency.rawValue)
return Pair(left: viewModel.symbol, right: session.config.currency.rawValue)
}()
init(
@ -78,26 +78,10 @@ class SendViewController: FormViewController {
title = viewModel.title
view.backgroundColor = viewModel.backgroundColor
let pasteButton = Button(size: .normal, style: .borderless)
pasteButton.translatesAutoresizingMaskIntoConstraints = false
pasteButton.setTitle(NSLocalizedString("send.paste.button.title", value: "Paste", comment: ""), for: .normal)
pasteButton.addTarget(self, action: #selector(pasteAction), for: .touchUpInside)
let qrButton = UIButton(type: .custom)
qrButton.translatesAutoresizingMaskIntoConstraints = false
qrButton.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
qrButton.setImage(R.image.qr_code_icon(), for: .normal)
qrButton.addTarget(self, action: #selector(openReader), for: .touchUpInside)
let recipientRightView = UIStackView(arrangedSubviews: [
pasteButton,
qrButton,
.spacerWidth(1),
])
recipientRightView.translatesAutoresizingMaskIntoConstraints = false
recipientRightView.distribution = .equalSpacing
recipientRightView.spacing = 10
recipientRightView.axis = .horizontal
let recipientRightView = FieldAppereance.addressFieldRightView(
pasteAction: { self.pasteAction() },
qrAction: { self.openReader() }
)
let maxButton = Button(size: .normal, style: .borderless)
maxButton.translatesAutoresizingMaskIntoConstraints = false

@ -0,0 +1,37 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
import UIKit
class FieldAppereance {
static func addressFieldRightView(
pasteAction: @escaping () -> Void,
qrAction: @escaping () -> Void
) -> UIView {
let pasteButton = Button(size: .normal, style: .borderless)
pasteButton.translatesAutoresizingMaskIntoConstraints = false
pasteButton.setTitle(NSLocalizedString("send.paste.button.title", value: "Paste", comment: ""), for: .normal)
UITapGestureRecognizer(addToView: pasteButton) {
pasteAction()
}
let qrButton = UIButton(type: .custom)
qrButton.translatesAutoresizingMaskIntoConstraints = false
qrButton.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
qrButton.setImage(R.image.qr_code_icon(), for: .normal)
qrButton.contentEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
UITapGestureRecognizer(addToView: qrButton) {
qrAction()
}
let recipientRightView = UIStackView(arrangedSubviews: [
pasteButton,
qrButton,
])
recipientRightView.translatesAutoresizingMaskIntoConstraints = false
recipientRightView.distribution = .equalSpacing
recipientRightView.spacing = 2
recipientRightView.axis = .horizontal
return recipientRightView
}
}
Loading…
Cancel
Save