Updated on 2026-08-14
This commit is contained in:
parent
3c8fb7f668
commit
ebfa4fed41
8 changed files with 160 additions and 39 deletions
|
|
@ -26,6 +26,7 @@ import com.tangem.domain.core.lce.lceFlow
|
|||
import com.tangem.domain.staking.model.*
|
||||
import com.tangem.domain.staking.model.action.StakingAction
|
||||
import com.tangem.domain.staking.model.action.StakingActionCommonType
|
||||
import com.tangem.domain.staking.model.action.StakingActionType
|
||||
import com.tangem.domain.staking.model.transaction.ActionParams
|
||||
import com.tangem.domain.staking.model.transaction.StakingGasEstimate
|
||||
import com.tangem.domain.staking.model.transaction.StakingTransaction
|
||||
|
|
@ -158,10 +159,12 @@ internal class DefaultStakingRepository(
|
|||
|
||||
override suspend fun createAction(params: ActionParams): StakingAction {
|
||||
return withContext(dispatchers.io) {
|
||||
val body = createActionRequestBody(params)
|
||||
val response = when (params.actionCommonType) {
|
||||
StakingActionCommonType.ENTER -> stakeKitApi.createEnterAction(body)
|
||||
StakingActionCommonType.EXIT -> stakeKitApi.createExitAction(body)
|
||||
StakingActionCommonType.ENTER -> stakeKitApi.createEnterAction(createActionRequestBody(params))
|
||||
StakingActionCommonType.EXIT -> stakeKitApi.createExitAction(createActionRequestBody(params))
|
||||
StakingActionCommonType.PENDING -> stakeKitApi.createPendingAction(
|
||||
createPendingActionRequestBody(params),
|
||||
)
|
||||
}
|
||||
|
||||
enterActionResponseConverter.convert(response.getOrThrow())
|
||||
|
|
@ -170,11 +173,12 @@ internal class DefaultStakingRepository(
|
|||
|
||||
override suspend fun estimateGas(params: ActionParams): StakingGasEstimate {
|
||||
return withContext(dispatchers.io) {
|
||||
val body = createActionRequestBody(params)
|
||||
|
||||
val gasEstimateDTO = when (params.actionCommonType) {
|
||||
StakingActionCommonType.ENTER -> stakeKitApi.estimateGasOnEnter(body)
|
||||
StakingActionCommonType.EXIT -> stakeKitApi.estimateGasOnExit(body)
|
||||
StakingActionCommonType.ENTER -> stakeKitApi.estimateGasOnEnter(createActionRequestBody(params))
|
||||
StakingActionCommonType.EXIT -> stakeKitApi.estimateGasOnExit(createActionRequestBody(params))
|
||||
StakingActionCommonType.PENDING -> stakeKitApi.estimateGasOnPending(
|
||||
createPendingActionRequestBody(params),
|
||||
)
|
||||
}
|
||||
|
||||
gasEstimateConverter.convert(gasEstimateDTO.getOrThrow())
|
||||
|
|
@ -432,7 +436,7 @@ internal class DefaultStakingRepository(
|
|||
return ActionRequestBody(
|
||||
integrationId = params.integrationId,
|
||||
addresses = Address(params.address),
|
||||
args = ActionRequestBody.EnterActionRequestBodyArgs(
|
||||
args = ActionRequestBodyArgs(
|
||||
amount = params.amount.toFormattedString(params.token.decimals),
|
||||
inputToken = tokenConverter.convertBack(params.token),
|
||||
validatorAddress = params.validatorAddress,
|
||||
|
|
@ -440,6 +444,18 @@ internal class DefaultStakingRepository(
|
|||
)
|
||||
}
|
||||
|
||||
private fun createPendingActionRequestBody(params: ActionParams): PendingActionRequestBody {
|
||||
return PendingActionRequestBody(
|
||||
integrationId = params.integrationId,
|
||||
type = params.type ?: StakingActionType.UNKNOWN,
|
||||
passthrough = params.passthrough.orEmpty(),
|
||||
args = ActionRequestBodyArgs(
|
||||
amount = params.amount.toFormattedString(params.token.decimals),
|
||||
validatorAddress = params.validatorAddress,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
override fun isStakeMoreAvailable(networkId: Network.ID): Boolean {
|
||||
val blockchain = Blockchain.fromId(networkId.value)
|
||||
return when (blockchain) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.data.staking.converters
|
||||
|
||||
import com.tangem.data.staking.converters.action.PendingActionConverter
|
||||
import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO
|
||||
import com.tangem.domain.staking.model.BalanceItem
|
||||
import com.tangem.domain.staking.model.BalanceType
|
||||
|
|
@ -9,6 +10,8 @@ import com.tangem.utils.converter.Converter
|
|||
|
||||
internal class YieldBalanceConverter : Converter<YieldBalanceConverter.Data, YieldBalance> {
|
||||
|
||||
private val pendingActionConverter by lazy(LazyThreadSafetyMode.NONE) { PendingActionConverter() }
|
||||
|
||||
override fun convert(value: Data): YieldBalance {
|
||||
return if (value.balance.isEmpty()) {
|
||||
YieldBalance.Empty
|
||||
|
|
@ -22,6 +25,7 @@ internal class YieldBalanceConverter : Converter<YieldBalanceConverter.Data, Yie
|
|||
pricePerShare = item.pricePerShare,
|
||||
rawCurrencyId = item.tokenDTO.coinGeckoId,
|
||||
validatorAddress = item.validatorAddress,
|
||||
pendingActions = pendingActionConverter.convertList(item.pendingActions),
|
||||
)
|
||||
},
|
||||
integrationId = value.integrationId,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package com.tangem.data.staking.converters.action
|
||||
|
||||
import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO
|
||||
import com.tangem.domain.staking.model.PendingAction
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
||||
internal class PendingActionConverter : Converter<BalanceDTO.PendingAction, PendingAction> {
|
||||
|
||||
private val stakingActionTypeConverter by lazy(LazyThreadSafetyMode.NONE) { StakingActionTypeConverter() }
|
||||
|
||||
override fun convert(value: BalanceDTO.PendingAction): PendingAction {
|
||||
return PendingAction(
|
||||
type = stakingActionTypeConverter.convert(value.type),
|
||||
passthrough = value.passthrough,
|
||||
args = with(value.args) {
|
||||
PendingAction.PendingActionArgs(
|
||||
amount = this?.amount?.let {
|
||||
PendingAction.PendingActionArgs.Amount(
|
||||
required = it.required,
|
||||
minimum = it.minimum,
|
||||
maximum = it.maximum,
|
||||
)
|
||||
},
|
||||
duration = this?.duration?.let {
|
||||
PendingAction.PendingActionArgs.Duration(
|
||||
required = it.required,
|
||||
minimum = it.minimum,
|
||||
maximum = it.maximum,
|
||||
)
|
||||
},
|
||||
validatorAddress = this?.validatorAddress?.required,
|
||||
validatorAddresses = this?.validatorAddresses?.required,
|
||||
tronResource = this?.tronResource?.let {
|
||||
PendingAction.PendingActionArgs.TronResource(
|
||||
required = it.required,
|
||||
options = it.options,
|
||||
)
|
||||
},
|
||||
signatureVerification = this?.signatureVerification?.required,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue