Updated on 2026-08-14

This commit is contained in:
Tangem 2023-05-29 15:29:24 +05:00
parent 307520acbd
commit 88ee5df2a4
4 changed files with 17 additions and 17 deletions

View file

@ -82,7 +82,7 @@ class AmountMiddleware {
val sendState = appState?.sendState ?: return
dispatch(AmountAction.SetAmount(sendState.amountState.balanceCrypto, false))
if (sendState.amountState.isCoinAmount()) {
if (sendState.amountState.canIncludeFee()) {
dispatch(FeeAction.ChangeLayoutVisibility(main = true, controls = true))
dispatch(FeeActionUi.ChangeIncludeFee(true))
}

View file

@ -1,20 +1,10 @@
package com.tangem.tap.features.send.redux.reducers
import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.Blockchain
import com.tangem.tap.common.CurrencyConverter
import com.tangem.tap.common.entities.IndeterminateProgressButton
import com.tangem.tap.features.send.redux.AddressPayIdActionUi
import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction
import com.tangem.tap.features.send.redux.AmountAction
import com.tangem.tap.features.send.redux.AmountActionUi
import com.tangem.tap.features.send.redux.FeeAction
import com.tangem.tap.features.send.redux.FeeActionUi
import com.tangem.tap.features.send.redux.PrepareSendScreen
import com.tangem.tap.features.send.redux.ReceiptAction
import com.tangem.tap.features.send.redux.ReleaseSendState
import com.tangem.tap.features.send.redux.SendAction
import com.tangem.tap.features.send.redux.SendScreenAction
import com.tangem.tap.features.send.redux.TransactionExtrasAction
import com.tangem.tap.features.send.redux.*
import com.tangem.tap.features.send.redux.states.ExternalTransactionData
import com.tangem.tap.features.send.redux.states.IdStateHolder
import com.tangem.tap.features.send.redux.states.SendState
@ -98,21 +88,28 @@ private class PrepareSendScreenStatesReducer : SendInternalReducer {
val walletManager = action.walletManager!!
val amountToExtract = prepareAction.tokenAmount ?: prepareAction.coinAmount!!
val decimals = amountToExtract.decimals
val feePaidInNetworkCurrency = isFeePaidInNetworkCurrency(walletManager.wallet.blockchain)
return sendState.copy(
walletManager = walletManager,
coinConverter = action.coinRate?.let { CurrencyConverter(it, decimals) },
tokenConverter = action.tokenRate?.let { CurrencyConverter(it, decimals) },
amountState = sendState.amountState.copy(
feePaidInCurrencyNetworkCurrency = feePaidInNetworkCurrency,
amountToExtract = amountToExtract,
typeOfAmount = amountToExtract.type,
balanceCrypto = amountToExtract.value ?: BigDecimal.ZERO,
),
feeState = sendState.feeState.copy(
includeFeeSwitcherIsEnabled = amountToExtract.type == AmountType.Coin,
includeFeeSwitcherIsEnabled = feePaidInNetworkCurrency || isCoinAmount(amountToExtract.type),
),
)
}
private fun isFeePaidInNetworkCurrency(blockchain: Blockchain): Boolean =
blockchain.tokenTransactionFeePaidInNetworkCurrency()
private fun isCoinAmount(typeOfAmount: AmountType): Boolean = typeOfAmount == AmountType.Coin
}
internal fun updateLastState(sendState: SendState, lastChangedState: IdStateHolder): SendState {

View file

@ -91,7 +91,7 @@ data class SendState(
fun getButtonState(): ButtonState = if (isReadyToSend()) ButtonState.ENABLED else ButtonState.DISABLED
fun getTotalAmountToSend(value: BigDecimal = amountState.amountToSendCrypto): BigDecimal {
val needToExtractFee = amountState.isCoinAmount() && feeState.feeIsIncluded
val needToExtractFee = amountState.canIncludeFee() && feeState.feeIsIncluded
return if (needToExtractFee) value.minus(feeState.getCurrentFeeValue()) else value
}
@ -135,13 +135,16 @@ data class AmountState(
val decimalSeparator: String = ".",
val error: TapError? = null,
val inputIsEnabled: Boolean = true,
private val feePaidInCurrencyNetworkCurrency: Boolean = false,
) : SendScreenState {
override val stateId: StateId = StateId.AMOUNT
fun isReady(): Boolean = error == null && !amountToSendCrypto.isZero()
fun isCoinAmount(): Boolean = typeOfAmount == AmountType.Coin
private fun isCoinAmount(): Boolean = typeOfAmount == AmountType.Coin
fun canIncludeFee(): Boolean = isCoinAmount() || feePaidInCurrencyNetworkCurrency
fun createMainCurrency(type: MainCurrencyType, canSwitched: Boolean): MainCurrency {
return if (!canSwitched) {

View file

@ -73,7 +73,7 @@ reactiveNetwork = "3.0.8"
# endregion Other libraries
# region Tangem
tangemBlockchainSdk = "develop-224"
tangemBlockchainSdk = "develop-225"
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
tangemCardSdk = "develop-249"
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds