diff --git a/WooCommerce/Classes/ViewModels/Order Details/OrderDetailsDataSource.swift b/WooCommerce/Classes/ViewModels/Order Details/OrderDetailsDataSource.swift index d3c0c2020ec..d5517598bd6 100644 --- a/WooCommerce/Classes/ViewModels/Order Details/OrderDetailsDataSource.swift +++ b/WooCommerce/Classes/ViewModels/Order Details/OrderDetailsDataSource.swift @@ -71,6 +71,12 @@ final class OrderDetailsDataSource: NSObject { !isEligibleForCardPresentPayment } + /// Whether the row for amount paid should be visible. + /// + private var shouldShowCustomerPaidRow: Bool { + order.datePaid != nil + } + /// Whether the option to re-create shipping labels should be visible. /// var shouldAllowRecreatingShippingLabels: Bool { @@ -515,7 +521,7 @@ private extension OrderDetailsDataSource { } private func configureRefund(cell: TwoColumnHeadlineFootnoteTableViewCell, at indexPath: IndexPath) { - let index = indexPath.row - Constants.paymentCell - Constants.paidByCustomerCell + let index = indexPath.row - Constants.paymentCell - Constants.paidByCustomerCell(isDisplayed: shouldShowCustomerPaidRow) let condensedRefund = condensedRefunds[index] let refund = lookUpRefund(by: condensedRefund.refundID) let paymentViewModel = OrderPaymentDetailsViewModel(order: order, refund: refund) @@ -1030,8 +1036,6 @@ extension OrderDetailsDataSource { let payment: Section = { var rows: [Row] = [.payment] - let shouldShowCustomerPaidRow = order.datePaid != nil - if shouldShowCustomerPaidRow { rows.append(.customerPaid) } @@ -1109,7 +1113,7 @@ extension OrderDetailsDataSource { } func refund(at indexPath: IndexPath) -> Refund? { - let index = indexPath.row - Constants.paymentCell - Constants.paidByCustomerCell + let index = indexPath.row - Constants.paymentCell - Constants.paidByCustomerCell(isDisplayed: shouldShowCustomerPaidRow) let condensedRefund = condensedRefunds[index] let refund = refunds.first { $0.refundID == condensedRefund.refundID } @@ -1501,10 +1505,15 @@ extension OrderDetailsDataSource { case editShippingAddress } - struct Constants { + enum Constants { static let addOrderCell = 1 static let paymentCell = 1 - static let paidByCustomerCell = 1 + + /// Input value required because cell is displayed conditionally + /// + static func paidByCustomerCell(isDisplayed: Bool) -> Int { + isDisplayed ? 1 : 0 + } } }