@@ -25,6 +25,12 @@ struct PointOfSaleCollectCashView: View {
2525 String . localizedStringWithFormat ( Localization . backNavigationSubtitle, orderTotal)
2626 }
2727
28+ private var isButtonEnabled : Bool {
29+ viewHelper. isPaymentButtonEnabled ( orderTotal: orderTotal,
30+ textFieldAmountInput: textFieldAmountInput,
31+ isLoading: isLoading)
32+ }
33+
2834 @StateObject private var textFieldViewModel = FormattableAmountTextFieldViewModel ( size: . extraLarge,
2935 locale: Locale . autoupdatingCurrent,
3036 storeCurrencySettings: ServiceLocator . currencySettings,
@@ -89,7 +95,7 @@ struct PointOfSaleCollectCashView: View {
8995 . buttonStyle ( POSFilledButtonStyle ( size: . normal, isLoading: isLoading) )
9096 . frame ( maxWidth: . infinity)
9197 . dynamicTypeSize ( ... DynamicTypeSize . accessibility1)
92- . disabled ( isLoading )
98+ . disabled ( !isButtonEnabled )
9399 }
94100 . padding ( [ . horizontal] )
95101 . padding ( . bottom, max ( keyboardFrame. height - geometry. safeAreaInsets. bottom,
@@ -110,6 +116,9 @@ struct PointOfSaleCollectCashView: View {
110116 }
111117 }
112118 . frame ( maxWidth: . infinity, maxHeight: . infinity)
119+ . onAppear {
120+ prefillOrderTotal ( )
121+ }
113122 }
114123
115124 private func markComplete( ) async throws {
@@ -122,9 +131,6 @@ struct PointOfSaleCollectCashView: View {
122131private extension PointOfSaleCollectCashView {
123132 private func submitCashAmount( ) async {
124133 ServiceLocator . analytics. track ( . pointOfSaleCashPaymentTapped)
125- guard validateAmountOnSubmit ( ) else {
126- return
127- }
128134 isLoading = true
129135 do {
130136 try await markComplete ( )
@@ -141,14 +147,12 @@ private extension PointOfSaleCollectCashView {
141147 textFieldAmountInput: textFieldAmountInput)
142148 }
143149
144- private func validateAmountOnSubmit( ) -> Bool {
145- viewHelper. validateAmountOnSubmit (
146- orderTotal: orderTotal,
147- textFieldAmountInput: textFieldAmountInput,
148- onError: { error in
149- errorMessage = error
150- } )
150+ private func prefillOrderTotal( ) {
151+ if let orderDecimal = viewHelper. parseCurrency ( orderTotal) {
152+ textFieldViewModel. presetAmount ( orderDecimal)
151153 }
154+ isTextFieldFocused = true
155+ }
152156}
153157
154158private extension PointOfSaleCollectCashView {
0 commit comments