From 5104802b3b2e0a62a267882760f71a14ff0da75c Mon Sep 17 00:00:00 2001 From: shamim-emon Date: Sat, 14 Sep 2024 22:00:07 +0600 Subject: [PATCH] Fix for : EditTransactionViewModel.kt:859:24: This condition is too complex (4). Defined complexity threshold for conditions is set to '4' [ComplexCondition] --- .../ivy/transaction/EditTransactionViewModel.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/screen/edit-transaction/src/main/java/com/ivy/transaction/EditTransactionViewModel.kt b/screen/edit-transaction/src/main/java/com/ivy/transaction/EditTransactionViewModel.kt index 775eec5f37..6574d4d36e 100644 --- a/screen/edit-transaction/src/main/java/com/ivy/transaction/EditTransactionViewModel.kt +++ b/screen/edit-transaction/src/main/java/com/ivy/transaction/EditTransactionViewModel.kt @@ -856,9 +856,10 @@ class EditTransactionViewModel @Inject constructor( } val exRate = exchangeRate - ?: if ( - customExchangeRateState.showCard && toAccCurrencyCode == customExchangeRateState.toCurrencyCode && - fromAccCurrencyCode == customExchangeRateState.fromCurrencyCode && !resetRate + ?: if (isCustomExchangeRateCurrencyCodeMatchingWithSourceAndDestinationAccountCurrencyCode( + toAccCurrencyCode = toAccCurrencyCode, + fromAccCurrencyCode = fromAccCurrencyCode + ) && !resetRate ) { customExchangeRateState.exchangeRate } else { @@ -887,6 +888,15 @@ class EditTransactionViewModel @Inject constructor( } } + private fun isCustomExchangeRateCurrencyCodeMatchingWithSourceAndDestinationAccountCurrencyCode( + toAccCurrencyCode: String, + fromAccCurrencyCode: String + ): Boolean { + return customExchangeRateState.showCard && + toAccCurrencyCode == customExchangeRateState.toCurrencyCode && + fromAccCurrencyCode == customExchangeRateState.fromCurrencyCode + } + private fun saveIfEditMode(closeScreen: Boolean = false) { if (editMode) { hasChanges = true