-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMobileMoneyChargeView.swift
More file actions
69 lines (61 loc) · 2.7 KB
/
Copy pathMobileMoneyChargeView.swift
File metadata and controls
69 lines (61 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import SwiftUI
@available(iOS 14.0, *)
struct MobileMoneyChargeView: View {
@StateObject
var viewModel: MobileMoneyChargeViewModel
private let phoneNumberMaximumLength = 15
@State private var showPhoneNumberError = false
init(
chargeCardContainer: ChargeContainer,
transactionDetails: VerifyAccessCode,
provider: MobileMoneyChannel) {
self._viewModel = StateObject(wrappedValue: MobileMoneyChargeViewModel(
chargeCardContainer: chargeCardContainer,
transactionDetails: transactionDetails,
provider: provider))
}
var body: some View {
switch viewModel.transactionState {
case .loading(let message):
LoadingView(message: message)
case .error(let chargeError):
ErrorView(message: chargeError.message,
buttonText: "Try again",
buttonAction: viewModel.restartMobileMoneyPayment)
case .fatalError(let error):
ErrorView(message: error.message,
automaticallyDismissWith: .init(
error: error,
transactionReference: viewModel.transactionDetails.reference))
case .processTransaction(let transaction):
MobileMoneyProcessingView(container: viewModel,
mobileMoneyTransaction: transaction)
case .countdown:
VStack(spacing: .triplePadding) {
Text("Please enter your mobile money number to begin this payment")
.font(.body16M)
.foregroundColor(.stackBlue)
.multilineTextAlignment(.center)
FormInput(title: "Pay \(viewModel.transactionDetails.amountCurrency.description)",
enabled: viewModel.isValid,
action: viewModel.submitPhoneNumber,
secondaryAction: viewModel.cancelTransaction) {
phoneNumber
}
}
.padding(.doublePadding)
}
}
@ViewBuilder
var phoneNumber: some FormInputItemView {
TextFieldFormInputView(title: "Phone Number",
placeholder: "070 000 0000",
text: $viewModel.phoneNumber,
keyboardType: .phonePad,
maxLength: phoneNumberMaximumLength,
inErrorState: $showPhoneNumberError,
defaultFocused: true,
accessoryView: viewModel.provider.phoneInputAccessory)
.minLength(10, errorMessage: "Invalid Phone Number")
}
}