Updated on 2026-08-14

This commit is contained in:
Tangem 2025-10-07 19:39:10 +05:00
parent 5d21b088c4
commit 16156c559a
2 changed files with 21 additions and 6 deletions

View file

@ -5,6 +5,7 @@ import com.tangem.blockchain.common.TransactionData
import com.tangem.core.ui.components.currency.icon.CurrencyIconState
import com.tangem.core.ui.extensions.TextReference
import kotlinx.collections.immutable.ImmutableList
import java.math.BigDecimal
@Immutable
internal sealed class YieldSupplyFeeUM {
@ -27,4 +28,5 @@ internal data class YieldSupplyActionUM(
val yieldSupplyFeeUM: YieldSupplyFeeUM,
val isPrimaryButtonEnabled: Boolean,
val isTransactionSending: Boolean,
val maxFee: BigDecimal = BigDecimal.ZERO,
)

View file

@ -8,8 +8,10 @@ import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.core.ui.utils.parseToBigDecimal
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.tokens.FetchCurrencyStatusUseCase
@ -18,6 +20,7 @@ import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.transaction.usecase.SendTransactionUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.domain.yield.supply.usecase.YieldSupplyEstimateEnterFeeUseCase
import com.tangem.domain.yield.supply.usecase.YieldSupplyGetTokenStatusUseCase
import com.tangem.domain.yield.supply.usecase.YieldSupplyStartEarningUseCase
import com.tangem.features.yield.supply.impl.R
import com.tangem.features.yield.supply.impl.common.YieldSupplyAlertFactory
@ -55,6 +58,7 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
private val yieldSupplyNotificationsUpdateTrigger: YieldSupplyNotificationsUpdateTrigger,
private val fetchCurrencyStatusUseCase: FetchCurrencyStatusUseCase,
private val yieldSupplyAlertFactory: YieldSupplyAlertFactory,
private val yieldSupplyGetTokenStatusUseCase: YieldSupplyGetTokenStatusUseCase,
) : Model(), YieldSupplyNotificationsComponent.ModelCallback {
private val params: YieldSupplyStartEarningComponent.Params = paramsContainer.require()
@ -106,13 +110,26 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
}
}
private suspend fun getMaxFee(): BigDecimal? {
if (uiState.value.maxFee != BigDecimal.ZERO) return uiState.value.maxFee
val yieldTokenStatus = yieldSupplyGetTokenStatusUseCase(cryptoCurrency as CryptoCurrency.Token)
.getOrNull()
return yieldTokenStatus?.maxFeeNative?.parseToBigDecimal(cryptoCurrency.decimals)
}
private suspend fun onLoadFee() {
if (cryptoCurrencyStatus.value is CryptoCurrencyStatus.Loading || uiState.value.isTransactionSending) return
val maxFee = if (uiState.value.maxFee == BigDecimal.ZERO) {
getMaxFee()
} else {
uiState.value.maxFee
} ?: return
val transactionListData = yieldSupplyStartEarningUseCase(
userWalletId = userWallet.walletId,
cryptoCurrencyStatus = cryptoCurrencyStatus,
maxNetworkFee = MAX_NETWORK_FEE,
maxNetworkFee = maxFee,
).getOrNull() ?: return
uiState.update {
@ -146,7 +163,7 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
appCurrency = appCurrency,
updatedTransactionList = updatedTransactionList,
feeValue = feeSum,
maxNetworkFee = MAX_NETWORK_FEE,
maxNetworkFee = maxFee,
),
)
yieldSupplyNotificationsUpdateTrigger.triggerUpdate(
@ -274,8 +291,4 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
popBack = params.callback::onBackClick,
)
}
private companion object {
val MAX_NETWORK_FEE: BigDecimal = BigDecimal.TEN // TODO replace with value from api
}
}