Skip to content

Commit 0340eb2

Browse files
authored
Merge pull request #8312 from woocommerce/issue/8082-built-in-reader-configuration-update-alerts
[Mobile Payments] Built-in reader configuration update alerts
2 parents d3e873b + 0af2f5e commit 0340eb2

File tree

5 files changed

+145
-20
lines changed

5 files changed

+145
-20
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import UIKit
2+
3+
/// Modal presented when a firmware update is being installed
4+
///
5+
final class CardPresentModalBuiltInConfigurationProgress: CardPresentPaymentsModalViewModel, CardPresentModalProgressDisplaying {
6+
/// Called when cancel button is tapped
7+
private let cancelAction: (() -> Void)?
8+
9+
let textMode: PaymentsModalTextMode = .fullInfo
10+
let actionsMode: PaymentsModalActionsMode
11+
12+
var topSubtitle: String? = nil
13+
14+
var progress: Float
15+
16+
let primaryButtonTitle: String? = nil
17+
18+
let secondaryButtonTitle: String? = Localization.cancel
19+
20+
let auxiliaryButtonTitle: String? = nil
21+
22+
var titleComplete: String
23+
24+
var titleInProgress: String
25+
26+
var messageComplete: String?
27+
28+
var messageInProgress: String?
29+
30+
var accessibilityLabel: String? {
31+
Localization.title
32+
}
33+
34+
init(progress: Float, cancel: (() -> Void)?) {
35+
self.progress = progress
36+
self.cancelAction = cancel
37+
38+
titleComplete = Localization.titleComplete
39+
titleInProgress = Localization.title
40+
messageComplete = Localization.messageComplete
41+
messageInProgress = Localization.message
42+
actionsMode = cancel != nil ? .secondaryOnlyAction : .none
43+
}
44+
45+
func didTapPrimaryButton(in viewController: UIViewController?) {}
46+
47+
func didTapSecondaryButton(in viewController: UIViewController?) {
48+
cancelAction?()
49+
}
50+
51+
func didTapAuxiliaryButton(in viewController: UIViewController?) {}
52+
}
53+
54+
private extension CardPresentModalBuiltInConfigurationProgress {
55+
enum Localization {
56+
static let title = NSLocalizedString(
57+
"Configuring iPhone",
58+
comment: "Dialog title that displays when iPhone configuration is being updated for use as a card reader"
59+
)
60+
61+
static let titleComplete = NSLocalizedString(
62+
"Configuration updated",
63+
comment: "Dialog title that displays when a configuration update just finished installing"
64+
)
65+
66+
static let message = NSLocalizedString(
67+
"Your iPhone needs to be configured to collect payments.",
68+
comment: "Label that displays when a configuration update is happening"
69+
)
70+
71+
static let messageComplete = NSLocalizedString(
72+
"Your phone will be ready to collect payments in a moment...",
73+
comment: "Dialog message that displays when a configuration update just finished installing"
74+
)
75+
76+
static let cancel = NSLocalizedString(
77+
"Cancel",
78+
comment: "Label for a cancel button"
79+
)
80+
}
81+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import UIKit
2+
3+
protocol CardPresentModalProgressDisplaying: CardPresentPaymentsModalViewModel {
4+
var progress: Float { get }
5+
var isComplete: Bool { get }
6+
var titleComplete: String { get }
7+
var titleInProgress: String { get }
8+
var messageComplete: String? { get }
9+
var messageInProgress: String? { get }
10+
}
11+
12+
extension CardPresentModalProgressDisplaying {
13+
var image: UIImage {
14+
.softwareUpdateProgress(progress: CGFloat(progress))
15+
}
16+
17+
var isComplete: Bool {
18+
progress == 1
19+
}
20+
21+
var topTitle: String {
22+
isComplete ? titleComplete : titleInProgress
23+
}
24+
25+
var bottomTitle: String? {
26+
String(format: CardPresentModalProgressDisplayingLocalization.percentComplete, 100 * progress)
27+
}
28+
29+
var bottomSubtitle: String? {
30+
isComplete ? messageComplete : messageInProgress
31+
}
32+
}
33+
34+
fileprivate enum CardPresentModalProgressDisplayingLocalization {
35+
static let percentComplete = NSLocalizedString(
36+
"%.0f%% complete",
37+
comment: "Label that describes the completed progress of an update being installed (e.g. 15% complete). Keep the %.0f%% exactly as is"
38+
)
39+
}

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalUpdateProgress.swift

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,45 @@ import UIKit
22

33
/// Modal presented when a firmware update is being installed
44
///
5-
final class CardPresentModalUpdateProgress: CardPresentPaymentsModalViewModel {
5+
final class CardPresentModalUpdateProgress: CardPresentPaymentsModalViewModel, CardPresentModalProgressDisplaying {
66
/// Called when cancel button is tapped
77
private let cancelAction: (() -> Void)?
88

99
let textMode: PaymentsModalTextMode = .fullInfo
1010
let actionsMode: PaymentsModalActionsMode
1111

12-
var topTitle: String
13-
1412
var topSubtitle: String? = nil
1513

16-
let image: UIImage
14+
var progress: Float
1715

1816
let primaryButtonTitle: String? = nil
1917

2018
let secondaryButtonTitle: String? = Localization.cancel
2119

2220
let auxiliaryButtonTitle: String? = nil
2321

24-
let bottomTitle: String?
22+
var titleComplete: String
23+
24+
var titleInProgress: String
2525

26-
var bottomSubtitle: String? = nil
26+
var messageComplete: String?
27+
28+
var messageInProgress: String?
2729

2830
var accessibilityLabel: String? {
2931
Localization.title
3032
}
3133

3234
init(requiredUpdate: Bool, progress: Float, cancel: (() -> Void)?) {
35+
self.progress = progress
3336
self.cancelAction = cancel
37+
actionsMode = cancel != nil ? .secondaryOnlyAction : .none
38+
titleComplete = Localization.titleComplete
39+
titleInProgress = Localization.title
3440

35-
let isComplete = progress == 1
36-
topTitle = isComplete ? Localization.titleComplete : Localization.title
37-
image = .softwareUpdateProgress(progress: CGFloat(progress))
38-
bottomTitle = String(format: Localization.percentComplete, 100 * progress)
3941
if !isComplete {
40-
bottomSubtitle = requiredUpdate ? Localization.messageRequired : Localization.messageOptional
42+
messageInProgress = requiredUpdate ? Localization.messageRequired : Localization.messageOptional
4143
}
42-
actionsMode = cancel != nil ? .secondaryOnlyAction : .none
4344
}
4445

4546
func didTapPrimaryButton(in viewController: UIViewController?) {}
@@ -63,12 +64,6 @@ private extension CardPresentModalUpdateProgress {
6364
comment: "Dialog title that displays when a software update just finished installing"
6465
)
6566

66-
67-
static let percentComplete = NSLocalizedString(
68-
"%.0f%% complete",
69-
comment: "Label that describes the completed progress of a software update being installed (e.g. 15% complete). Keep the %.0f%% exactly as is"
70-
)
71-
7267
static let messageRequired = NSLocalizedString(
7368
"Your card reader software needs to be updated to collect payments. Cancelling will block your reader connection.",
7469
comment: "Label that displays when a mandatory software update is happening"

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/BuiltInReaderConnectionAlertsProvider.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ struct BuiltInReaderConnectionAlertsProvider: CardReaderConnectionAlertsProvidin
3939
return CardPresentModalUpdateFailedNonRetryable(close: close)
4040
}
4141
}
42-
func updateProgress(requiredUpdate: Bool, progress: Float,
42+
43+
func updateProgress(requiredUpdate: Bool,
44+
progress: Float,
4345
cancel: (() -> Void)?) -> CardPresentPaymentsModalViewModel {
44-
CardPresentModalUpdateProgress(requiredUpdate: requiredUpdate, progress: progress, cancel: cancel)
46+
CardPresentModalBuiltInConfigurationProgress(progress: progress, cancel: cancel)
4547
}
4648
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@
500500
03E471C4293A1F8D001A58AD /* BuiltInReaderConnectionAlertsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E471C3293A1F8D001A58AD /* BuiltInReaderConnectionAlertsProvider.swift */; };
501501
03E471C6293A2E95001A58AD /* CardPresentModalBuiltInReaderCheckingDeviceSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E471C5293A2E95001A58AD /* CardPresentModalBuiltInReaderCheckingDeviceSupport.swift */; };
502502
03E471C8293A3076001A58AD /* CardPresentModalBuiltInConnectingToReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E471C7293A3075001A58AD /* CardPresentModalBuiltInConnectingToReader.swift */; };
503+
03E471CA293E0A30001A58AD /* CardPresentModalBuiltInConfigurationProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E471C9293E0A2F001A58AD /* CardPresentModalBuiltInConfigurationProgress.swift */; };
504+
03E471CC293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E471CB293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift */; };
503505
03EF24FA28BF5D21006A033E /* InPersonPaymentsCashOnDeliveryToggleRowViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EF24F928BF5D21006A033E /* InPersonPaymentsCashOnDeliveryToggleRowViewModel.swift */; };
504506
03EF24FC28BF996F006A033E /* InPersonPaymentsCashOnDeliveryPaymentGatewayHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EF24FB28BF996F006A033E /* InPersonPaymentsCashOnDeliveryPaymentGatewayHelpers.swift */; };
505507
03EF24FE28C0B356006A033E /* CardPresentPaymentsPlugin+CashOnDelivery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EF24FD28C0B356006A033E /* CardPresentPaymentsPlugin+CashOnDelivery.swift */; };
@@ -2511,6 +2513,8 @@
25112513
03E471C3293A1F8D001A58AD /* BuiltInReaderConnectionAlertsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuiltInReaderConnectionAlertsProvider.swift; sourceTree = "<group>"; };
25122514
03E471C5293A2E95001A58AD /* CardPresentModalBuiltInReaderCheckingDeviceSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardPresentModalBuiltInReaderCheckingDeviceSupport.swift; sourceTree = "<group>"; };
25132515
03E471C7293A3075001A58AD /* CardPresentModalBuiltInConnectingToReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardPresentModalBuiltInConnectingToReader.swift; sourceTree = "<group>"; };
2516+
03E471C9293E0A2F001A58AD /* CardPresentModalBuiltInConfigurationProgress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardPresentModalBuiltInConfigurationProgress.swift; sourceTree = "<group>"; };
2517+
03E471CB293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentModalProgressDisplaying.swift; sourceTree = "<group>"; };
25142518
03EF24F928BF5D21006A033E /* InPersonPaymentsCashOnDeliveryToggleRowViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InPersonPaymentsCashOnDeliveryToggleRowViewModel.swift; sourceTree = "<group>"; };
25152519
03EF24FB28BF996F006A033E /* InPersonPaymentsCashOnDeliveryPaymentGatewayHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InPersonPaymentsCashOnDeliveryPaymentGatewayHelpers.swift; sourceTree = "<group>"; };
25162520
03EF24FD28C0B356006A033E /* CardPresentPaymentsPlugin+CashOnDelivery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CardPresentPaymentsPlugin+CashOnDelivery.swift"; sourceTree = "<group>"; };
@@ -8563,6 +8567,8 @@
85638567
children = (
85648568
D8815AE626383FD600EDAD62 /* CardPresentPaymentsModalViewModel.swift */,
85658569
03E471C5293A2E95001A58AD /* CardPresentModalBuiltInReaderCheckingDeviceSupport.swift */,
8570+
03E471C9293E0A2F001A58AD /* CardPresentModalBuiltInConfigurationProgress.swift */,
8571+
03E471CB293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift */,
85668572
03E471C7293A3075001A58AD /* CardPresentModalBuiltInConnectingToReader.swift */,
85678573
311237ED2714DA240033C44E /* CardPresentModalDisplayMessage.swift */,
85688574
D8815B0026385E3F00EDAD62 /* CardPresentModalTapCard.swift */,
@@ -10000,6 +10006,7 @@
1000010006
E138D4FC269EEAFE006EA5C6 /* InPersonPaymentsViewModel.swift in Sources */,
1000110007
039D948F276113490044EF38 /* UIView+SuperviewConstraints.swift in Sources */,
1000210008
D8736B5322EF4F5900A14A29 /* NotificationsBadgeController.swift in Sources */,
10009+
03E471CC293E0FB8001A58AD /* CardPresentModalProgressDisplaying.swift in Sources */,
1000310010
B541B220218A007C008FE7C1 /* NSMutableParagraphStyle+Helpers.swift in Sources */,
1000410011
45AE582C230D9D35001901E3 /* OrderNoteHeaderTableViewCell.swift in Sources */,
1000510012
6832C7CA26DA5C4500BA4088 /* LabeledTextViewTableViewCell.swift in Sources */,
@@ -10020,6 +10027,7 @@
1002010027
E1325EFB28FD544E00EC9B2A /* InAppPurchasesDebugView.swift in Sources */,
1002110028
74460D4022289B7600D7316A /* Coordinator.swift in Sources */,
1002210029
B57C743D20F5493300EEFC87 /* AccountHeaderView.swift in Sources */,
10030+
03E471CA293E0A30001A58AD /* CardPresentModalBuiltInConfigurationProgress.swift in Sources */,
1002310031
31AD0B1126E9575F000B6391 /* CardPresentModalConnectingFailed.swift in Sources */,
1002410032
576EA39425264C9B00AFC0B3 /* RefundConfirmationViewModel.swift in Sources */,
1002510033
DEC51B00276AEE91009F3DF4 /* SystemStatusReportViewModel.swift in Sources */,

0 commit comments

Comments
 (0)