2020-12-09 15:58:33 -08:00
|
|
|
//
|
|
|
|
// GetUTXOsViewController.swift
|
|
|
|
// ZcashLightClientSample
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 12/9/20.
|
|
|
|
// Copyright © 2020 Electric Coin Company. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import ZcashLightClientKit
|
|
|
|
import KRProgressHUD
|
|
|
|
class GetUTXOsViewController: UIViewController {
|
|
|
|
@IBOutlet weak var tAddressField: UITextField!
|
|
|
|
@IBOutlet weak var getButton: UIButton!
|
2020-12-11 12:15:29 -08:00
|
|
|
@IBOutlet weak var getFromCache: UIButton!
|
2020-12-09 15:58:33 -08:00
|
|
|
@IBOutlet weak var validAddressLabel: UILabel!
|
|
|
|
@IBOutlet weak var messageLabel: UILabel!
|
|
|
|
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
updateUI()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateUI() {
|
|
|
|
let valid = Initializer.shared.isValidTransparentAddress(tAddressField.text ?? "")
|
|
|
|
|
|
|
|
self.validAddressLabel.text = valid ? "Valid TransparentAddress" : "Invalid Transparent address"
|
|
|
|
self.validAddressLabel.textColor = valid ? UIColor.systemGreen : UIColor.systemRed
|
|
|
|
|
|
|
|
self.getButton.isEnabled = valid
|
2020-12-11 12:15:29 -08:00
|
|
|
self.getFromCache.isEnabled = valid
|
2020-12-09 15:58:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func getButtonTapped(_ sender: Any) {
|
|
|
|
guard Initializer.shared.isValidTransparentAddress(tAddressField.text ?? ""),
|
|
|
|
let tAddr = tAddressField.text else {
|
2020-12-11 12:15:29 -08:00
|
|
|
self.messageLabel.text = "Invalid t-Address"
|
2020-12-09 15:58:33 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
KRProgressHUD.showMessage("fetching")
|
2020-12-11 12:15:29 -08:00
|
|
|
AppDelegate.shared.sharedSynchronizer.latestUTXOs(address: tAddr) { (result) in
|
2020-12-09 15:58:33 -08:00
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
|
KRProgressHUD.dismiss()
|
|
|
|
switch result {
|
|
|
|
case .success(let utxos):
|
|
|
|
self?.messageLabel.text = "found \(utxos.count) UTXOs for address \(tAddr)"
|
|
|
|
|
|
|
|
case .failure(let error):
|
|
|
|
self?.messageLabel.text = "Error \(error)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 12:15:29 -08:00
|
|
|
@IBAction func getFromCacheTapped(_ sender: Any) {
|
|
|
|
guard Initializer.shared.isValidTransparentAddress(tAddressField.text ?? ""),
|
|
|
|
let tAddr = tAddressField.text else {
|
|
|
|
self.messageLabel.text = "Invalid t-Address"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
let utxos = try AppDelegate.shared.sharedSynchronizer.cachedUTXOs(address: tAddr)
|
|
|
|
self.messageLabel.text = "found \(utxos.count) UTXOs for address \(tAddr) on cache"
|
|
|
|
} catch {
|
|
|
|
self.messageLabel.text = "Error \(error)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-09 15:58:33 -08:00
|
|
|
@IBAction func viewTapped(_ recognizer: UITapGestureRecognizer) {
|
|
|
|
self.tAddressField.resignFirstResponder()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension GetUTXOsViewController: UITextFieldDelegate {
|
|
|
|
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
|
|
|
updateUI()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func textFieldDidEndEditing(_ textField: UITextField) {
|
|
|
|
updateUI()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|