Skip to content

Commit

Permalink
Crash in case order is null illegally
Browse files Browse the repository at this point in the history
  • Loading branch information
samiuelson committed Dec 11, 2024
1 parent 1c2ddee commit 8b21898
Showing 1 changed file with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,9 @@ class WooPosTotalsViewModel @Inject constructor(
private suspend fun retryPaymentCollectionFromScratch() {
cancelPaymentAction()
val order = totalsRepository.getOrderById(dataState.value.orderId)
if (order == null) {
returnToCart()
} else {
uiState.value = buildWooPosTotalsViewState(order)
collectPayment()
}
checkNotNull(order)
uiState.value = buildWooPosTotalsViewState(order)
collectPayment()
}

private fun collectPayment() {
Expand Down Expand Up @@ -222,7 +219,7 @@ class WooPosTotalsViewModel @Inject constructor(
when (paymentState) {
is CardReaderPaymentState.CollectingPayment,
is CardReaderPaymentState.LoadingData ->
handlePaymentState(paymentState as CardReaderPaymentState)
handlePaymentState(paymentState)

is CardReaderPaymentState.ProcessingPayment,
is CardReaderPaymentState.PaymentCapturing,
Expand All @@ -233,9 +230,7 @@ class WooPosTotalsViewModel @Inject constructor(

is CardReaderPaymentState.PaymentSuccessful -> {
uiState.value =
PaymentSuccess(
orderTotalText = paymentState.amountWithCurrencyLabel
)
PaymentSuccess(orderTotalText = paymentState.amountWithCurrencyLabel)
childrenToParentEventSender.sendToParent(ChildToParentEvent.OrderSuccessfullyPaid)
}

Expand Down Expand Up @@ -263,13 +258,9 @@ class WooPosTotalsViewModel @Inject constructor(
)
} else {
val order = totalsRepository.getOrderById(dataState.value.orderId)
if (order == null) {
returnToCart()
} else {
uiState.value =
buildWooPosTotalsViewState(order, paymentState)
childrenToParentEventSender.sendToParent(ChildToParentEvent.PaymentCollecting)
}
checkNotNull(order)
uiState.value = buildWooPosTotalsViewState(order, paymentState)
childrenToParentEventSender.sendToParent(ChildToParentEvent.PaymentCollecting)
}
}

Expand Down

0 comments on commit 8b21898

Please sign in to comment.