Updated on 2026-08-14
This commit is contained in:
parent
155e7e3d2c
commit
e0a5bf6e9e
9 changed files with 63 additions and 28 deletions
|
|
@ -27,6 +27,7 @@ dependencies {
|
|||
implementation(projects.domain.wallets.models)
|
||||
implementation(projects.domain.appCurrency.models)
|
||||
implementation(projects.domain.tokens.models)
|
||||
implementation(projects.domain.tokens)
|
||||
|
||||
/** Project - Utils */
|
||||
implementation(projects.core.utils)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
@ -15,8 +15,4 @@ interface KycRepository {
|
|||
* Returns KYC data to continue the survey. Used when KYC wasn't finished by the user
|
||||
*/
|
||||
suspend fun getKycStartInfo(authHeader: String): Either<UniversalError, KycStartInfo>
|
||||
|
||||
interface Factory {
|
||||
fun create(): KycRepository
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.domain.pay.usecase
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.core.error.UniversalError
|
||||
import com.tangem.domain.pay.KycStartInfo
|
||||
|
||||
interface KycStartInfoUseCase {
|
||||
|
||||
suspend operator fun invoke(): Either<UniversalError, KycStartInfo>
|
||||
}
|
||||
|
|
@ -4,14 +4,9 @@ import com.tangem.core.decompose.context.AppComponentContext
|
|||
|
||||
interface KycComponent {
|
||||
|
||||
fun launch(params: Params)
|
||||
fun launch()
|
||||
|
||||
interface Factory {
|
||||
fun create(appComponentContext: AppComponentContext): KycComponent
|
||||
}
|
||||
|
||||
data class Params(
|
||||
val targetAddress: String,
|
||||
val cardId: String,
|
||||
)
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ class DefaultKycComponent @AssistedInject constructor(
|
|||
|
||||
private val model: DefaultKycModel = getOrCreateModel()
|
||||
|
||||
override fun launch(params: KycComponent.Params) {
|
||||
override fun launch() {
|
||||
componentScope.launch {
|
||||
model.uiState.collect {
|
||||
it?.let { startInfo ->
|
||||
|
|
@ -35,7 +35,7 @@ class DefaultKycComponent @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
model.getKycToken(params)
|
||||
model.getKycToken()
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import androidx.compose.runtime.Stable
|
|||
import com.tangem.core.decompose.di.ModelScoped
|
||||
import com.tangem.core.decompose.model.Model
|
||||
import com.tangem.domain.pay.KycStartInfo
|
||||
import com.tangem.domain.pay.repository.KycRepository
|
||||
import com.tangem.domain.pay.usecase.KycStartInfoUseCase
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
|
@ -15,18 +15,15 @@ import javax.inject.Inject
|
|||
@ModelScoped
|
||||
class DefaultKycModel @Inject constructor(
|
||||
override val dispatchers: CoroutineDispatcherProvider,
|
||||
kycRepositoryFactory: KycRepository.Factory,
|
||||
private val kycStartInfoUseCase: KycStartInfoUseCase,
|
||||
) : Model() {
|
||||
|
||||
private val kycRepository = kycRepositoryFactory.create()
|
||||
|
||||
private val _uiState: MutableStateFlow<KycStartInfo?> = MutableStateFlow(null)
|
||||
val uiState = _uiState.asStateFlow()
|
||||
|
||||
fun getKycToken(params: KycComponent.Params) {
|
||||
fun getKycToken() {
|
||||
modelScope.launch {
|
||||
kycRepository.getKycStartInfo(address = params.targetAddress, cardId = params.cardId).getOrNull()
|
||||
?.let { _uiState.emit(it) }
|
||||
kycStartInfoUseCase().getOrNull()?.let { _uiState.emit(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue