Updated on 2026-08-14
This commit is contained in:
commit
dc0b552f5a
6 changed files with 42 additions and 13 deletions
|
|
@ -91,7 +91,7 @@ class TokenItemStateConverter(
|
|||
}
|
||||
|
||||
private fun CryptoCurrencyStatus.getStakedBalance() =
|
||||
(value.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero()
|
||||
(value.yieldBalance as? YieldBalance.Data)?.getTotalWithRewardsStakingBalance().orZero()
|
||||
|
||||
private fun CryptoCurrencyStatus.mapToUnreachableTokenItemState(): TokenItemState.Unreachable {
|
||||
return TokenItemState.Unreachable(
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ sealed class YieldBalance {
|
|||
val balance: YieldBalanceItem,
|
||||
val address: String,
|
||||
) : YieldBalance() {
|
||||
fun getTotalWithRewardsStakingBalance(): BigDecimal {
|
||||
return balance.items.sumOf { it.amount }
|
||||
}
|
||||
|
||||
fun getTotalStakingBalance(): BigDecimal {
|
||||
return balance.items
|
||||
.filterNot { it.type == BalanceType.REWARDS }
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ internal class TokenListFiatBalanceOperations(
|
|||
currentBalance: TotalFiatBalance,
|
||||
): TotalFiatBalance {
|
||||
return with(currentBalance) {
|
||||
val stakingBalance = (status.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero()
|
||||
val yieldBalance = status.yieldBalance as? YieldBalance.Data
|
||||
val stakingBalance = yieldBalance?.getTotalWithRewardsStakingBalance().orZero()
|
||||
val fiatStakingBalance = status.fiatRate.times(stakingBalance)
|
||||
|
||||
(this as? TotalFiatBalance.Loaded)?.copy(
|
||||
|
|
@ -76,7 +77,7 @@ internal class TokenListFiatBalanceOperations(
|
|||
): TotalFiatBalance {
|
||||
return with(currentBalance) {
|
||||
val isTokenAmountCanBeSummarized = status.fiatAmount != null
|
||||
val yieldBalance = (status.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero()
|
||||
val yieldBalance = (status.yieldBalance as? YieldBalance.Data)?.getTotalWithRewardsStakingBalance().orZero()
|
||||
val fiatYieldBalance = status.fiatRate?.times(yieldBalance).orZero()
|
||||
(this as? TotalFiatBalance.Loaded)?.copy(
|
||||
amount = this.amount + status.fiatAmount.orZero() + fiatYieldBalance,
|
||||
|
|
|
|||
|
|
@ -67,13 +67,18 @@ internal class AddStakingNotificationsTransformer(
|
|||
isSubtractAvailable = isSubtractAvailable,
|
||||
reduceAmountBy = reduceAmountBy,
|
||||
)
|
||||
val sendingAmount = checkAndCalculateSubtractedAmount(
|
||||
isAmountSubtractAvailable = isSubtractAvailable,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
amountValue = amountValue,
|
||||
feeValue = feeValue,
|
||||
reduceAmountBy = reduceAmountBy,
|
||||
)
|
||||
val sendingAmount = if (isEnterAction) {
|
||||
checkAndCalculateSubtractedAmount(
|
||||
isAmountSubtractAvailable = isSubtractAvailable,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
amountValue = amountValue,
|
||||
feeValue = feeValue,
|
||||
reduceAmountBy = reduceAmountBy,
|
||||
)
|
||||
} else {
|
||||
// No amount is taken from account balance on exit or pending actions
|
||||
BigDecimal.ZERO
|
||||
}
|
||||
|
||||
val notifications = buildList {
|
||||
// errors
|
||||
|
|
@ -222,6 +227,9 @@ internal class AddStakingNotificationsTransformer(
|
|||
StakingActionType.RESTAKE_REWARDS -> {
|
||||
R.string.staking_restake to R.string.staking_notification_restake_rewards_text
|
||||
}
|
||||
StakingActionType.WITHDRAW -> {
|
||||
R.string.staking_withdraw to R.string.staking_notification_withdraw_text
|
||||
}
|
||||
else -> null to null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,9 +56,11 @@ import com.tangem.features.staking.impl.presentation.state.transformers.approval
|
|||
import com.tangem.features.staking.impl.presentation.state.transformers.approval.SetConfirmationStateAssentApprovalTransformer
|
||||
import com.tangem.features.staking.impl.presentation.state.transformers.approval.ShowApprovalBottomSheetTransformer
|
||||
import com.tangem.features.staking.impl.presentation.state.transformers.validator.ValidatorSelectChangeTransformer
|
||||
import com.tangem.features.staking.impl.presentation.state.utils.checkAndCalculateSubtractedAmount
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.coroutines.*
|
||||
import com.tangem.utils.extensions.isSingleItem
|
||||
import com.tangem.utils.extensions.orZero
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
|
@ -236,7 +238,7 @@ internal class StakingViewModel @Inject constructor(
|
|||
val validatorState = confirmationState.validatorState as? ValidatorState.Content
|
||||
?: error("No validator provided")
|
||||
val amountState = value.amountState as? AmountState.Data ?: error("No amount provided")
|
||||
val amountValue = amountState.amountTextField.cryptoAmount.value ?: error("No amount value")
|
||||
|
||||
val fee = (confirmationState.feeState as? FeeState.Content)?.fee ?: error("No fee provided")
|
||||
val defaultAddress = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value
|
||||
?: error("No available address")
|
||||
|
|
@ -248,7 +250,7 @@ internal class StakingViewModel @Inject constructor(
|
|||
params = ActionParams(
|
||||
actionCommonType = value.actionType,
|
||||
integrationId = yield.id,
|
||||
amount = amountValue,
|
||||
amount = getAmount(amountState, fee, confirmationState.reduceAmountBy),
|
||||
address = defaultAddress,
|
||||
validatorAddress = validatorState.chosenValidator.address,
|
||||
token = yield.token,
|
||||
|
|
@ -893,6 +895,20 @@ internal class StakingViewModel @Inject constructor(
|
|||
.getOrElse { false }
|
||||
}
|
||||
|
||||
private fun getAmount(amountState: AmountState.Data, fee: Fee, reduceAmountBy: BigDecimal?): BigDecimal {
|
||||
val amountValue = amountState.amountTextField.cryptoAmount.value ?: error("No amount value")
|
||||
val feeValue = fee.amount.value ?: error("No fee value")
|
||||
val isEnterAction = stateController.value.actionType == StakingActionCommonType.ENTER
|
||||
|
||||
return checkAndCalculateSubtractedAmount(
|
||||
isAmountSubtractAvailable = isAmountSubtractAvailable && isEnterAction,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
amountValue = amountValue,
|
||||
feeValue = feeValue,
|
||||
reduceAmountBy = reduceAmountBy.orZero(),
|
||||
)
|
||||
}
|
||||
|
||||
private data class FullTransactionData(
|
||||
val stakeKitTransaction: StakingTransaction,
|
||||
val tangemTransaction: TransactionData.Compiled,
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ internal class TokenDetailsLoadedBalanceConverter(
|
|||
currentState: TokenDetailsBalanceBlockState,
|
||||
status: CryptoCurrencyStatus,
|
||||
): TokenDetailsBalanceBlockState {
|
||||
val stakingCryptoAmount = (status.value.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance()
|
||||
val stakingCryptoAmount = (status.value.yieldBalance as? YieldBalance.Data)?.getTotalWithRewardsStakingBalance()
|
||||
val stakingFiatAmount = stakingCryptoAmount?.let { status.value.fiatRate?.multiply(it) }
|
||||
val isBalanceSelectorEnabled = stakingFeatureToggles.isStakingEnabled && !stakingCryptoAmount.isNullOrZero()
|
||||
return when (status.value) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue