Updated on 2026-08-14
This commit is contained in:
parent
5014718503
commit
94c372754b
3 changed files with 57 additions and 39 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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<GetFeeError, TransactionFee> {
|
||||
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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue