From 94c372754b5668e84eb9fa32dd4a1ba1b13f2d53 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 12 May 2025 22:10:37 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../send/v2/common/PredefinedValues.kt | 2 +- .../send/v2/send/DefaultSendComponent.kt | 18 +---- .../features/send/v2/send/model/SendModel.kt | 76 +++++++++++++------ 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/PredefinedValues.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/PredefinedValues.kt index ef94394fcf..9ebfa54ccf 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/PredefinedValues.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/PredefinedValues.kt @@ -9,7 +9,7 @@ sealed class PredefinedValues { abstract val memo: String? data class Deeplink( - override val amount: String?, + override val amount: String, override val address: String, override val memo: String?, val transactionId: String, diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt index 3f2eba602f..36b57ddd7c 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt @@ -21,7 +21,6 @@ import com.tangem.core.ui.decompose.ComposableContentComponent import com.tangem.core.ui.extensions.resourceReference import com.tangem.features.send.v2.api.SendComponent import com.tangem.features.send.v2.common.CommonSendRoute -import com.tangem.features.send.v2.common.PredefinedValues import com.tangem.features.send.v2.common.analytics.CommonSendAnalyticEvents import com.tangem.features.send.v2.common.analytics.CommonSendAnalyticEvents.SendScreenSource import com.tangem.features.send.v2.common.ui.SendContent @@ -252,20 +251,7 @@ internal class DefaultSendComponent @AssistedInject constructor( private fun getConfirmComponent(factoryContext: AppComponentContext): ComposableContentComponent { val cryptoCurrencyStatus = model.cryptoCurrencyStatus val feeCryptoCurrencyStatus = model.feeCryptoCurrencyStatus - val predefinedAmount = params.amount - val predefinedTxId = params.transactionId - val predefinedAddress = params.destinationAddress - val predefinedValues = - if (predefinedAmount != null && predefinedTxId != null && predefinedAddress != null) { - PredefinedValues.Content.Deeplink( - amount = predefinedAmount, - address = predefinedAddress, - memo = params.tag, - transactionId = predefinedTxId, - ) - } else { - PredefinedValues.Empty - } + return if (cryptoCurrencyStatus != null && feeCryptoCurrencyStatus != null) { SendConfirmComponent( appComponentContext = factoryContext, @@ -279,7 +265,7 @@ internal class DefaultSendComponent @AssistedInject constructor( feeCryptoCurrencyStatus = feeCryptoCurrencyStatus, appCurrency = model.appCurrency, callback = model, - predefinedValues = predefinedValues, + predefinedValues = model.predefinedValues, onLoadFee = model::loadFee, ), ) diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt index ff273f2b85..d8878e70e0 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt @@ -11,6 +11,7 @@ import com.tangem.core.decompose.model.Model import com.tangem.core.decompose.model.ParamsContainer import com.tangem.core.decompose.navigation.Router import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.core.ui.utils.parseBigDecimalOrNull import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase @@ -111,6 +112,7 @@ internal class SendModel @Inject constructor( subscribeOnQRScannerResult() subscribeOnCurrencyStatusUpdates() initAppCurrency() + initPredefinedValues() } override fun onNavigationResult(navigationUM: NavigationUM) { @@ -135,19 +137,31 @@ internal class SendModel @Inject constructor( } suspend fun loadFee(): Either { - val destinationUM = uiState.value.destinationUM as? DestinationUM.Content ?: error("Invalid destination") - val amountUM = uiState.value.amountUM as? AmountState.Data ?: error("Invalid amount") - val enteredDestinationAddress = destinationUM.addressTextField.value - val enteredMemo = destinationUM.memoTextField?.value - val enteredAmount = amountUM.amountTextField.cryptoAmount.value ?: error("Invalid amount") + val predefinedValues = predefinedValues + val transferTransaction = if (predefinedValues is PredefinedValues.Content.Deeplink) { + val predefinedAmount = predefinedValues.amount.parseBigDecimalOrNull()?.convertToSdkAmount(cryptoCurrency) + createTransferTransactionUseCase( + amount = predefinedAmount ?: error("Invalid amount"), + memo = predefinedValues.memo, + destination = predefinedValues.address, + userWalletId = userWallet.walletId, + network = cryptoCurrency.network, + ) + } else { + val destinationUM = uiState.value.destinationUM as? DestinationUM.Content ?: error("Invalid destination") + val amountUM = uiState.value.amountUM as? AmountState.Data ?: error("Invalid amount") + val enteredDestinationAddress = destinationUM.addressTextField.value + val enteredMemo = destinationUM.memoTextField?.value + val enteredAmount = amountUM.amountTextField.cryptoAmount.value ?: error("Invalid amount") - val transferTransaction = createTransferTransactionUseCase( - amount = enteredAmount.convertToSdkAmount(cryptoCurrency), - memo = enteredMemo, - destination = enteredDestinationAddress, - userWalletId = userWallet.walletId, - network = cryptoCurrency.network, - ).getOrElse { + createTransferTransactionUseCase( + amount = enteredAmount.convertToSdkAmount(cryptoCurrency), + memo = enteredMemo, + destination = enteredDestinationAddress, + userWalletId = userWallet.walletId, + network = cryptoCurrency.network, + ) + }.getOrElse { return GetFeeError.DataError(it).left() } @@ -158,16 +172,6 @@ internal class SendModel @Inject constructor( ) } - private fun resetPredefinedAmount() { - // reset predefined amount - val internalPredefinedValues = predefinedValues - predefinedValues = when (internalPredefinedValues) { - is PredefinedValues.Content.Deeplink -> internalPredefinedValues.copy(amount = null) - is PredefinedValues.Content.QrCode -> internalPredefinedValues.copy(amount = null) - PredefinedValues.Empty -> internalPredefinedValues - } - } - fun showAlertError() { sendConfirmAlertFactory.getGenericErrorState( onFailedTxEmailClick = ::onFailedTxEmailClick, @@ -181,6 +185,34 @@ internal class SendModel @Inject constructor( } } + private fun initPredefinedValues() { + val predefinedAmount = params.amount + val predefinedTxId = params.transactionId + val predefinedAddress = params.destinationAddress + + predefinedValues = if (predefinedAmount != null && predefinedTxId != null && predefinedAddress != null) { + PredefinedValues.Content.Deeplink( + amount = predefinedAmount, + address = predefinedAddress, + memo = params.tag, + transactionId = predefinedTxId, + ) + } else { + PredefinedValues.Empty + } + } + + private fun resetPredefinedAmount() { + // reset predefined amount + val internalPredefinedValues = predefinedValues + predefinedValues = when (internalPredefinedValues) { + is PredefinedValues.Content.QrCode -> internalPredefinedValues.copy(amount = null) + is PredefinedValues.Content.Deeplink, + PredefinedValues.Empty, + -> internalPredefinedValues + } + } + private fun subscribeOnCurrencyStatusUpdates() { modelScope.launch { getUserWalletUseCase(params.userWalletId).fold(