From 6c32021834a94fadf7e5d261669ebc6399ae43e1 Mon Sep 17 00:00:00 2001 From: Swen van Zanten Date: Fri, 24 Aug 2018 17:45:10 +0200 Subject: [PATCH 1/3] Revamp send view and add send confirm view --- VergeiOS.xcodeproj/project.pbxproj | 20 ++ .../Icons/Checked.imageset/Contents.json | 16 ++ .../Icons/Checked.imageset/icons8-checked.pdf | Bin 0 -> 1173 bytes .../UI/Buttons/SelectorButton.swift | 4 +- .../UI/Layout/BorderPanelView.swift | 75 ++++- VergeiOS/Components/UI/Layout/PanelView.swift | 18 +- VergeiOS/Delegates/AmountDelegate.swift | 11 + VergeiOS/Delegates/RecipientDelegate.swift | 11 + VergeiOS/Model/SendTransaction.swift | 14 + VergeiOS/Storyboards/Send.storyboard | 114 +++++--- VergeiOS/Views/Send/ConfirmSendView.swift | 74 +++++ VergeiOS/Views/Send/ConfirmSendView.xib | 270 ++++++++++++++++++ .../Views/Send/ScanQRCodeViewController.swift | 6 +- .../SelectRecipientTableViewController.swift | 69 +---- VergeiOS/Views/Send/SendViewController.swift | 118 ++++++-- .../Views/Send/SetAmountViewController.swift | 17 +- 16 files changed, 692 insertions(+), 145 deletions(-) create mode 100644 VergeiOS/Assets.xcassets/Icons/Checked.imageset/Contents.json create mode 100644 VergeiOS/Assets.xcassets/Icons/Checked.imageset/icons8-checked.pdf create mode 100644 VergeiOS/Delegates/AmountDelegate.swift create mode 100644 VergeiOS/Delegates/RecipientDelegate.swift create mode 100644 VergeiOS/Model/SendTransaction.swift create mode 100644 VergeiOS/Views/Send/ConfirmSendView.swift create mode 100644 VergeiOS/Views/Send/ConfirmSendView.xib diff --git a/VergeiOS.xcodeproj/project.pbxproj b/VergeiOS.xcodeproj/project.pbxproj index 1a2004da..7ca692c5 100644 --- a/VergeiOS.xcodeproj/project.pbxproj +++ b/VergeiOS.xcodeproj/project.pbxproj @@ -118,6 +118,11 @@ A398B20F212B2886004ACB73 /* UIWindow+VisibleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A398B20E212B2886004ACB73 /* UIWindow+VisibleViewController.swift */; }; A398B213212EBDD7004ACB73 /* CreditsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A398B212212EBDD7004ACB73 /* CreditsTableViewController.swift */; }; A398B215212F0949004ACB73 /* DisconnectWalletViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A398B214212F0949004ACB73 /* DisconnectWalletViewController.swift */; }; + A398B21B212F91F0004ACB73 /* ConfirmSendView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A398B21A212F91F0004ACB73 /* ConfirmSendView.swift */; }; + A398B21F21302DC5004ACB73 /* ConfirmSendView.xib in Resources */ = {isa = PBXBuildFile; fileRef = A398B21E21302DC5004ACB73 /* ConfirmSendView.xib */; }; + B2BD72F8A7F67D4C11416F74 /* RecipientDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2BD74068BD3DBE015E9B35E /* RecipientDelegate.swift */; }; + B2BD76A67D70DB341C28F00B /* AmountDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2BD788873F8343FD7DB3E2C /* AmountDelegate.swift */; }; + B2BD7F39EE96EB7B9E5A870A /* SendTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2BD780B0BE45F52AD3B526D /* SendTransaction.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -270,6 +275,11 @@ A398B20E212B2886004ACB73 /* UIWindow+VisibleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindow+VisibleViewController.swift"; sourceTree = ""; }; A398B212212EBDD7004ACB73 /* CreditsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreditsTableViewController.swift; sourceTree = ""; }; A398B214212F0949004ACB73 /* DisconnectWalletViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisconnectWalletViewController.swift; sourceTree = ""; }; + A398B21A212F91F0004ACB73 /* ConfirmSendView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfirmSendView.swift; sourceTree = ""; }; + A398B21E21302DC5004ACB73 /* ConfirmSendView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConfirmSendView.xib; sourceTree = ""; }; + B2BD74068BD3DBE015E9B35E /* RecipientDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecipientDelegate.swift; sourceTree = ""; }; + B2BD780B0BE45F52AD3B526D /* SendTransaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendTransaction.swift; sourceTree = ""; }; + B2BD788873F8343FD7DB3E2C /* AmountDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AmountDelegate.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -309,6 +319,7 @@ 07B9F4532107C9EB00871990 /* BlockchainInfo.swift */, A3256664211A3B61006FB08A /* XvgInfo.swift */, A302D2FA211F64FB00EA8091 /* Address.swift */, + B2BD780B0BE45F52AD3B526D /* SendTransaction.swift */, ); path = Model; sourceTree = ""; @@ -459,6 +470,8 @@ isa = PBXGroup; children = ( A305DDB92107BB8B00911B64 /* KeyboardDelegate.swift */, + B2BD74068BD3DBE015E9B35E /* RecipientDelegate.swift */, + B2BD788873F8343FD7DB3E2C /* AmountDelegate.swift */, ); path = Delegates; sourceTree = ""; @@ -585,6 +598,8 @@ A302D2EE211F2E4900EA8091 /* SelectRecipientTableViewController.swift */, A302D2F0211F3B4400EA8091 /* SetAmountViewController.swift */, A302D306212036B400EA8091 /* ScanQRCodeViewController.swift */, + A398B21A212F91F0004ACB73 /* ConfirmSendView.swift */, + A398B21E21302DC5004ACB73 /* ConfirmSendView.xib */, ); path = Send; sourceTree = ""; @@ -838,6 +853,7 @@ A325664B211373FF006FB08A /* Wallet.storyboard in Resources */, A376411B2108F0C700E04521 /* Cartfile in Resources */, A338E6B92110D60F000D44EE /* ChartWalletSlideView.xib in Resources */, + A398B21F21302DC5004ACB73 /* ConfirmSendView.xib in Resources */, A32566562115AEDB006FB08A /* FiatBalanceView.xib in Resources */, A325664321135A00006FB08A /* Settings.storyboard in Resources */, A305DDA52106940E00911B64 /* .gitignore in Resources */, @@ -963,6 +979,7 @@ A305DDC32107C83200911B64 /* NumberKey.swift in Sources */, A302D3412122053300EA8091 /* PriceTicker.swift in Sources */, A338E69C210D456D000D44EE /* ConfirmPaperkeyViewController.swift in Sources */, + A398B21B212F91F0004ACB73 /* ConfirmSendView.swift in Sources */, A325664D211375E5006FB08A /* PinUnlockViewController.swift in Sources */, A302D2F1211F3B4400EA8091 /* SetAmountViewController.swift in Sources */, A32566542115AEBF006FB08A /* XVGBalanceView.swift in Sources */, @@ -999,6 +1016,9 @@ A302D34D21260F1C00EA8091 /* UIScrollView+Pagination.swift in Sources */, A33F6A7020EEE485001492C2 /* AppDelegate.swift in Sources */, A302D2F9211F3F5700EA8091 /* XVGCardImageView.swift in Sources */, + B2BD72F8A7F67D4C11416F74 /* RecipientDelegate.swift in Sources */, + B2BD76A67D70DB341C28F00B /* AmountDelegate.swift in Sources */, + B2BD7F39EE96EB7B9E5A870A /* SendTransaction.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/VergeiOS/Assets.xcassets/Icons/Checked.imageset/Contents.json b/VergeiOS/Assets.xcassets/Icons/Checked.imageset/Contents.json new file mode 100644 index 00000000..e5541d52 --- /dev/null +++ b/VergeiOS/Assets.xcassets/Icons/Checked.imageset/Contents.json @@ -0,0 +1,16 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "icons8-checked.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + }, + "properties" : { + "template-rendering-intent" : "template", + "preserves-vector-representation" : true + } +} \ No newline at end of file diff --git a/VergeiOS/Assets.xcassets/Icons/Checked.imageset/icons8-checked.pdf b/VergeiOS/Assets.xcassets/Icons/Checked.imageset/icons8-checked.pdf new file mode 100644 index 0000000000000000000000000000000000000000..1f891fccf86a955a06ae98c82f96f2773a69ea4e GIT binary patch literal 1173 zcmZWpYe-X390%z`T#D#{iDDg!;RbE@-d#608^PM9v(&~`Sq+QRcAU5L-gWO;%=}=_ z4<$XZh|-K+NM>MSMg%>u2Nk;LLDCBnOQAmW0HY{6=gzHRhr>Dd{LcUUAHUz9tMj=_ zjJ(Oh=z2e2{>2mm4#*ofF%Ab{%aIhpwZK9kKLY?@OT;>i6tdSrjNB+BhY_=638P{K z!Fnd%T7S5rvY(r_XWYJr-M%-!pz^@&nF;T-=CQ16H~ZBSoG|O+vkz)}d((oJFE^&H z*F7EaZZHfc#*eOlCsa2b$r)dC&T%5)Z0j96^X+%e+V_vLr_SvO9QNiFbq0GzuXvir zKN{kFZLQvx;PYFrnX-~O2ac-w9ad%6>W4$F3&GYm`H^Fib5+5Z-Vm+izLY;6vYu@T zE)F#M>Ya&LcGZ!G#;RxDfw#IfD3LW>{Bw2gp9kfaMrWhzxzm5V9fYU;?Cun{%-hNA z+q)8W)sAK_{<`d51$;4d!}0FU?kOh+zqd3T%DwvP?ET|+Uv}>w@XW93=$6|1wx4e< zb3)#PJx0sSaA3`F;8WyqEJV6nAA+JH1Kz}2OgsnlwHQZ> zSwb#BBMOYxiXqh`D-nZ13*;ibk40H>Q(^S(Vl&6vIGb7E?R+6;Hgc8%jx%J$EXs(P zOxgu8tdk>}H!6%eA;mud;|i)_IACMA^Z-_iMX-Pxkix8XJJ4={l*S5egfcoZF`m#i z3FCOufRix6_P@U(E0KMYoy|siB!yuGigifQ{vH8w8zL!FG5oTO0WCb)F=bMX3@G=S Um@0+})+)3MW=5y;tSDjr0&dN2eE NSNumber +} diff --git a/VergeiOS/Delegates/RecipientDelegate.swift b/VergeiOS/Delegates/RecipientDelegate.swift new file mode 100644 index 00000000..d5727b90 --- /dev/null +++ b/VergeiOS/Delegates/RecipientDelegate.swift @@ -0,0 +1,11 @@ +// +// Created by Swen van Zanten on 24-08-18. +// Copyright (c) 2018 Verge Currency. All rights reserved. +// + +import Foundation + +protocol RecipientDelegate { + func didSelectRecipientAddress(_ address: String) + func selectedRecipientAddress() -> String +} diff --git a/VergeiOS/Model/SendTransaction.swift b/VergeiOS/Model/SendTransaction.swift new file mode 100644 index 00000000..a21cf3ae --- /dev/null +++ b/VergeiOS/Model/SendTransaction.swift @@ -0,0 +1,14 @@ +// +// Created by Swen van Zanten on 24-08-18. +// Copyright (c) 2018 Verge Currency. All rights reserved. +// + +import Foundation + +class SendTransaction { + + var amount: NSNumber = 0.0 + var address: String = "" + var memo: String = "" + +} diff --git a/VergeiOS/Storyboards/Send.storyboard b/VergeiOS/Storyboards/Send.storyboard index 37ddf393..e787c3d9 100644 --- a/VergeiOS/Storyboards/Send.storyboard +++ b/VergeiOS/Storyboards/Send.storyboard @@ -122,11 +122,22 @@ Please increase you're balance. + - + - + - + - + @@ -230,7 +261,6 @@ Please increase you're balance. - @@ -242,9 +272,11 @@ Please increase you're balance. - - - + + + + + @@ -253,18 +285,21 @@ Please increase you're balance. - @@ -300,23 +335,14 @@ Please increase you're balance. - - - - - - - - - - - - + + + - + @@ -343,9 +369,6 @@ Please increase you're balance. - - - @@ -658,13 +681,14 @@ Please increase you're balance. + + - @@ -674,8 +698,20 @@ Please increase you're balance. + + + + + + + + + + + + diff --git a/VergeiOS/Views/Send/ConfirmSendView.swift b/VergeiOS/Views/Send/ConfirmSendView.swift new file mode 100644 index 00000000..2a4c33d7 --- /dev/null +++ b/VergeiOS/Views/Send/ConfirmSendView.swift @@ -0,0 +1,74 @@ +// +// ConfirmSendView.swift +// VergeiOS +// +// Created by Swen van Zanten on 24-08-18. +// Copyright © 2018 Verge Currency. All rights reserved. +// + +import UIKit + +class ConfirmSendView: UIView { + + @IBOutlet weak var sendingAmountLabel: UILabel! + @IBOutlet weak var transactionFeeAmountLabel: UILabel! + @IBOutlet weak var totalXvgAmountLabel: UILabel! + @IBOutlet weak var totalFiatAmountLabel: UILabel! + @IBOutlet weak var recipientAddressLabel: UILabel! + + var transaction: SendTransaction! + + func makeActionSheet() -> UIAlertController { + let viewHeight: CGFloat = subviews.first?.frame.height ?? 0 + let lineHeight: CGFloat = 18.33 + let times = (viewHeight / lineHeight).rounded() + let enters: String = String(repeating: "\n", count: Int(times)) + + let alertController = UIAlertController(title: enters, message: nil, preferredStyle: .actionSheet) + + let margin: CGFloat = 10.0 + frame = CGRect( + x: 0, + y: 0, + width: alertController.view.bounds.size.width - margin * 2.0, + height: viewHeight + ) + + let container = UIView(frame: frame) + container.addSubview(self) + + alertController.view.addSubview(container) + + return alertController + } + + func setTransaction(_ transaction: SendTransaction) { + self.transaction = transaction + + updateTransactionValues() + } + + func updateTransactionValues() { + if let xvgInfo = PriceTicker.shared.xvgInfo { + let transactionFee = 0.1 + let totalXVG = transaction.amount.doubleValue + transactionFee + let totalFiat = totalXVG * xvgInfo.raw.price + + sendingAmountLabel.text = transaction.amount.toCurrency(currency: "XVG") + transactionFeeAmountLabel.text = NSNumber(floatLiteral: 0.1).toCurrency(currency: "XVG") + + totalXvgAmountLabel.text = NSNumber(floatLiteral: (transaction.amount.doubleValue + 0.1)).toCurrency( + currency: "XVG", + fractDigits: 6 + ) + + totalFiatAmountLabel.text = NSNumber(floatLiteral: totalFiat).toCurrency( + currency: WalletManager.default.currency, + fractDigits: 6 + ) + + recipientAddressLabel.text = transaction.address + } + } + +} diff --git a/VergeiOS/Views/Send/ConfirmSendView.xib b/VergeiOS/Views/Send/ConfirmSendView.xib new file mode 100644 index 00000000..0cfe80dc --- /dev/null +++ b/VergeiOS/Views/Send/ConfirmSendView.xib @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/VergeiOS/Views/Send/ScanQRCodeViewController.swift b/VergeiOS/Views/Send/ScanQRCodeViewController.swift index 1b379ec4..4c336536 100644 --- a/VergeiOS/Views/Send/ScanQRCodeViewController.swift +++ b/VergeiOS/Views/Send/ScanQRCodeViewController.swift @@ -10,8 +10,8 @@ import UIKit import AVFoundation class ScanQRCodeViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { - - var sendViewController: SendViewController? + + var delegate: RecipientDelegate! var captureSession: AVCaptureSession? var videoPreviewLayer: AVCaptureVideoPreviewLayer? @@ -108,7 +108,7 @@ class ScanQRCodeViewController: UIViewController, AVCaptureMetadataOutputObjects // Make sure we have a value. if metadataObj.stringValue != nil && metadataObj.stringValue?.count == 34 { - self.sendViewController?.receipientTextField.valueLabel?.text = metadataObj.stringValue + delegate.didSelectRecipientAddress(metadataObj.stringValue ?? "") DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { self.closeController(self) diff --git a/VergeiOS/Views/Send/SelectRecipientTableViewController.swift b/VergeiOS/Views/Send/SelectRecipientTableViewController.swift index 97bae4e6..c30f3c37 100644 --- a/VergeiOS/Views/Send/SelectRecipientTableViewController.swift +++ b/VergeiOS/Views/Send/SelectRecipientTableViewController.swift @@ -10,8 +10,8 @@ import UIKit class SelectRecipientTableViewController: UITableViewController, UITextFieldDelegate { - var sendViewController: SendViewController? - + var delegate: RecipientDelegate! + var addresses: [Address] = [] override func viewDidLoad() { @@ -29,11 +29,6 @@ class SelectRecipientTableViewController: UITableViewController, UITextFieldDele self.addresses.append(xvgAddress2) } - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { @@ -61,7 +56,7 @@ class SelectRecipientTableViewController: UITableViewController, UITextFieldDele override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.section == 0 && indexPath.row == 0 { let cell = tableView.dequeueReusableCell(withIdentifier: "addressCell", for: indexPath) as! AddressCell - cell.addressTextField.text = self.sendViewController?.receipientTextField.valueLabel?.text + cell.addressTextField.text = delegate.selectedRecipientAddress() cell.addressTextField.delegate = self return cell @@ -75,7 +70,7 @@ class SelectRecipientTableViewController: UITableViewController, UITextFieldDele cell.textLabel?.text = addresses[indexPath.row].name cell.detailTextLabel?.text = addresses[indexPath.row].address - if addresses[indexPath.row].address == self.sendViewController?.receipientTextField.valueLabel?.text { + if addresses[indexPath.row].address == delegate.selectedRecipientAddress() { cell.accessoryType = .checkmark } @@ -91,10 +86,10 @@ class SelectRecipientTableViewController: UITableViewController, UITextFieldDele tableView.deselectRow(at: indexPath, animated: true) return } - - self.sendViewController?.receipientTextField.valueLabel?.text = address + + delegate.didSelectRecipientAddress(address ?? "") } else { - self.sendViewController?.receipientTextField.valueLabel?.text = addresses[indexPath.row].address + delegate.didSelectRecipientAddress(addresses[indexPath.row].address) } self.closeViewController(self) @@ -106,50 +101,14 @@ class SelectRecipientTableViewController: UITableViewController, UITextFieldDele return true } - /* - // Override to support conditional editing of the table view. - override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { - // Return false if you do not want the specified item to be editable. - return true - } - */ - - /* - // Override to support editing the table view. - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { - if editingStyle == .delete { - // Delete the row from the data source - tableView.deleteRows(at: [indexPath], with: .fade) - } else if editingStyle == .insert { - // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view - } - } - */ - - /* - // Override to support rearranging the table view. - override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) { - - } - */ - - /* - // Override to support conditional rearranging of the table view. - override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { - // Return false if you do not want the item to be re-orderable. - return true - } - */ - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destinationViewController. - // Pass the selected object to the new view controller. + override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + switch indexPath.section { + case 1: + return 56 + default: + return 44 + } } - */ @IBAction func closeViewController(_ sender: Any) { self.dismiss(animated: true, completion: nil) diff --git a/VergeiOS/Views/Send/SendViewController.swift b/VergeiOS/Views/Send/SendViewController.swift index fb396aa0..6d67264a 100644 --- a/VergeiOS/Views/Send/SendViewController.swift +++ b/VergeiOS/Views/Send/SendViewController.swift @@ -13,43 +13,56 @@ enum CurrencySwitch { case FIAT } -class SendViewController: UIViewController { +class SendViewController: UIViewController, RecipientDelegate, AmountDelegate { @IBOutlet weak var xvgCardContainer: UIView! @IBOutlet weak var noBalanceView: UIView! @IBOutlet weak var walletAmountLabel: UILabel! - @IBOutlet weak var receipientTextField: SelectorButton! + @IBOutlet weak var recipientTextField: SelectorButton! @IBOutlet weak var amountTextField: SelectorButton! + @IBOutlet weak var memoTextField: UITextField! + @IBOutlet weak var confirmButton: UIButton! var currency = CurrencySwitch.XVG var walletAmount: NSNumber = WalletManager.default.amount var amount: NSNumber = 0.0 + var confirmButtonInterval: Timer? + override var prefersStatusBarHidden: Bool { return false } - + override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { return .slide } - + override func viewDidLoad() { super.viewDidLoad() - + + confirmButtonInterval = setInterval(1) { + self.isSendable() + } + DispatchQueue.main.async { self.updateAmountLabel() self.updateWalletAmountLabel() } - - NotificationCenter.default.addObserver(self, selector: #selector(didReceiveStats), name: .didReceiveStats, object: nil) + + NotificationCenter.default.addObserver( + self, + selector: #selector(didReceiveStats), + name: .didReceiveStats, + object: nil + ) } - + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - + self.xvgCardContainer.alpha = 0.0 self.xvgCardContainer.center.y += 20.0 - + UIView.animate(withDuration: 0.3, delay: 0.2, options: .curveEaseInOut, animations: { self.xvgCardContainer.alpha = 1.0 self.xvgCardContainer.center.y -= 20.0 @@ -60,14 +73,14 @@ class SendViewController: UIViewController { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } - + @objc func didReceiveStats(_ notification: Notification) { // Update price } - + @IBAction func switchCurrency(_ sender: UIBarButtonItem) { currency = (currency == .XVG) ? .FIAT : .XVG - + // Get current price. if let xvgInfo = PriceTicker.shared.xvgInfo { if currency == .XVG { @@ -80,45 +93,102 @@ class SendViewController: UIViewController { walletAmount = NSNumber(value: Double(truncating: walletAmount) * xvgInfo.raw.price) } } - + self.updateWalletAmountLabel() self.updateAmountLabel() } - + func updateWalletAmountLabel() { self.walletAmountLabel.text = walletAmount.toCurrency(currency: getCurrencyString()) } - + func updateAmountLabel() { self.amountTextField.valueLabel?.text = amount.toCurrency(currency: getCurrencyString(), fractDigits: 6) } - + func getCurrencyString() -> String { return currency == .XVG ? "XVG" : WalletManager.default.currency } - + // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. - + if segue.identifier == "scanQRCode" { let vc = segue.destination as! ScanQRCodeViewController - vc.sendViewController = self + vc.delegate = self } - + if segue.identifier == "selectRecipient" { let nc = segue.destination as! UINavigationController let vc = nc.viewControllers.first as! SelectRecipientTableViewController - vc.sendViewController = self + vc.delegate = self } - + if segue.identifier == "setAmount" { let vc = segue.destination as! SetAmountViewController - vc.sendViewController = self + vc.delegate = self + } + } + + func isSendable() { + let enabled = currentAmount().doubleValue > 0.0 && selectedRecipientAddress() != "" + + confirmButton.isEnabled = enabled + confirmButton.backgroundColor = (enabled ? UIColor.primaryLight() : UIColor.vergeGrey()) + } + + @IBAction func confirm(_ sender: Any) { + let confirmSendView = Bundle.main.loadNibNamed( + "ConfirmSendView", + owner: self, + options: nil + )?.first as! ConfirmSendView + + let transaction = SendTransaction() + transaction.amount = currentAmount() + transaction.address = selectedRecipientAddress() + + confirmSendView.setTransaction(transaction) + let alertController = confirmSendView.makeActionSheet() + let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) + let sendAction = UIAlertAction(title: "Send", style: .default) { alert in + self.didSelectRecipientAddress("") + self.didChangeAmount(0) } + + alertController.addAction(sendAction) + alertController.addAction(cancelAction) + + DispatchQueue.main.async { + self.present(alertController, animated: true, completion:{}) + } + } + + // MARK: - Recipients + + func didSelectRecipientAddress(_ address: String) { + recipientTextField.valueLabel?.text = address + } + + func selectedRecipientAddress() -> String { + return recipientTextField.valueLabel?.text ?? "" + } + + + // MARK: - Amounts + + func didChangeAmount(_ amount: NSNumber) { + self.amount = amount + + updateAmountLabel() + } + + func currentAmount() -> NSNumber { + return amount } } diff --git a/VergeiOS/Views/Send/SetAmountViewController.swift b/VergeiOS/Views/Send/SetAmountViewController.swift index e867e304..f55cf244 100644 --- a/VergeiOS/Views/Send/SetAmountViewController.swift +++ b/VergeiOS/Views/Send/SetAmountViewController.swift @@ -10,7 +10,7 @@ import UIKit class SetAmountViewController: UIViewController, KeyboardDelegate { - var sendViewController: SendViewController? + var delegate: AmountDelegate! @IBOutlet weak var currencyLabel: UILabel! @IBOutlet weak var amountLabel: UILabel! @@ -24,7 +24,7 @@ class SetAmountViewController: UIViewController, KeyboardDelegate { self.isSwipable() self.amountKeyboard.delegate = self - self.amount = Double(truncating: self.sendViewController!.amount) + self.amount = Double(truncating: delegate.currentAmount()) self.updateAmountLabel() } @@ -64,22 +64,11 @@ class SetAmountViewController: UIViewController, KeyboardDelegate { } @IBAction func setAmount(_ sender: Any) { - sendViewController?.amount = NSNumber(value: amount) - sendViewController?.updateAmountLabel() + delegate.didChangeAmount(NSNumber(value: amount)) self.closeViewController(self) } - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destinationViewController. - // Pass the selected object to the new view controller. - } - */ - @IBAction func closeViewController(_ sender: Any) { self.dismiss(animated: true, completion: nil) } From 642908b8b6266c1afc2e066e29ad0fcb09aa1c6f Mon Sep 17 00:00:00 2001 From: Swen van Zanten Date: Fri, 24 Aug 2018 19:50:34 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Added=20sending=20XVG=20simulation=20?= =?UTF-8?q?=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VergeiOS/Views/Send/SendViewController.swift | 56 ++++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/VergeiOS/Views/Send/SendViewController.swift b/VergeiOS/Views/Send/SendViewController.swift index 6d67264a..0a40828a 100644 --- a/VergeiOS/Views/Send/SendViewController.swift +++ b/VergeiOS/Views/Send/SendViewController.swift @@ -67,15 +67,16 @@ class SendViewController: UIViewController, RecipientDelegate, AmountDelegate { self.xvgCardContainer.alpha = 1.0 self.xvgCardContainer.center.y -= 20.0 }, completion: nil) - } - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. + updateWalletAmount() + updateWalletAmountLabel() + updateAmountLabel() } @objc func didReceiveStats(_ notification: Notification) { - // Update price + updateWalletAmount() + updateAmountLabel() + updateWalletAmountLabel() } @IBAction func switchCurrency(_ sender: UIBarButtonItem) { @@ -98,8 +99,13 @@ class SendViewController: UIViewController, RecipientDelegate, AmountDelegate { self.updateAmountLabel() } + func updateWalletAmount() { + walletAmount = WalletManager.default.amount + } + func updateWalletAmountLabel() { - self.walletAmountLabel.text = walletAmount.toCurrency(currency: getCurrencyString()) + let amountLeft = NSNumber(floatLiteral: walletAmount.doubleValue - amount.doubleValue - 0.1) + self.walletAmountLabel.text = amountLeft.toCurrency(currency: getCurrencyString()) } func updateAmountLabel() { @@ -156,22 +162,51 @@ class SendViewController: UIViewController, RecipientDelegate, AmountDelegate { let alertController = confirmSendView.makeActionSheet() let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) let sendAction = UIAlertAction(title: "Send", style: .default) { alert in - self.didSelectRecipientAddress("") - self.didChangeAmount(0) + self.sendXvg() } alertController.addAction(sendAction) alertController.addAction(cancelAction) + if let popoverController = alertController.popoverPresentationController { + popoverController.sourceView = self.view + popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0) + popoverController.permittedArrowDirections = [] + } + DispatchQueue.main.async { - self.present(alertController, animated: true, completion:{}) + self.present(alertController, animated: true) } } + func sendXvg() { + let unlockView = PinUnlockViewController.createFromStoryBoard() + unlockView.fillPinFor = .sending + unlockView.cancelable = true + unlockView.completion = { aunthenticated in + if !aunthenticated { + return unlockView.dismiss(animated: true) + } + + unlockView.dismiss(animated: true) + + // TODO ofcourse... + let newWalletAmount = NSNumber(floatLiteral: self.walletAmount.doubleValue - self.amount.doubleValue - 0.1) + WalletManager.default.amount = newWalletAmount + + self.didSelectRecipientAddress("") + self.didChangeAmount(0) + self.updateWalletAmount() + self.memoTextField.text = "" + } + + present(unlockView, animated: true) + } + // MARK: - Recipients func didSelectRecipientAddress(_ address: String) { - recipientTextField.valueLabel?.text = address + self.recipientTextField.valueLabel?.text = address } func selectedRecipientAddress() -> String { @@ -185,6 +220,7 @@ class SendViewController: UIViewController, RecipientDelegate, AmountDelegate { self.amount = amount updateAmountLabel() + updateWalletAmountLabel() } func currentAmount() -> NSNumber { From 6e8fdc052b4efdb5183fe1d2fb5ee459b4392ad5 Mon Sep 17 00:00:00 2001 From: Swen van Zanten Date: Fri, 24 Aug 2018 19:56:12 +0200 Subject: [PATCH 3/3] Added placeholder views --- VergeiOS/Storyboards/Settings.storyboard | 86 +++++++++++++++++++++++- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/VergeiOS/Storyboards/Settings.storyboard b/VergeiOS/Storyboards/Settings.storyboard index c3455ea7..db2dbaea 100644 --- a/VergeiOS/Storyboards/Settings.storyboard +++ b/VergeiOS/Storyboards/Settings.storyboard @@ -69,6 +69,9 @@ + + + @@ -206,6 +209,9 @@ + + + @@ -422,6 +428,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -674,6 +719,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -685,6 +767,7 @@ + @@ -708,9 +791,6 @@ - - -