Skip to content

Commit 0e4f0f5

Browse files
authored
Merge pull request #7113 from woocommerce/issue/7112-fix-refunds-crash
Hotfix: Add condition check for "paid" cell index value
2 parents 6c4ca51 + 6f5095e commit 0e4f0f5

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

WooCommerce/Classes/ViewModels/Order Details/OrderDetailsDataSource.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ final class OrderDetailsDataSource: NSObject {
7171
!isEligibleForCardPresentPayment
7272
}
7373

74+
/// Whether the row for amount paid should be visible.
75+
///
76+
private var shouldShowCustomerPaidRow: Bool {
77+
order.datePaid != nil
78+
}
79+
7480
/// Whether the option to re-create shipping labels should be visible.
7581
///
7682
var shouldAllowRecreatingShippingLabels: Bool {
@@ -515,7 +521,7 @@ private extension OrderDetailsDataSource {
515521
}
516522

517523
private func configureRefund(cell: TwoColumnHeadlineFootnoteTableViewCell, at indexPath: IndexPath) {
518-
let index = indexPath.row - Constants.paymentCell - Constants.paidByCustomerCell
524+
let index = indexPath.row - Constants.paymentCell - Constants.paidByCustomerCell(isDisplayed: shouldShowCustomerPaidRow)
519525
let condensedRefund = condensedRefunds[index]
520526
let refund = lookUpRefund(by: condensedRefund.refundID)
521527
let paymentViewModel = OrderPaymentDetailsViewModel(order: order, refund: refund)
@@ -1030,8 +1036,6 @@ extension OrderDetailsDataSource {
10301036
let payment: Section = {
10311037
var rows: [Row] = [.payment]
10321038

1033-
let shouldShowCustomerPaidRow = order.datePaid != nil
1034-
10351039
if shouldShowCustomerPaidRow {
10361040
rows.append(.customerPaid)
10371041
}
@@ -1109,7 +1113,7 @@ extension OrderDetailsDataSource {
11091113
}
11101114

11111115
func refund(at indexPath: IndexPath) -> Refund? {
1112-
let index = indexPath.row - Constants.paymentCell - Constants.paidByCustomerCell
1116+
let index = indexPath.row - Constants.paymentCell - Constants.paidByCustomerCell(isDisplayed: shouldShowCustomerPaidRow)
11131117
let condensedRefund = condensedRefunds[index]
11141118
let refund = refunds.first { $0.refundID == condensedRefund.refundID }
11151119

@@ -1501,10 +1505,15 @@ extension OrderDetailsDataSource {
15011505
case editShippingAddress
15021506
}
15031507

1504-
struct Constants {
1508+
enum Constants {
15051509
static let addOrderCell = 1
15061510
static let paymentCell = 1
1507-
static let paidByCustomerCell = 1
1511+
1512+
/// Input value required because cell is displayed conditionally
1513+
///
1514+
static func paidByCustomerCell(isDisplayed: Bool) -> Int {
1515+
isDisplayed ? 1 : 0
1516+
}
15081517
}
15091518
}
15101519

0 commit comments

Comments
 (0)