diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.pbxproj b/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.pbxproj index 6bf62abb..2f16a2e8 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.pbxproj +++ b/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 0D1BE4512581585C00F78BE3 /* DerivationToolViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D1BE4502581585C00F78BE3 /* DerivationToolViewController.swift */; }; + 0D1BE47F2581937100F78BE3 /* GetUTXOsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D1BE47E2581937100F78BE3 /* GetUTXOsViewController.swift */; }; 0D49A18C241698A800CC0649 /* SampleLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D49A18B241698A800CC0649 /* SampleLogger.swift */; }; 0D4EBA312396CFD70041B507 /* SendViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D4EBA302396CFD70041B507 /* SendViewController.swift */; }; 0D6CE8BD252E3C4A0005D707 /* SaplingParametersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D6CE8BC252E3C4A0005D707 /* SaplingParametersViewController.swift */; }; @@ -69,6 +70,7 @@ /* Begin PBXFileReference section */ 0D1BE4502581585C00F78BE3 /* DerivationToolViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DerivationToolViewController.swift; sourceTree = ""; }; + 0D1BE47E2581937100F78BE3 /* GetUTXOsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetUTXOsViewController.swift; sourceTree = ""; }; 0D49A18B241698A800CC0649 /* SampleLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleLogger.swift; sourceTree = ""; }; 0D4EBA302396CFD70041B507 /* SendViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendViewController.swift; sourceTree = ""; }; 0D6CE8BC252E3C4A0005D707 /* SaplingParametersViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaplingParametersViewController.swift; sourceTree = ""; }; @@ -155,6 +157,14 @@ path = "Derivation Tool"; sourceTree = ""; }; + 0D1BE47D2581933C00F78BE3 /* Get UTXOs */ = { + isa = PBXGroup; + children = ( + 0D1BE47E2581937100F78BE3 /* GetUTXOsViewController.swift */, + ); + path = "Get UTXOs"; + sourceTree = ""; + }; 0D4EBA2F2396CFBE0041B507 /* Send */ = { isa = PBXGroup; children = ( @@ -214,6 +224,7 @@ 0D907F142322CC5900D641FE /* ZcashLightClientSample */ = { isa = PBXGroup; children = ( + 0D1BE47D2581933C00F78BE3 /* Get UTXOs */, 0D1BE44F2581583D00F78BE3 /* Derivation Tool */, 0D6CE8BB252E3C1A0005D707 /* Sapling Parameters */, 0DBF8F9323A80F0E0010B85F /* Transaction Detail */, @@ -679,6 +690,7 @@ 0DDFB33E236B844900AED892 /* DemoAppConfig.swift in Sources */, 0D907F162322CC5900D641FE /* AppDelegate.swift in Sources */, 0D6CE8BD252E3C4A0005D707 /* SaplingParametersViewController.swift in Sources */, + 0D1BE47F2581937100F78BE3 /* GetUTXOsViewController.swift in Sources */, 0D1BE4512581585C00F78BE3 /* DerivationToolViewController.swift in Sources */, 0D7C85E523AD5A9B006878FC /* SampleStorage.swift in Sources */, 0D49A18C241698A800CC0649 /* SampleLogger.swift in Sources */, diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard b/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard index 0deae59a..e99fe7ba 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard +++ b/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard @@ -280,6 +280,26 @@ + + + + + + + + + + + + + + @@ -1352,6 +1372,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample/Get UTXOs/GetUTXOsViewController.swift b/Example/ZcashLightClientSample/ZcashLightClientSample/Get UTXOs/GetUTXOsViewController.swift new file mode 100644 index 00000000..03d577cb --- /dev/null +++ b/Example/ZcashLightClientSample/ZcashLightClientSample/Get UTXOs/GetUTXOsViewController.swift @@ -0,0 +1,71 @@ +// +// 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! + @IBOutlet weak var validAddressLabel: UILabel! + @IBOutlet weak var messageLabel: UILabel! + + var service: LightWalletGRPCService = LightWalletGRPCService(endpoint: DemoAppConfig.endpoint) + + 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 + } + + @IBAction func getButtonTapped(_ sender: Any) { + guard Initializer.shared.isValidTransparentAddress(tAddressField.text ?? ""), + let tAddr = tAddressField.text else { + return + } + KRProgressHUD.showMessage("fetching") + service.fetchUTXOs(for: tAddr) { [weak self] (result) in + 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)" + } + } + } + } + + @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() + } + +}