Updated on 2026-08-14
This commit is contained in:
parent
06d1f35002
commit
6ed1946ac3
16 changed files with 191 additions and 220 deletions
|
|
@ -16,8 +16,8 @@ import com.tangem.data.visa.config.VisaLibLoader
|
|||
import com.tangem.data.visa.utils.*
|
||||
import com.tangem.datasource.api.visa.VisaApi
|
||||
import com.tangem.datasource.api.visa.models.response.VisaTxHistoryResponse
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.card.common.util.cardTypesResolver
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.models.wallet.requireColdWallet
|
||||
|
|
@ -40,7 +40,7 @@ internal class DefaultVisaRepository @Inject constructor(
|
|||
private val visaLibLoader: VisaLibLoader,
|
||||
private val quotesFetcher: QuotesFetcher,
|
||||
private val cacheRegistry: CacheRegistry,
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
private val userWalletsListRepository: UserWalletsListRepository,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
private val visaApiRequestMaker: VisaApiRequestMaker,
|
||||
private val visaApi: VisaApi,
|
||||
|
|
@ -176,7 +176,7 @@ internal class DefaultVisaRepository @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun makeAddress(userWalletId: UserWalletId): String {
|
||||
private fun makeAddress(userWalletId: UserWalletId): String {
|
||||
if (VisaConstants.IS_DEMO_MODE_ENABLED) return getDemoAddress()
|
||||
|
||||
val userWallet = findVisaUserWallet(userWalletId)
|
||||
|
|
@ -219,9 +219,7 @@ internal class DefaultVisaRepository @Inject constructor(
|
|||
}
|
||||
|
||||
private fun findVisaUserWallet(userWalletId: UserWalletId): UserWallet {
|
||||
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
|
||||
"No user wallet found: $userWalletId"
|
||||
}
|
||||
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
|
||||
if (!userWallet.requireColdWallet().scanResponse.cardTypesResolver.isVisaWallet()) {
|
||||
error("VISA wallet required: $userWalletId")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ import com.tangem.datasource.api.common.response.ApiResponseError
|
|||
import com.tangem.datasource.api.common.response.getOrThrow
|
||||
import com.tangem.datasource.api.pay.models.request.RefreshTokenByCardWalletRequest
|
||||
import com.tangem.datasource.api.visa.VisaApi
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.card.common.util.cardTypesResolver
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.common.wallets.update
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.models.wallet.requireColdWallet
|
||||
|
|
@ -23,7 +24,7 @@ import javax.inject.Inject
|
|||
typealias VisaAuthorizationHeader = String
|
||||
|
||||
internal class VisaApiRequestMaker @Inject constructor(
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
private val userWalletsListRepository: UserWalletsListRepository,
|
||||
private val visaAuthApi: VisaApi,
|
||||
private val accessCodeDataConverter: AccessCodeDataConverter,
|
||||
private val dispatcherProvider: CoroutineDispatcherProvider,
|
||||
|
|
@ -47,11 +48,11 @@ internal class VisaApiRequestMaker @Inject constructor(
|
|||
|
||||
val newTokens = runCatching {
|
||||
refreshAccessTokens(authTokens.refreshToken)
|
||||
}.getOrElse {
|
||||
if (it is ApiResponseError.HttpException &&
|
||||
it.code == ApiResponseError.HttpException.Code.UNAUTHORIZED
|
||||
}.getOrElse { throwable ->
|
||||
if (throwable is ApiResponseError.HttpException &&
|
||||
throwable.code == ApiResponseError.HttpException.Code.UNAUTHORIZED
|
||||
) {
|
||||
userWalletsStore.update(userWalletId) { userWallet ->
|
||||
userWalletsListRepository.update(userWalletId) { userWallet ->
|
||||
userWallet.requireColdWallet().copy(
|
||||
scanResponse = userWallet.scanResponse.copy(
|
||||
// visaCardActivationStatus = VisaCardActivationStatus.RefreshTokenExpired,
|
||||
|
|
@ -62,7 +63,7 @@ internal class VisaApiRequestMaker @Inject constructor(
|
|||
throw RefreshTokenExpiredException()
|
||||
}
|
||||
|
||||
userWalletsStore.update(userWalletId) { userWallet ->
|
||||
userWalletsListRepository.update(userWalletId) { userWallet ->
|
||||
userWallet.requireColdWallet().copy(
|
||||
scanResponse = userWallet.scanResponse.copy(
|
||||
// visaCardActivationStatus = VisaCardActivationStatus.Activated(
|
||||
|
|
@ -92,7 +93,7 @@ internal class VisaApiRequestMaker @Inject constructor(
|
|||
|
||||
@Throws
|
||||
private fun getAuthTokens(userWalletId: UserWalletId): VisaAuthTokens {
|
||||
val userWallet = findVisaUserWallet(userWalletId)
|
||||
findVisaUserWallet(userWalletId)
|
||||
// val status = userWallet.requireColdWallet().scanResponse.visaCardActivationStatus
|
||||
// ?: error("Visa card activation status not found")
|
||||
val status: VisaCardActivationStatus = TODO("Fix visaCardActivationStatus retrieval")
|
||||
|
|
@ -105,9 +106,7 @@ internal class VisaApiRequestMaker @Inject constructor(
|
|||
}
|
||||
|
||||
private fun findVisaUserWallet(userWalletId: UserWalletId): UserWallet {
|
||||
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
|
||||
"No user wallet found: $userWalletId"
|
||||
}
|
||||
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
|
||||
if (!userWallet.requireColdWallet().scanResponse.cardTypesResolver.isVisaWallet()) {
|
||||
error("VISA wallet required: $userWalletId")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue