Updated on 2026-08-14

This commit is contained in:
Tangem 2025-09-10 11:17:04 +04:00
parent 155e7e3d2c
commit e0a5bf6e9e
9 changed files with 63 additions and 28 deletions

View file

@ -1,7 +1,9 @@
package com.tangem.data.pay.di
import com.tangem.data.pay.repository.DefaultKycRepository
import com.tangem.data.pay.usecase.DefaultKycStartInfoUseCase
import com.tangem.domain.pay.repository.KycRepository
import com.tangem.domain.pay.usecase.KycStartInfoUseCase
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
@ -14,5 +16,9 @@ internal interface TangemPayDataModule {
@Binds
@Singleton
fun bindKycRepositoryFactory(factory: DefaultKycRepository.Factory): KycRepository.Factory
fun bindKycRepository(repository: DefaultKycRepository): KycRepository
@Binds
@Singleton
fun bindKycStartInfoUseCase(useCase: DefaultKycStartInfoUseCase): KycStartInfoUseCase
}

View file

@ -13,10 +13,9 @@ import com.tangem.domain.pay.KycStartInfo
import com.tangem.domain.pay.datasource.TangemPayAuthDataSource
import com.tangem.domain.pay.repository.KycRepository
import com.tangem.domain.visa.error.VisaApiError
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import javax.inject.Inject
class DefaultKycRepository @AssistedInject constructor(
class DefaultKycRepository @Inject constructor(
@NetworkMoshi moshi: Moshi,
private val tangemPayApi: TangemPayApi,
private val authDataSource: TangemPayAuthDataSource,
@ -65,9 +64,4 @@ class DefaultKycRepository @AssistedInject constructor(
return Either.Left(VisaApiError.UnknownWithoutCode)
}
}
@AssistedFactory
interface Factory : KycRepository.Factory {
override fun create(): DefaultKycRepository
}
}

View file

@ -0,0 +1,36 @@
package com.tangem.data.pay.usecase
import arrow.core.Either
import arrow.core.raise.either
import com.tangem.core.error.UniversalError
import com.tangem.domain.core.wallets.UserWalletsListRepository
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.pay.KycStartInfo
import com.tangem.domain.pay.repository.KycRepository
import com.tangem.domain.pay.usecase.KycStartInfoUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.visa.error.VisaApiError
import javax.inject.Inject
/**
* For TangemPay Customer Wallet auth we are using polygon address
*/
private const val POL_VALUE = "coin⟨POLYGON⟩polygon-ecosystem-token"
internal class DefaultKycStartInfoUseCase @Inject constructor(
private val userWalletsRepository: UserWalletsListRepository,
private val getCurrencyUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val kycRepository: KycRepository,
) : KycStartInfoUseCase {
override suspend fun invoke(): Either<UniversalError, KycStartInfo> = either {
val wallet = userWalletsRepository.userWalletsSync().find { it is UserWallet.Cold } as? UserWallet.Cold
?: raise(VisaApiError.UnknownWithoutCode)
val address = getCurrencyUseCase.invokeMultiWalletSync(wallet.walletId, CryptoCurrency.ID.fromValue(POL_VALUE))
.getOrNull()?.value?.networkAddress?.defaultAddress?.value ?: raise(VisaApiError.UnknownWithoutCode)
kycRepository.getKycStartInfo(address, wallet.cardId).bind()
}
}