Merge pull request #211 from James-Sangalli/fix-sell-ticket-price-screen-per-ticket

Fix: sell ticket price entered is per ticket, wrongly taken as per bundle
pull/213/head
James Sangalli 7 years ago committed by GitHub
commit 11d622eb72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      Trust/Sell/ViewControllers/EnterSellTicketsPriceQuantityViewController.swift

@ -26,6 +26,23 @@ class EnterSellTicketsPriceQuantityViewController: UIViewController {
let nextButton = UIButton(type: .system) let nextButton = UIButton(type: .system)
var viewModel: EnterSellTicketsPriceQuantityViewControllerViewModel! var viewModel: EnterSellTicketsPriceQuantityViewControllerViewModel!
var paymentFlow: PaymentFlow var paymentFlow: PaymentFlow
var totalEthCost: Double {
if let ethCostPerTicket = Double(pricePerTicketField.ethCost) {
let quantity = Double(quantityStepper.value)
return ethCostPerTicket * quantity
} else {
return 0
}
}
var totalDollarCost: Double {
if let dollarCostPerTicket = Double(pricePerTicketField.dollarCost) {
let quantity = Double(quantityStepper.value)
return dollarCostPerTicket * quantity
} else {
return 0
}
}
weak var delegate: EnterSellTicketsPriceQuantityViewControllerDelegate? weak var delegate: EnterSellTicketsPriceQuantityViewControllerDelegate?
init(storage: TokensDataStore, paymentFlow: PaymentFlow) { init(storage: TokensDataStore, paymentFlow: PaymentFlow) {
@ -67,6 +84,7 @@ class EnterSellTicketsPriceQuantityViewController: UIViewController {
quantityStepper.translatesAutoresizingMaskIntoConstraints = false quantityStepper.translatesAutoresizingMaskIntoConstraints = false
quantityStepper.minimumValue = 1 quantityStepper.minimumValue = 1
quantityStepper.value = 1 quantityStepper.value = 1
quantityStepper.addTarget(self, action: #selector(quantityChanged), for: .valueChanged)
let col0 = UIStackView(arrangedSubviews: [ let col0 = UIStackView(arrangedSubviews: [
pricePerTicketLabel, pricePerTicketLabel,
@ -237,7 +255,17 @@ class EnterSellTicketsPriceQuantityViewController: UIViewController {
return return
} }
delegate?.didEnterSellTicketsPriceQuantity(ticketHolder: getTicketHolderFromQuantity(), ethCost: pricePerTicketField.ethCost, dollarCost: pricePerTicketField.dollarCost, in: self) delegate?.didEnterSellTicketsPriceQuantity(ticketHolder: getTicketHolderFromQuantity(), ethCost: String(totalEthCost), dollarCost: String(totalDollarCost), in: self)
}
@objc func quantityChanged() {
updateTotalCostsLabels()
}
private func updateTotalCostsLabels() {
viewModel.ethCost = String(totalEthCost)
viewModel.dollarCost = String(totalDollarCost)
configure(viewModel: viewModel)
} }
@objc func showInfo() { @objc func showInfo() {
@ -342,14 +370,10 @@ class EnterSellTicketsPriceQuantityViewController: UIViewController {
extension EnterSellTicketsPriceQuantityViewController: AmountTextFieldDelegate { extension EnterSellTicketsPriceQuantityViewController: AmountTextFieldDelegate {
func changeAmount(in textField: AmountTextField) { func changeAmount(in textField: AmountTextField) {
viewModel.ethCost = textField.ethCost updateTotalCostsLabels()
viewModel.dollarCost = textField.dollarCost
configure(viewModel: viewModel)
} }
func changeType(in textField: AmountTextField) { func changeType(in textField: AmountTextField) {
viewModel.ethCost = textField.ethCost updateTotalCostsLabels()
viewModel.dollarCost = textField.dollarCost
configure(viewModel: viewModel)
} }
} }

Loading…
Cancel
Save