From 896d81739324cf6389013f6895731dd22f8c7fb4 Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Sun, 22 Apr 2018 11:14:03 +0800 Subject: [PATCH] Similar to transfer: In sell flow, allow user to set expiry time to earlier time and only check when user hits Next. More user friendly --- Trust/Extensions/Date.swift | 4 ++++ Trust/Localization/en.lproj/Localizable.strings | 1 + .../SetSellTicketsExpiryDateViewController.swift | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Trust/Extensions/Date.swift b/Trust/Extensions/Date.swift index 646197695..ebf7db111 100644 --- a/Trust/Extensions/Date.swift +++ b/Trust/Extensions/Date.swift @@ -35,6 +35,10 @@ public extension Date { return foundFormatter! } + public static var yesterday: Date { + return Calendar.current.date(byAdding: .day, value: -1, to: Date())! + } + public static var tomorrow: Date { return Calendar.current.date(byAdding: .day, value: 1, to: Date())! } diff --git a/Trust/Localization/en.lproj/Localizable.strings b/Trust/Localization/en.lproj/Localizable.strings index aefc719f4..3abdaad59 100644 --- a/Trust/Localization/en.lproj/Localizable.strings +++ b/Trust/Localization/en.lproj/Localizable.strings @@ -204,6 +204,7 @@ "a.wallet.ticketToken.sell.noteLabel.title" = "Before the link expires, anyone with the MagicLink can purchase your tickets with one click"; "a.wallet.ticketToken.sell.linkExpiryDate.title" = "LINK EXPIRY DATE"; "a.wallet.ticketToken.sell.linkExpiryTime.title" = "LINK EXPIRY TIME"; +"a.wallet.ticketToken.sell.linkExpiryTime.atLeastNow.title" = "Please select a date in the future"; "a.wallet.ticketToken.sell.totalCost.title" = "Total Cost:"; "a.wallet.ticketToken.sell.confirm.title" = "Confirm Sale?"; "a.wallet.ticketToken.sell.confirm.subtitle" = "Generate Sale Link"; diff --git a/Trust/Sell/ViewControllers/SetSellTicketsExpiryDateViewController.swift b/Trust/Sell/ViewControllers/SetSellTicketsExpiryDateViewController.swift index 20c4cab8e..d3a93876d 100644 --- a/Trust/Sell/ViewControllers/SetSellTicketsExpiryDateViewController.swift +++ b/Trust/Sell/ViewControllers/SetSellTicketsExpiryDateViewController.swift @@ -126,7 +126,7 @@ class SetSellTicketsExpiryDateViewController: UIViewController { datePicker.isHidden = true timePicker.datePickerMode = .time - timePicker.minimumDate = Date() + timePicker.minimumDate = Date.yesterday timePicker.addTarget(self, action: #selector(timePickerValueChanged), for: .valueChanged) timePicker.isHidden = true @@ -229,8 +229,18 @@ class SetSellTicketsExpiryDateViewController: UIViewController { fatalError("init(coder:) has not been implemented") } - @objc - func nextButtonTapped() { + @objc func nextButtonTapped() { + let expiryDate = linkExpiryDate() + guard expiryDate > Date() else { + UIAlertController.alert(title: "", + message: R.string.localizable.aWalletTicketTokenSellLinkExpiryTimeAtLeastNowTitle(), + alertButtonTitles: [R.string.localizable.oK()], + alertButtonStyles: [.cancel], + viewController: self, + completion: nil) + return + } + //TODO be good if we check if date chosen is not too far into the future. Example 1 year ahead. Common error? delegate?.didSetSellTicketsExpiryDate(ticketHolder: ticketHolder, linkExpiryDate: linkExpiryDate(), ethCost: ethCost, dollarCost: dollarCost, in: self) }