Skip to content

Commit 1eec56c

Browse files
committed
Use formatted values from order in list and details view
1 parent 50bf66e commit 1eec56c

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

WooCommerce/Classes/POS/Presentation/Orders/PointOfSaleOrderDetailsView.swift

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ struct PointOfSaleOrderDetailsView: View {
1111

1212
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
1313

14-
private let helper = PointOfSaleOrderDetailsViewHelper()
15-
1614
private var shouldShowBackButton: Bool {
1715
horizontalSizeClass == .compact
1816
}
@@ -150,7 +148,8 @@ private extension PointOfSaleOrderDetailsView {
150148
productAttributesView(item.attributes)
151149
}
152150

153-
Text(Localization.quantityLabel(item.quantity.intValue, helper.formatItemPrice(item.price, with: order.currency)))
151+
Text(Localization.quantityLabel(item.quantity.intValue,
152+
item.formattedPrice))
154153
.font(.posBodySmallRegular())
155154
.foregroundStyle(Color.posOnSurfaceVariantHighest)
156155
}
@@ -166,7 +165,7 @@ private extension PointOfSaleOrderDetailsView {
166165

167166
@ViewBuilder
168167
func productTotalView(item: POSOrderItem, order: POSOrder) -> some View {
169-
Text(helper.formatItemTotal(item.total, with: order.currency))
168+
Text(item.formattedTotal)
170169
.font(.posBodyMediumRegular())
171170
.foregroundStyle(Color.posOnSurface)
172171
}
@@ -177,40 +176,35 @@ private extension PointOfSaleOrderDetailsView {
177176
private extension PointOfSaleOrderDetailsView {
178177
@ViewBuilder
179178
func productsSubtotalRow(_ order: POSOrder) -> some View {
180-
if helper.shouldShowProductsSubtotal(for: order) {
181-
totalsRow(
182-
title: Localization.productsLabel,
183-
amount: helper.productsSubtotal(for: order)
184-
)
185-
}
179+
totalsRow(
180+
title: Localization.productsLabel,
181+
amount: order.formattedSubtotal
182+
)
186183
}
187184

188185
@ViewBuilder
189186
func discountTotalRow(_ order: POSOrder) -> some View {
190-
if helper.shouldShowDiscount(for: order),
191-
let discountAmount = helper.formattedDiscountTotal(for: order) {
187+
if let formattedDiscountTotal = order.formattedDiscountTotal {
192188
totalsRow(
193189
title: Localization.discountTotalLabel,
194-
amount: discountAmount
190+
amount: formattedDiscountTotal
195191
)
196192
}
197193
}
198194

199195
@ViewBuilder
200196
func taxTotalRow(_ order: POSOrder) -> some View {
201-
if let taxAmount = helper.formattedTaxTotal(for: order) {
202-
totalsRow(
203-
title: Localization.taxesLabel,
204-
amount: taxAmount
205-
)
206-
}
197+
totalsRow(
198+
title: Localization.taxesLabel,
199+
amount: order.formattedTotalTax
200+
)
207201
}
208202

209203
@ViewBuilder
210204
func mainTotalRow(_ order: POSOrder) -> some View {
211205
totalsRow(
212206
title: Localization.totalLabel,
213-
amount: helper.formattedOrderTotal(for: order),
207+
amount: order.formattedTotal,
214208
titleFont: .posBodyMediumBold
215209
)
216210
}
@@ -220,13 +214,15 @@ private extension PointOfSaleOrderDetailsView {
220214
VStack(alignment: .leading, spacing: POSSpacing.xSmall) {
221215
totalsRow(
222216
title: Localization.paidLabel,
223-
amount: helper.formattedPaidAmount(for: order),
217+
amount: order.formattedPaymentTotal,
224218
titleFont: .posBodyMediumBold
225219
)
226220

227-
Text(order.paymentMethodTitle)
228-
.font(.posBodySmallRegular())
229-
.foregroundStyle(Color.posOnSurfaceVariantHighest)
221+
if order.paymentMethodTitle.isNotEmpty {
222+
Text(order.paymentMethodTitle)
223+
.font(.posBodySmallRegular())
224+
.foregroundStyle(Color.posOnSurfaceVariantHighest)
225+
}
230226
}
231227
}
232228

@@ -237,8 +233,8 @@ private extension PointOfSaleOrderDetailsView {
237233
refundRow(refund: refund, order: order)
238234
}
239235

240-
if helper.shouldShowNetPayment(for: order) {
241-
netPaymentRow(order: order)
236+
if let netAmount = order.formattedNetAmount {
237+
netPaymentRow(netAmount: netAmount)
242238
}
243239
}
244240
}
@@ -248,7 +244,7 @@ private extension PointOfSaleOrderDetailsView {
248244
VStack(alignment: .leading, spacing: POSSpacing.xSmall) {
249245
totalsRow(
250246
title: Localization.refundLabel,
251-
amount: helper.formattedRefundTotal(refund, currency: order.currency),
247+
amount: refund.formattedTotal,
252248
titleFont: .posBodyMediumBold
253249
)
254250

@@ -261,10 +257,10 @@ private extension PointOfSaleOrderDetailsView {
261257
}
262258

263259
@ViewBuilder
264-
func netPaymentRow(order: POSOrder) -> some View {
260+
func netPaymentRow(netAmount: String) -> some View {
265261
totalsRow(
266262
title: Localization.netPaymentLabel,
267-
amount: helper.netPaymentAfterRefunds(for: order),
263+
amount: netAmount,
268264
titleFont: .posBodyMediumBold
269265
)
270266
}

WooCommerce/Classes/POS/Presentation/Orders/PointOfSaleOrderListView.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct PointOfSaleOrderListView: View {
99
@Environment(PointOfSaleOrderListModel.self) private var orderListModel
1010
@StateObject private var infiniteScrollTriggerDeterminer = ThresholdInfiniteScrollTriggerDeterminer()
1111

12-
private var ordersViewState: OrderListState {
12+
private var ordersViewState: POSOrderListState {
1313
orderListModel.ordersController.ordersViewState
1414
}
1515

@@ -122,16 +122,10 @@ private struct OrderRowView: View {
122122
@ScaledMetric private var scale: CGFloat = 1.0
123123
@Environment(\.dynamicTypeSize) var dynamicTypeSize
124124

125-
private let currencyFormatter = CurrencyFormatter(currencySettings: ServiceLocator.currencySettings)
126-
127125
private var minHeight: CGFloat {
128126
min(Constants.orderCardMinHeight * scale, Constants.maximumOrderCardHeight)
129127
}
130128

131-
private var formattedTotal: String {
132-
currencyFormatter.formatAmount(order.total, with: order.currency) ?? ""
133-
}
134-
135129
var body: some View {
136130
HStack(alignment: .center, spacing: POSSpacing.medium) {
137131
VStack(alignment: .leading, spacing: POSSpacing.xSmall) {
@@ -158,7 +152,7 @@ private struct OrderRowView: View {
158152
Spacer()
159153

160154
VStack(alignment: .trailing, spacing: POSSpacing.xSmall) {
161-
Text(formattedTotal)
155+
Text(order.formattedTotal)
162156
.font(.posBodyLargeBold)
163157
.foregroundStyle(Color.posOnSurface)
164158

0 commit comments

Comments
 (0)