Updated on 2026-08-14
This commit is contained in:
commit
21ae19f625
938 changed files with 40685 additions and 7487 deletions
|
|
@ -44,6 +44,7 @@ internal class DefaultTangemPayEligibilityManager @Inject constructor(
|
|||
|
||||
override suspend fun getTangemPayAvailability(): Boolean {
|
||||
return onboardingRepository.checkCustomerEligibility()
|
||||
.also { isEligible -> if (!isEligible) reset() }
|
||||
}
|
||||
|
||||
private suspend fun getUserWalletsData(): List<UserWalletData> {
|
||||
|
|
@ -120,7 +121,7 @@ internal class DefaultTangemPayEligibilityManager @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun reset() {
|
||||
override fun reset() {
|
||||
cachedEligibleWallets = null
|
||||
eligibleWalletsDeferred?.cancel()
|
||||
eligibleWalletsDeferred = null
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@ import java.util.concurrent.ConcurrentHashMap
|
|||
import javax.inject.Inject
|
||||
|
||||
private const val VALID_STATUS = "valid"
|
||||
private const val APPROVED_KYC_STATUS = "APPROVED"
|
||||
private const val APPROVED_KYC_STATUS = "approved"
|
||||
private const val IN_PROGRESS_KYC_STATUS = "in_progress"
|
||||
private const val DECLINED_KYC_STATUS = "declined"
|
||||
private const val TAG = "TangemPay: OnboardingRepository"
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
|
|
@ -168,8 +170,9 @@ internal class DefaultOnboardingRepository @Inject constructor(
|
|||
ProductInstance(id = instance.id, cardId = instance.cardId, cardFrozenState = cardFrozenState)
|
||||
}
|
||||
return CustomerInfo(
|
||||
customerId = response?.id,
|
||||
productInstance = productInstance,
|
||||
isKycApproved = response?.kyc?.status == APPROVED_KYC_STATUS,
|
||||
kycStatus = getKycStatus(status = response?.kyc?.status),
|
||||
cardInfo = cardInfo,
|
||||
).also {
|
||||
lastFetchedCustomerInfoMap[userWalletId] = it
|
||||
|
|
@ -182,11 +185,8 @@ internal class DefaultOnboardingRepository @Inject constructor(
|
|||
return Either.Right(hasTangemPay)
|
||||
}
|
||||
|
||||
return requestHelper.performWithStaticToken { staticToken ->
|
||||
tangemPayApi.checkCustomerWalletId(
|
||||
authHeader = staticToken,
|
||||
customerWalletId = userWalletId.stringValue,
|
||||
)
|
||||
return requestHelper.performWithStaticToken {
|
||||
tangemPayApi.checkCustomerWalletId(customerWalletId = userWalletId.stringValue)
|
||||
}.map { response ->
|
||||
val id = response.result?.id
|
||||
val isTangemPayEnabled = response.result?.isTangemPayEnabled == true
|
||||
|
|
@ -202,7 +202,7 @@ internal class DefaultOnboardingRepository @Inject constructor(
|
|||
}
|
||||
|
||||
override suspend fun checkCustomerEligibility(): Boolean {
|
||||
val response = requestHelper.performWithoutToken {
|
||||
val response = requestHelper.performWithStaticToken {
|
||||
tangemPayApi.checkCustomerEligibility()
|
||||
}.getOrNull()
|
||||
|
||||
|
|
@ -236,4 +236,13 @@ internal class DefaultOnboardingRepository @Inject constructor(
|
|||
setHideMainOnboardingBanner(userWalletId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getKycStatus(status: String?): CustomerInfo.KycStatus {
|
||||
return when (status?.lowercase()) {
|
||||
IN_PROGRESS_KYC_STATUS -> CustomerInfo.KycStatus.PENDING
|
||||
DECLINED_KYC_STATUS -> CustomerInfo.KycStatus.REJECTED
|
||||
APPROVED_KYC_STATUS -> CustomerInfo.KycStatus.APPROVED
|
||||
else -> CustomerInfo.KycStatus.INIT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,6 @@ import com.tangem.datasource.api.common.response.ApiResponse
|
|||
import com.tangem.datasource.api.pay.TangemPayAuthApi
|
||||
import com.tangem.datasource.api.pay.models.request.RefreshCustomerWalletAccessTokenRequest
|
||||
import com.tangem.datasource.api.pay.models.response.TangemPayGetTokensResponse
|
||||
import com.tangem.datasource.local.config.environment.EnvironmentConfigStorage
|
||||
import com.tangem.datasource.local.visa.TangemPayStorage
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.visa.error.VisaApiError
|
||||
|
|
@ -32,7 +31,6 @@ private const val TAG = "TangemPayRequestPerformer"
|
|||
@Singleton
|
||||
internal class TangemPayRequestPerformer @Inject constructor(
|
||||
private val errorConverter: TangemPayErrorConverter,
|
||||
private val environmentConfigStorage: EnvironmentConfigStorage,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
private val tangemPayAuthApi: TangemPayAuthApi,
|
||||
private val tangemPayStorage: TangemPayStorage,
|
||||
|
|
@ -41,23 +39,10 @@ internal class TangemPayRequestPerformer @Inject constructor(
|
|||
private val customerWalletAddresses = ConcurrentHashMap<UserWalletId, String>()
|
||||
private val tokensMutex = Mutex()
|
||||
|
||||
suspend fun <T : Any> performWithStaticToken(
|
||||
requestBlock: suspend (header: String) -> ApiResponse<T>,
|
||||
): Either<VisaApiError, T> = withContext(dispatchers.io) {
|
||||
catch(
|
||||
block = {
|
||||
val staticToken =
|
||||
environmentConfigStorage.getConfigSync().bffStaticToken ?: error("BFF static token is null")
|
||||
when (val apiResponse = requestBlock(staticToken)) {
|
||||
is ApiResponse.Error -> errorConverter.convert(apiResponse.cause).left()
|
||||
is ApiResponse.Success<T> -> apiResponse.data.right()
|
||||
}
|
||||
},
|
||||
catch = { errorConverter.convert(it).left() },
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun <T : Any> performWithoutToken(requestBlock: suspend () -> ApiResponse<T>): Either<VisaApiError, T> =
|
||||
/**
|
||||
* Static token added in headers [com.tangem.datasource.api.common.config.TangemPay]
|
||||
*/
|
||||
suspend fun <T : Any> performWithStaticToken(requestBlock: suspend () -> ApiResponse<T>): Either<VisaApiError, T> =
|
||||
withContext(dispatchers.io) {
|
||||
catch(
|
||||
block = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue