Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-16 19:18:15 +04:00
parent 1cdece6ae7
commit d7a120fc86
24 changed files with 486 additions and 160 deletions

View file

@ -24,6 +24,7 @@ dependencies {
implementation(projects.domain.core)
implementation(projects.domain.tokens.models)
implementation(projects.domain.wallets.models)
implementation(projects.features.swap.domain)
/** Feature API - remove after removing [TangemPayFeatureToggles] */
implementation(projects.features.tangempay.details.api)

View file

@ -0,0 +1,14 @@
package com.tangem.domain.pay
data class TangemPayWithdrawState(
val orderId: String,
val exchangeData: TangemPayWithdrawExchangeState?,
)
data class TangemPayWithdrawExchangeState(
val txId: String,
val fromNetwork: String,
val fromAddress: String,
val payInAddress: String,
val payInExtraId: String?,
)

View file

@ -0,0 +1,6 @@
package com.tangem.domain.pay.model
data class OrderData(
val status: OrderStatus,
val withdrawTxHash: String?,
)

View file

@ -2,12 +2,10 @@ package com.tangem.domain.pay.repository
import arrow.core.Either
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.pay.model.OrderStatus
import com.tangem.domain.pay.model.OrderData
import com.tangem.domain.visa.error.VisaApiError
interface CustomerOrderRepository {
suspend fun getOrderStatus(userWalletId: UserWalletId, orderId: String): Either<VisaApiError, OrderStatus>
suspend fun hasWithdrawOrder(userWalletId: UserWalletId): Boolean
suspend fun getOrderData(userWalletId: UserWalletId, orderId: String): Either<VisaApiError, OrderData>
}

View file

@ -4,15 +4,22 @@ import arrow.core.Either
import com.tangem.core.error.UniversalError
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.pay.TangemPayWithdrawExchangeState
import com.tangem.domain.pay.WithdrawalResult
import com.tangem.domain.visa.error.VisaApiError
import java.math.BigDecimal
interface TangemPaySwapRepository {
interface TangemPayWithdrawRepository {
suspend fun withdraw(
userWallet: UserWallet,
receiverAddress: String,
cryptoAmount: BigDecimal,
cryptoCurrencyId: CryptoCurrency.RawID,
exchangeData: TangemPayWithdrawExchangeState,
): Either<UniversalError, WithdrawalResult>
suspend fun hasWithdrawOrder(userWallet: UserWallet): Boolean
suspend fun pollWithdrawOrderIfNeeds(userWallet: UserWallet): Either<VisaApiError, Unit>
}

View file

@ -137,13 +137,13 @@ class TangemPayMainScreenCustomerInfoUseCase(
userWalletId: UserWalletId,
orderId: String,
): Either<TangemPayCustomerInfoError, MainScreenCustomerInfo> {
return customerOrderRepository.getOrderStatus(userWalletId, orderId = orderId)
return customerOrderRepository.getOrderData(userWalletId, orderId = orderId)
.fold(
ifLeft = { error ->
error.mapErrorForCustomer().left()
},
ifRight = { orderStatus ->
when (orderStatus) {
ifRight = { orderData ->
when (orderData.status) {
// Kyc is passed and user waits for order creation -> no need to get customer info
OrderStatus.NEW,
OrderStatus.PROCESSING,
@ -154,7 +154,7 @@ class TangemPayMainScreenCustomerInfoUseCase(
kycStatus = CustomerInfo.KycStatus.APPROVED,
cardInfo = null,
),
orderStatus = orderStatus,
orderStatus = orderData.status,
).right()
// Order was created/cancelled -> clear order id and get customer info
@ -164,11 +164,11 @@ class TangemPayMainScreenCustomerInfoUseCase(
-> {
onboardingRepository.clearOrderId(userWalletId)
// If order was cancelled -> start order creation
if (orderStatus == OrderStatus.CANCELED) onboardingRepository.createOrder(userWalletId)
if (orderData.status == OrderStatus.CANCELED) onboardingRepository.createOrder(userWalletId)
onboardingRepository.getCustomerInfo(userWalletId = userWalletId)
.mapLeft { it.mapErrorForCustomer() }
.map { customerInfo ->
MainScreenCustomerInfo(info = customerInfo, orderStatus = orderStatus)
MainScreenCustomerInfo(info = customerInfo, orderStatus = orderData.status)
}
}
}

View file

@ -4,6 +4,7 @@ import arrow.core.Either
import com.tangem.core.error.UniversalError
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.pay.TangemPayWithdrawExchangeState
import com.tangem.domain.pay.WithdrawalResult
import java.math.BigDecimal
@ -14,5 +15,6 @@ interface TangemPayWithdrawUseCase {
cryptoAmount: BigDecimal,
cryptoCurrencyId: CryptoCurrency.RawID,
receiverCexAddress: String,
exchangeData: TangemPayWithdrawExchangeState,
): Either<UniversalError, WithdrawalResult>
}