From 0f6476b1cacd24699acfd7f604fc883af94322ab Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 6 Jun 2024 17:07:45 +0500 Subject: [PATCH 1/2] Updated on 2026-08-14 --- .../common/redux/legacy/LegacyMiddleware.kt | 32 +++++++++++++++++-- .../com/tangem/domain/redux/LegacyAction.kt | 19 ++++++++++- .../presentation/viewmodel/SendViewModel.kt | 22 ++++++++++++- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt index 9ad974cdcd..5b83d8c803 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt @@ -1,12 +1,18 @@ package com.tangem.tap.common.redux.legacy import com.tangem.domain.redux.LegacyAction +import com.tangem.domain.tokens.utils.convertToAmount +import com.tangem.tap.common.extensions.inject import com.tangem.tap.common.feedback.RateCanBeBetterEmail import com.tangem.tap.common.feedback.SendTransactionFailedEmail import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction +import com.tangem.tap.proxy.redux.DaggerGraphState +import com.tangem.tap.scope import com.tangem.tap.store +import kotlinx.coroutines.launch import org.rekotlin.Middleware +import java.math.BigDecimal internal object LegacyMiddleware { val legacyMiddleware: Middleware = { _, _ -> @@ -22,9 +28,29 @@ internal object LegacyMiddleware { ) } is LegacyAction.SendEmailTransactionFailed -> { - store.state.globalState.feedbackManager?.sendEmail( - SendTransactionFailedEmail(action.errorMessage), - ) + if (store.inject(DaggerGraphState::feedbackManagerFeatureToggles).isLocalLogsEnabled) { + store.state.globalState.feedbackManager?.sendEmail( + SendTransactionFailedEmail(action.errorMessage), + ) + } else { + scope.launch { + store.inject(DaggerGraphState::walletManagersFacade) + .getOrCreateWalletManager( + userWalletId = action.userWalletId, + network = action.cryptoCurrency.network, + )?.let { walletManager -> + store.state.globalState.feedbackManager?.infoHolder?.updateOnSendError( + walletManager = walletManager, + amountToSend = action.amount.convertToAmount(action.cryptoCurrency), + feeAmount = action.fee.convertToAmount(action.cryptoCurrency), + destinationAddress = action.destinationAddress, + ) + } + store.state.globalState.feedbackManager?.sendEmail( + SendTransactionFailedEmail(action.errorMessage), + ) + } + } } } next(action) diff --git a/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt b/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt index 826ba5a966..f159059c87 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt @@ -1,7 +1,10 @@ package com.tangem.domain.redux import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.wallets.models.UserWalletId import org.rekotlin.Action +import java.math.BigDecimal sealed interface LegacyAction : Action { @@ -16,6 +19,20 @@ sealed interface LegacyAction : Action { /** * Sending an email to support when sending transaction failed + * + * @param cryptoCurrency current currency + * @param userWalletId selected user wallet id + * @param amount sending amount + * @param fee spending fee + * @param destinationAddress recipient address + * @param errorMessage sending error */ - data class SendEmailTransactionFailed(val errorMessage: String) : LegacyAction + data class SendEmailTransactionFailed( + val cryptoCurrency: CryptoCurrency, + val userWalletId: UserWalletId, + val amount: BigDecimal, + val fee: BigDecimal, + val destinationAddress: String, + val errorMessage: String, + ) : LegacyAction } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt index 61a4828722..8654c0f8f9 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt @@ -541,7 +541,27 @@ internal class SendViewModel @Inject constructor( } override fun onFailedTxEmailClick(errorMessage: String) { - reduxStateHolder.dispatch(LegacyAction.SendEmailTransactionFailed(errorMessage)) + val recipient = uiState.recipientState?.addressTextField?.value ?: return + val feeValue = uiState.feeState?.fee?.amount?.value ?: return + val amountValue = uiState.amountState?.amountTextField?.cryptoAmount?.value ?: return + + val receivingAmount = checkAndCalculateSubtractedAmount( + isAmountSubtractAvailable = isAmountSubtractAvailable, + cryptoCurrencyStatus = cryptoCurrencyStatus, + amountValue = amountValue, + feeValue = feeValue, + reduceAmountBy = uiState.sendState?.reduceAmountBy ?: BigDecimal.ZERO, + ) + reduxStateHolder.dispatch( + LegacyAction.SendEmailTransactionFailed( + cryptoCurrency = cryptoCurrency, + userWalletId = userWalletId, + amount = receivingAmount, + fee = feeValue, + destinationAddress = recipient, + errorMessage = errorMessage, + ), + ) } override fun onTokenDetailsClick(userWalletId: UserWalletId, currency: CryptoCurrency) = From 94b59fcbe35d5b401199313e8c6ba84ee3e5d3a1 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 6 Jun 2024 17:53:12 +0500 Subject: [PATCH 2/2] Updated on 2026-08-14 --- .../common/feedback/AdditionalFeedbackInfo.kt | 10 ++++---- .../common/redux/legacy/LegacyMiddleware.kt | 5 ++-- .../com/tangem/domain/redux/LegacyAction.kt | 6 ++--- .../presentation/viewmodel/SendViewModel.kt | 24 +++++++++++-------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/common/feedback/AdditionalFeedbackInfo.kt b/app/src/main/java/com/tangem/tap/common/feedback/AdditionalFeedbackInfo.kt index 975fb1fb2f..21f7717f88 100644 --- a/app/src/main/java/com/tangem/tap/common/feedback/AdditionalFeedbackInfo.kt +++ b/app/src/main/java/com/tangem/tap/common/feedback/AdditionalFeedbackInfo.kt @@ -89,19 +89,19 @@ class AdditionalFeedbackInfo { fun updateOnSendError( walletManager: WalletManager, - amountToSend: Amount, + amountToSend: Amount?, feeAmount: Amount?, - destinationAddress: String, + destinationAddress: String?, ) { onSendErrorWalletInfo = createEmailWalletInfo(walletManager) - this.destinationAddress = destinationAddress - amount = amountToSend.value?.stripZeroPlainString() ?: "0" + this.destinationAddress = destinationAddress ?: "0" + amount = amountToSend?.value?.stripZeroPlainString() ?: "0" fee = if (feeAmount != null) { feeAmount.value?.stripZeroPlainString() ?: "0" } else { "Unable to receive" } - token = if (amountToSend.type is AmountType.Token) amountToSend.currencySymbol else "" + token = if (amountToSend?.type is AmountType.Token) amountToSend.currencySymbol else "" } private fun createEmailWalletInfo(walletManager: WalletManager): EmailWalletInfo { diff --git a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt index 5b83d8c803..7cf0e08bf1 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt @@ -12,7 +12,6 @@ import com.tangem.tap.scope import com.tangem.tap.store import kotlinx.coroutines.launch import org.rekotlin.Middleware -import java.math.BigDecimal internal object LegacyMiddleware { val legacyMiddleware: Middleware = { _, _ -> @@ -41,8 +40,8 @@ internal object LegacyMiddleware { )?.let { walletManager -> store.state.globalState.feedbackManager?.infoHolder?.updateOnSendError( walletManager = walletManager, - amountToSend = action.amount.convertToAmount(action.cryptoCurrency), - feeAmount = action.fee.convertToAmount(action.cryptoCurrency), + amountToSend = action.amount?.convertToAmount(action.cryptoCurrency), + feeAmount = action.fee?.convertToAmount(action.cryptoCurrency), destinationAddress = action.destinationAddress, ) } diff --git a/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt b/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt index f159059c87..3e0b022afd 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt @@ -30,9 +30,9 @@ sealed interface LegacyAction : Action { data class SendEmailTransactionFailed( val cryptoCurrency: CryptoCurrency, val userWalletId: UserWalletId, - val amount: BigDecimal, - val fee: BigDecimal, - val destinationAddress: String, + val amount: BigDecimal?, + val fee: BigDecimal?, + val destinationAddress: String?, val errorMessage: String, ) : LegacyAction } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt index 8654c0f8f9..40add3e136 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt @@ -541,17 +541,21 @@ internal class SendViewModel @Inject constructor( } override fun onFailedTxEmailClick(errorMessage: String) { - val recipient = uiState.recipientState?.addressTextField?.value ?: return - val feeValue = uiState.feeState?.fee?.amount?.value ?: return - val amountValue = uiState.amountState?.amountTextField?.cryptoAmount?.value ?: return + val recipient = uiState.recipientState?.addressTextField?.value + val feeValue = uiState.feeState?.fee?.amount?.value + val amountValue = uiState.amountState?.amountTextField?.cryptoAmount?.value - val receivingAmount = checkAndCalculateSubtractedAmount( - isAmountSubtractAvailable = isAmountSubtractAvailable, - cryptoCurrencyStatus = cryptoCurrencyStatus, - amountValue = amountValue, - feeValue = feeValue, - reduceAmountBy = uiState.sendState?.reduceAmountBy ?: BigDecimal.ZERO, - ) + val receivingAmount = if (amountValue != null && feeValue != null) { + checkAndCalculateSubtractedAmount( + isAmountSubtractAvailable = isAmountSubtractAvailable, + cryptoCurrencyStatus = cryptoCurrencyStatus, + amountValue = amountValue, + feeValue = feeValue, + reduceAmountBy = uiState.sendState?.reduceAmountBy ?: BigDecimal.ZERO, + ) + } else { + null + } reduxStateHolder.dispatch( LegacyAction.SendEmailTransactionFailed( cryptoCurrency = cryptoCurrency,