Updated on 2026-08-14

This commit is contained in:
Tangem 2025-05-30 14:08:42 +03:00
parent e33bd4d849
commit b98b0f659c
138 changed files with 686 additions and 346 deletions

View file

@ -24,6 +24,7 @@ import com.tangem.domain.visa.model.VisaTxHistoryItem
import com.tangem.domain.visa.repository.VisaRepository
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.models.requireColdWallet
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
@ -142,7 +143,7 @@ internal class DefaultVisaRepository @Inject constructor(
txDetailsFactory.create(
transaction = transaction,
walletBlockchain = userWallet.scanResponse.cardTypesResolver.getBlockchain(),
walletBlockchain = userWallet.requireColdWallet().scanResponse.cardTypesResolver.getBlockchain(),
)
}
}
@ -153,7 +154,7 @@ internal class DefaultVisaRepository @Inject constructor(
val customerInfo = visaApiRequestMaker.request(userWalletId) { authHeader, _ ->
visaApi.getCustomerInfo(
authHeader = authHeader,
cardId = userWallet.scanResponse.card.cardId,
cardId = userWallet.requireColdWallet().scanResponse.card.cardId,
)
}
@ -198,7 +199,7 @@ internal class DefaultVisaRepository @Inject constructor(
}
private fun makeWalletAddresses(userWallet: UserWallet): Set<Address> {
val walletBlockchain = userWallet.scanResponse.cardTypesResolver.getBlockchain()
val walletBlockchain = userWallet.requireColdWallet().scanResponse.cardTypesResolver.getBlockchain()
return walletBlockchain.makeAddresses(getCardPubKey(userWallet).hexToBytes())
}
@ -206,7 +207,7 @@ internal class DefaultVisaRepository @Inject constructor(
private fun getCardPubKey(userWallet: UserWallet): String {
if (VisaConstants.IS_DEMO_MODE_ENABLED) return getDemoPublicKey()
val cardWallet = userWallet.scanResponse.card.wallets.firstOrNull {
val cardWallet = userWallet.requireColdWallet().scanResponse.card.wallets.firstOrNull {
it.curve == EllipticCurve.Secp256k1
}
requireNotNull(cardWallet) { "Visa card wallet not found" }
@ -218,7 +219,7 @@ internal class DefaultVisaRepository @Inject constructor(
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
"No user wallet found: $userWalletId"
}
if (!userWallet.scanResponse.cardTypesResolver.isVisaWallet()) {
if (!userWallet.requireColdWallet().scanResponse.cardTypesResolver.isVisaWallet()) {
error("VISA wallet required: $userWalletId")
}

View file

@ -15,6 +15,7 @@ import com.tangem.domain.visa.model.VisaCardActivationStatus
import com.tangem.domain.visa.model.getAuthHeader
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.models.requireColdWallet
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.withContext
import javax.inject.Inject
@ -52,7 +53,7 @@ internal class VisaApiRequestMaker @Inject constructor(
it.code == ApiResponseError.HttpException.Code.UNAUTHORIZED
) {
userWalletsStore.update(userWalletId) { userWallet ->
userWallet.copy(
userWallet.requireColdWallet().copy(
scanResponse = userWallet.scanResponse.copy(
visaCardActivationStatus = VisaCardActivationStatus.RefreshTokenExpired,
),
@ -63,7 +64,7 @@ internal class VisaApiRequestMaker @Inject constructor(
}
userWalletsStore.update(userWalletId) { userWallet ->
userWallet.copy(
userWallet.requireColdWallet().copy(
scanResponse = userWallet.scanResponse.copy(
visaCardActivationStatus = VisaCardActivationStatus.Activated(
visaAuthTokens = newTokens,
@ -93,7 +94,8 @@ internal class VisaApiRequestMaker @Inject constructor(
@Throws
private fun getAuthTokens(userWalletId: UserWalletId): VisaAuthTokens {
val userWallet = findVisaUserWallet(userWalletId)
val status = userWallet.scanResponse.visaCardActivationStatus ?: error("Visa card activation status not found")
val status = userWallet.requireColdWallet().scanResponse.visaCardActivationStatus
?: error("Visa card activation status not found")
if (status is VisaCardActivationStatus.RefreshTokenExpired) {
throw RefreshTokenExpiredException()
@ -106,7 +108,7 @@ internal class VisaApiRequestMaker @Inject constructor(
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
"No user wallet found: $userWalletId"
}
if (!userWallet.scanResponse.cardTypesResolver.isVisaWallet()) {
if (!userWallet.requireColdWallet().scanResponse.cardTypesResolver.isVisaWallet()) {
error("VISA wallet required: $userWalletId")
}

View file

@ -8,6 +8,7 @@ import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.NetworkAddress
import com.tangem.domain.visa.model.VisaCurrency
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.models.requireColdWallet
import com.tangem.lib.visa.model.VisaContractInfo
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
@ -33,7 +34,7 @@ internal class VisaCurrencyFactory @Inject constructor(
val currencyNetwork = networkFactory.create(
blockchain = Blockchain.Polygon,
extraDerivationPath = null,
derivationStyleProvider = userWallet.scanResponse.derivationStyleProvider,
derivationStyleProvider = userWallet.requireColdWallet().scanResponse.derivationStyleProvider,
canHandleTokens = true,
) ?: error("Unable to create network for Visa currency")