From 69775af939c8b01d81ff30af8ac6d4132ad80caf Mon Sep 17 00:00:00 2001 From: Vishwa Raghavendra K S Date: Mon, 25 Apr 2022 14:12:38 +0530 Subject: [PATCH] Todo-Fix: CustomExchangeRate --- .../ui/edit/EditTransactionViewModel.kt | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt index f8c8fb2107..d6e32d5fbd 100644 --- a/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/edit/EditTransactionViewModel.kt @@ -232,22 +232,20 @@ class EditTransactionViewModel @Inject constructor( updateCurrency(account = selectedAccount) - //TODO: Fix that -// transaction.toAmount?.let { -// val exchangeRate = it / transaction.amount -// val toAccountCurrency = -// _accounts.value?.find { acc -> acc.id == transaction.toAccountId }?.currency -// _customExchangeRateState.value = -// _customExchangeRateState.value.copy( -// showCard = toAccountCurrency != account.value?.currency, -// exchangeRate = exchangeRate, -// convertedAmount = it, -// toCurrencyCode = toAccountCurrency, -// fromCurrencyCode = currency.value -// ) -// } ?: let { -// _customExchangeRateState.value = CustomExchangeRateState() -// } + _customExchangeRateState.value = if (transaction.toAccountId == null) + CustomExchangeRateState() + else { + val exchangeRate = transaction.toAmount / transaction.amount + val toAccountCurrency = + _accounts.value.find { acc -> acc.id == transaction.toAccountId }?.currency + CustomExchangeRateState( + showCard = toAccountCurrency != account.value?.currency, + exchangeRate = exchangeRate.toDouble(), + convertedAmount = transaction.toAmount.toDouble(), + toCurrencyCode = toAccountCurrency, + fromCurrencyCode = currency.value + ) + } _displayLoanHelper.value = getDisplayLoanHelper(trans = transaction) }