editing of memo completed

This commit is contained in:
loj 2019-02-21 22:50:07 +01:00
parent 15aeeab3ce
commit 3ec662c1e1
9 changed files with 120 additions and 36 deletions

View File

@ -21,6 +21,8 @@
EE1876A322161632004853A7 /* ReviewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1876A222161632004853A7 /* ReviewTableViewCell.swift */; };
EE1876A52219DD99004853A7 /* AmountVCViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1876A42219DD99004853A7 /* AmountVCViewModel.swift */; };
EE1876A72219FA15004853A7 /* Wallet.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1876A62219FA15004853A7 /* Wallet.swift */; };
EE1876A9221EE0B2004853A7 /* Payment.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1876A8221EE0B2004853A7 /* Payment.swift */; };
EE1876AB221F4CD0004853A7 /* MemoVCViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1876AA221F4CD0004853A7 /* MemoVCViewModel.swift */; };
EE377EB321E5303E00138385 /* ViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE377EB221E5303D00138385 /* ViewFactory.swift */; };
EE377EB521E6821F00138385 /* CreateNewWalletCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE377EB421E6821F00138385 /* CreateNewWalletCoordinator.swift */; };
EE377EB721E6831E00138385 /* CreateNewWalletCoordinator.Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE377EB621E6831E00138385 /* CreateNewWalletCoordinator.Delegate.swift */; };
@ -123,6 +125,8 @@
EE1876A222161632004853A7 /* ReviewTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewTableViewCell.swift; sourceTree = "<group>"; };
EE1876A42219DD99004853A7 /* AmountVCViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmountVCViewModel.swift; sourceTree = "<group>"; };
EE1876A62219FA15004853A7 /* Wallet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wallet.swift; sourceTree = "<group>"; };
EE1876A8221EE0B2004853A7 /* Payment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Payment.swift; sourceTree = "<group>"; };
EE1876AA221F4CD0004853A7 /* MemoVCViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoVCViewModel.swift; sourceTree = "<group>"; };
EE377EB221E5303D00138385 /* ViewFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewFactory.swift; sourceTree = "<group>"; };
EE377EB421E6821F00138385 /* CreateNewWalletCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateNewWalletCoordinator.swift; sourceTree = "<group>"; };
EE377EB621E6831E00138385 /* CreateNewWalletCoordinator.Delegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateNewWalletCoordinator.Delegate.swift; sourceTree = "<group>"; };
@ -302,6 +306,7 @@
EE377EE121F4F18700138385 /* TrxDirection.swift */,
EE377EE521F4F1C400138385 /* TrxHistoryObservable.swift */,
EE377EF021FDEE3F00138385 /* ZEC.swift */,
EE1876A8221EE0B2004853A7 /* Payment.swift */,
);
path = Types;
sourceTree = "<group>";
@ -548,6 +553,7 @@
children = (
EEBEBB9C2208D60100A6BD18 /* MemoVC.swift */,
EEBEBB9F2208D66600A6BD18 /* MemoVCDelegate.swift */,
EE1876AA221F4CD0004853A7 /* MemoVCViewModel.swift */,
);
path = Memo;
sourceTree = "<group>";
@ -707,6 +713,7 @@
EE07A45521E24FDD006031C8 /* Localization.swift in Sources */,
EE377EE921F7A76500138385 /* TrxDetailsVC.swift in Sources */,
EEBEBB7B2200DFC000A6BD18 /* ScanVC.swift in Sources */,
EE1876A9221EE0B2004853A7 /* Payment.swift in Sources */,
EE576FFE21CFCC5500433CAB /* AppDelegate.swift in Sources */,
EE94A74C22135B7200882BB1 /* TrxDetailsVCDelegate.swift in Sources */,
EE377EC021E7D92200138385 /* PinEntryMode.swift in Sources */,
@ -729,6 +736,7 @@
EE377EBE21E68C0B00138385 /* PinVCDelegate.swift in Sources */,
EE1876A52219DD99004853A7 /* AmountVCViewModel.swift in Sources */,
EE57702F21D38BAD00433CAB /* ZWPinDotView.swift in Sources */,
EE1876AB221F4CD0004853A7 /* MemoVCViewModel.swift in Sources */,
EEBEBB7721FF91B700A6BD18 /* RecipientAddressDelegate.swift in Sources */,
EEBEBBA12208D75A00A6BD18 /* MemoVC.swift in Sources */,
EE07A45021E23E43006031C8 /* MainVC.swift in Sources */,

View File

@ -98,3 +98,5 @@
"amount.title.edit" = "Betrag ändern";
"memo.title.edit" = "Memo ändern";

View File

@ -98,3 +98,5 @@
"amount.title.edit" = "Edit Amount";
"memo.title.edit" = "Edit Memo";

View File

@ -0,0 +1,23 @@
//
// Payment.swift
// ZWallet
//
// Created by loj on 21.02.19.
// Copyright © 2019 XMR Systems LLC. All rights reserved.
//
import Foundation
internal protocol PaymentProtocol {
var targetAddress: String? { get set }
var amount: ZecInAtomicUnits? { get set }
var memo: String? { get set }
}
internal class Payment: PaymentProtocol {
var targetAddress: String? = nil
var amount: ZecInAtomicUnits? = nil
var memo: String? = nil
}

View File

@ -19,6 +19,8 @@ internal class SendCoordinator: BaseCoordinator {
private var viewFactory: ViewFactoryProtocol
private var localizer: Localizable
private var payment: PaymentProtocol
internal init(navigationController: UINavigationController,
iocContainer: IocContainerProtocol)
{
@ -27,6 +29,8 @@ internal class SendCoordinator: BaseCoordinator {
self.viewFactory = self.iocContainer.viewFactory
self.localizer = self.iocContainer.localizer
self.payment = Payment()
super.init(navigationController: navigationController)
}
@ -46,16 +50,16 @@ extension SendCoordinator: RecipientAddressDelegate {
}
func recipientAddressVCPasteFromClipboardButtonTouched(sender: RecipientAddressVC) {
#warning("implement")
#warning("implement check and store")
}
func recipientAddressVCEnterManuallyButtonTouched(sender: RecipientAddressVC) {
#warning("implement")
#warning("implement check and store")
let viewModel = AmountVCViewModel(mode: .new,
availableAmount: 2208_000_000_000)
#warning("set correct available amount")
self.showAmountView(withViewModel: viewModel)
self.showAmountView(with: viewModel)
}
func recipientAddressVCBackTouched(sender: RecipientAddressVC) {
@ -78,12 +82,12 @@ extension SendCoordinator: RecipientAddressDelegate {
extension SendCoordinator: ScanVCDelegate {
func scanVCDelegateUriDetected(uri: String, sender: ScanVC) {
#warning("implement")
#warning("implement check and store")
let viewModel = AmountVCViewModel(mode: .new,
availableAmount: 2208_000_000_000)
#warning("set correct available amount")
self.showAmountView(withViewModel: viewModel)
self.showAmountView(with: viewModel)
}
func scanVCDelegateCancelled(sender: ScanVC) {
@ -99,14 +103,13 @@ extension SendCoordinator: AmountVCDelegate {
}
func amountVCDelegateNextButtonTouched(sender: AmountVC, amount: ZecInAtomicUnits) {
#warning("implement")
self.showMemoView()
self.payment.amount = amount
let viewModel = MemoVCViewModel(mode: .new)
self.showMemoView(with: viewModel)
}
func amountVCDelegateDoneButtonTouched(sender: AmountVC, amount: ZecInAtomicUnits) {
#warning("store amount")
self.payment.amount = amount
self.navigationController.popViewController(animated: true)
}
@ -118,7 +121,7 @@ extension SendCoordinator: AmountVCDelegate {
self.delegate?.sendCoordinatorCancelled(coordinator: self)
}
private func showAmountView(withViewModel viewModel: AmountVCViewModel) {
private func showAmountView(with viewModel: AmountVCViewModel) {
let vc = self.viewFactory.getAmountView()
vc.delegate = self
vc.localizer = self.localizer
@ -131,12 +134,17 @@ extension SendCoordinator: AmountVCDelegate {
extension SendCoordinator: MemoVCDelegate {
func memoVCDelegateNextButtonTouched(sender: MemoVC, memo: String?) {
#warning("implement")
self.payment.memo = memo
self.showReviewView()
}
func memoVCDelegateDoneButtonTouched(sender: MemoVC, memo: String?) {
self.payment.memo = memo
self.navigationController.popViewController(animated: true)
}
func memoVCDelegateBackTouched(sender: MemoVC) {
self.payment.memo = nil
self.navigationController.popViewController(animated: true)
}
@ -144,11 +152,11 @@ extension SendCoordinator: MemoVCDelegate {
self.delegate?.sendCoordinatorCancelled(coordinator: self)
}
private func showMemoView() {
private func showMemoView(with viewModel: MemoVCViewModel) {
let vc = self.viewFactory.getMemoVC()
vc.delegate = self
vc.localizer = self.localizer
vc.memo = "22of8.ch"
vc.viewModel = viewModel
self.navigationController.pushViewController(vc, animated: true)
}
}
@ -169,12 +177,10 @@ extension SendCoordinator: ReviewVCDelegate {
}
func reviewVCDelegateChangeAmountTouched(sender: ReviewVC) {
#warning("implement")
let viewModel = AmountVCViewModel(mode: .edit(amount: 222888),
let viewModel = AmountVCViewModel(mode: .edit(amount: self.payment.amount ?? 0),
availableAmount: 2208_000_000_000)
#warning("set correct amounts")
self.showAmountView(withViewModel: viewModel)
self.showAmountView(with: viewModel)
}
func reviewVCDelegateChangeReceivingAddressTouched(sender: ReviewVC) {
@ -184,9 +190,8 @@ extension SendCoordinator: ReviewVCDelegate {
}
func reviewVCDelegateChangeMemoTouched(sender: ReviewVC) {
#warning("implement")
self.showMemoView()
let viewModel = MemoVCViewModel(mode: .edit(memo: self.payment.memo))
self.showMemoView(with: viewModel)
}
private func showReviewView() {
@ -195,10 +200,10 @@ extension SendCoordinator: ReviewVCDelegate {
vc.localizer = self.localizer
#warning("set view model")
vc.viewModel = ReviewViewModel(amount: 2208_000_000_000_000,
vc.viewModel = ReviewViewModel(amount: self.payment.amount ?? 0,
fiatAmount: "22.08 CHF",
receivingAddress: "reveiver's address here",
memo: "some memo for this transaction comes here and may be longer")
receivingAddress: self.payment.targetAddress ?? "",
memo: self.payment.memo)
self.navigationController.pushViewController(vc, animated: true)
}

View File

@ -19,10 +19,18 @@ class MemoVC: UIViewController {
public weak var delegate: MemoVCDelegate?
public weak var localizer: Localizable?
public var memo: String?
public var viewModel: MemoVCViewModel?
@IBAction func nextButtonTouched() {
self.delegate?.memoVCDelegateNextButtonTouched(sender: self, memo: self.memoTextField.text)
let memo = self.memoTextField.text
guard let mode = self.viewModel?.mode else { return }
switch mode {
case .new:
self.delegate?.memoVCDelegateNextButtonTouched(sender: self, memo: memo)
case .edit(_):
self.delegate?.memoVCDelegateDoneButtonTouched(sender: self, memo: memo)
}
}
@IBAction func backButtonTouched() {
@ -59,18 +67,28 @@ class MemoVC: UIViewController {
guard let localizer = self.localizer else { return }
self.titleLabel.text = localizer.localized("memo.title")
self.memoTextField.text = self.memo
self.memoTextField.placeholder = localizer.localized("memo.memo.placeholder")
self.nextButton.setTitle(localizer.localized("memo.next"), for: .normal)
if let mode = self.viewModel?.mode {
switch mode {
case .new:
self.titleLabel.text = localizer.localized("memo.title")
self.memoTextField.text = ""
self.nextButton.setTitle(localizer.localized("memo.next"), for: .normal)
self.backButton.isHidden = false
self.progressBar.isHidden = false
case .edit(let memo):
self.titleLabel.text = localizer.localized("memo.title.edit")
self.memoTextField.text = memo
self.nextButton.setTitle(localizer.localized("global.done"), for: .normal)
self.backButton.isHidden = true
self.progressBar.isHidden = true
}
}
}
@objc
private func memoTextFieldDidChange(_ sender: Any) {
self.memo = self.memoTextField.text
if let memo = self.memo {
print(memo)
}
#warning("how long does a memo allowed to be?")
}
}

View File

@ -11,6 +11,7 @@ import Foundation
internal protocol MemoVCDelegate: class {
func memoVCDelegateNextButtonTouched(sender: MemoVC, memo: String?)
func memoVCDelegateDoneButtonTouched(sender: MemoVC, memo: String?)
func memoVCDelegateBackTouched(sender: MemoVC)
func memoVCDelegateCancelTouched(sender: MemoVC)
}

View File

@ -0,0 +1,25 @@
//
// MemoVCViewModel.swift
// ZWallet
//
// Created by loj on 21.02.19.
// Copyright © 2019 XMR Systems LLC. All rights reserved.
//
import Foundation
internal enum MemoVCMode {
case new
case edit(memo: String?)
}
internal struct MemoVCViewModel {
let mode: MemoVCMode
init(mode: MemoVCMode)
{
self.mode = mode
}
}

View File

@ -13,5 +13,5 @@ internal struct ReviewViewModel {
let amount: ZecInAtomicUnits
let fiatAmount: String
let receivingAddress: String
let memo: String
let memo: String?
}