Updated on 2026-08-14
This commit is contained in:
parent
ab2f0f58bb
commit
22ad2ddc67
22 changed files with 190 additions and 15 deletions
|
|
@ -9,6 +9,15 @@ sealed class AssetRequirementsCondition {
|
|||
*/
|
||||
data object PaidTransaction : AssetRequirementsCondition()
|
||||
|
||||
/**
|
||||
* Trustlines are an explicit opt-in for an account to hold a particular asset.
|
||||
*/
|
||||
data class RequiredTrustline(
|
||||
val requiredAmount: BigDecimal,
|
||||
val currencySymbol: String,
|
||||
val decimals: Int,
|
||||
) : AssetRequirementsCondition()
|
||||
|
||||
/**
|
||||
* The exact value of the fee for this type of condition is stored in `feeAmount`.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.domain.transaction.error
|
||||
|
||||
import java.math.BigDecimal
|
||||
|
||||
sealed interface OpenTrustlineError {
|
||||
val message: String?
|
||||
|
||||
data class SomeError(override val message: String?) : OpenTrustlineError
|
||||
data class NotEnoughCoin(val amount: BigDecimal, override val message: String?) : OpenTrustlineError
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.tangem.domain.transaction.usecase
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.raise.catch
|
||||
import arrow.core.raise.either
|
||||
import com.tangem.blockchain.common.BlockchainSdkError
|
||||
import com.tangem.blockchain.extensions.SimpleResult
|
||||
import com.tangem.domain.card.repository.CardSdkConfigRepository
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.transaction.error.OpenTrustlineError
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
||||
class OpenTrustlineUseCase(
|
||||
private val cardSdkConfigRepository: CardSdkConfigRepository,
|
||||
private val walletManagersFacade: WalletManagersFacade,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
currency: CryptoCurrency,
|
||||
): Either<OpenTrustlineError, Unit> {
|
||||
return either {
|
||||
val signer = cardSdkConfigRepository.getCommonSigner(
|
||||
cardId = null,
|
||||
twinKey = null, // use null here because no assets support for Twin cards
|
||||
)
|
||||
|
||||
catch(
|
||||
block = {
|
||||
when (val result = walletManagersFacade.fulfillRequirements(userWalletId, currency, signer)) {
|
||||
is SimpleResult.Failure -> when (val error = result.error) {
|
||||
is BlockchainSdkError.Stellar.MinReserveRequired ->
|
||||
raise(OpenTrustlineError.NotEnoughCoin(error.amount, result.error.customMessage))
|
||||
else -> raise(OpenTrustlineError.SomeError(result.error.customMessage))
|
||||
}
|
||||
SimpleResult.Success -> Unit
|
||||
}
|
||||
},
|
||||
catch = { error -> raise(OpenTrustlineError.SomeError(error.message)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue