Updated on 2026-08-14

This commit is contained in:
Tangem 2025-04-01 09:06:11 +03:00
parent ded577faff
commit aea7f5f415
21 changed files with 220 additions and 136 deletions

View file

@ -27,6 +27,7 @@ dependencies {
implementation(projects.core.decompose)
implementation(projects.core.navigation)
implementation(projects.core.datasource)
implementation(projects.core.error.ext)
/** Common */
implementation(projects.common.ui)

View file

@ -7,6 +7,11 @@ import com.tangem.common.extensions.toHexString
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.decompose.ui.UiMessageSender
import com.tangem.core.error.ext.universalError
import com.tangem.core.ui.utils.showErrorDialog
import com.tangem.domain.visa.error.VisaAPIError
import com.tangem.domain.visa.error.VisaAuthorizationAPIError
import com.tangem.domain.visa.model.VisaCardActivationStatus
import com.tangem.domain.visa.model.VisaCardId
import com.tangem.domain.visa.model.VisaCustomerWalletDataToSignRequest
@ -34,6 +39,7 @@ internal class OnboardingVisaAccessCodeModel @Inject constructor(
@Suppress("UnusedPrivateMember")
private val tangemSdkManager: TangemSdkManager,
private val visaAuthRepository: VisaAuthRepository,
private val uiMessageSender: UiMessageSender,
) : Model() {
private val params: OnboardingVisaAccessCodeComponent.Config = paramsContainer.require()
@ -138,7 +144,7 @@ internal class OnboardingVisaAccessCodeModel @Inject constructor(
)
}.getOrElse {
loading(false)
// TODO show alert
uiMessageSender.showErrorDialog(VisaAuthorizationAPIError)
return@launch
}
@ -148,17 +154,22 @@ internal class OnboardingVisaAccessCodeModel @Inject constructor(
authorizationChallenge = challengeToSign,
),
activationInput = activationStatus.activationInput,
) as? CompletionResult.Success ?: run {
loading(false)
// TODO show alert
return@launch
)
val resultData = when (result) {
is CompletionResult.Failure -> {
loading(false)
uiMessageSender.showErrorDialog(result.error.universalError)
return@launch
}
is CompletionResult.Success -> result.data
}
runCatching {
visaActivationRepository.activateCard(result.data.signedActivationData)
visaActivationRepository.activateCard(resultData.signedActivationData)
}.onFailure {
loading(false)
// TODO show alert
uiMessageSender.showErrorDialog(VisaAPIError)
return@launch
}

View file

@ -6,6 +6,10 @@ import com.tangem.common.extensions.toHexString
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.decompose.ui.UiMessageSender
import com.tangem.core.error.ext.universalError
import com.tangem.core.ui.utils.showErrorDialog
import com.tangem.domain.visa.error.VisaAPIError
import com.tangem.domain.visa.model.VisaCardId
import com.tangem.domain.visa.model.VisaDataForApprove
import com.tangem.domain.visa.repository.VisaActivationRepository
@ -27,6 +31,7 @@ internal class OnboardingVisaApproveModel @Inject constructor(
visaActivationRepositoryFactory: VisaActivationRepository.Factory,
override val dispatchers: CoroutineDispatcherProvider,
private val tangemSdkManager: TangemSdkManager,
private val uiMessageSender: UiMessageSender,
) : Model() {
private val params = paramsContainer.require<OnboardingVisaApproveComponent.Config>()
@ -56,7 +61,7 @@ internal class OnboardingVisaApproveModel @Inject constructor(
visaActivationRepository.getCustomerWalletAcceptanceData(params.preparationDataForApprove.request)
}.getOrElse {
loading(false)
// TODO show dialog
uiMessageSender.showErrorDialog(VisaAPIError)
return@launch
}
@ -66,17 +71,22 @@ internal class OnboardingVisaApproveModel @Inject constructor(
targetAddress = params.preparationDataForApprove.customerWalletAddress,
dataToSign = dataToSign,
),
) as? CompletionResult.Success ?: run {
loading(false)
// TODO show dialog
return@launch
)
val resultData = when (result) {
is CompletionResult.Failure -> {
loading(false)
uiMessageSender.showErrorDialog(result.error.universalError)
return@launch
}
is CompletionResult.Success -> result.data
}
runCatching {
visaActivationRepository.approveByCustomerWallet(result.data)
visaActivationRepository.approveByCustomerWallet(resultData)
}.onFailure {
loading(false)
// TODO show dialog
uiMessageSender.showErrorDialog(VisaAPIError)
return@launch
}

View file

@ -5,9 +5,13 @@ import com.tangem.common.extensions.toHexString
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.decompose.ui.UiMessageSender
import com.tangem.core.ui.utils.showErrorDialog
import com.tangem.datasource.local.visa.VisaAuthTokenStorage
import com.tangem.datasource.local.visa.VisaOTPStorage
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.visa.error.VisaActivationError
import com.tangem.domain.visa.error.VisaAuthorizationAPIError
import com.tangem.domain.visa.model.*
import com.tangem.domain.visa.repository.VisaActivationRepository
import com.tangem.domain.visa.repository.VisaAuthRepository
@ -36,6 +40,7 @@ internal class OnboardingVisaInProgressModel @Inject constructor(
private val otpStorage: VisaOTPStorage,
private val userWalletBuilderFactory: UserWalletBuilder.Factory,
private val userWalletsListManager: UserWalletsListManager,
private val uiMessageSender: UiMessageSender,
) : Model() {
private val params = paramsContainer.require<Config>()
@ -58,7 +63,7 @@ internal class OnboardingVisaInProgressModel @Inject constructor(
is VisaActivationRemoteState.CardWalletSignatureRequired,
VisaActivationRemoteState.BlockedForActivation,
-> {
// TODO show alert inconsistent state
uiMessageSender.showErrorDialog(VisaActivationError.InconsistentRemoteState)
return@launch
}
is VisaActivationRemoteState.CustomerWalletSignatureRequired,
@ -92,7 +97,7 @@ internal class OnboardingVisaInProgressModel @Inject constructor(
val newTokens = runCatching {
visaAuthRepository.refreshAccessTokens(authTokens.refreshToken)
}.getOrElse {
// TODO show alert
uiMessageSender.showErrorDialog(VisaAuthorizationAPIError)
return
}

View file

@ -5,6 +5,10 @@ import com.tangem.common.extensions.toHexString
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.decompose.ui.UiMessageSender
import com.tangem.core.error.ext.universalError
import com.tangem.core.ui.utils.showErrorDialog
import com.tangem.domain.visa.error.VisaAPIError
import com.tangem.domain.visa.model.VisaCardId
import com.tangem.domain.visa.model.VisaCustomerWalletDataToSignRequest
import com.tangem.domain.visa.repository.VisaActivationRepository
@ -28,6 +32,7 @@ internal class OnboardingVisaWelcomeModel @Inject constructor(
override val dispatchers: CoroutineDispatcherProvider,
private val tangemSdkManager: TangemSdkManager,
private val visaActivationRepositoryFactory: VisaActivationRepository.Factory,
private val uiMessageSender: UiMessageSender,
) : Model() {
private val params = paramsContainer.require<Config>()
@ -68,24 +73,29 @@ internal class OnboardingVisaWelcomeModel @Inject constructor(
visaActivationRepository.getCardWalletAcceptanceData(params.dataToSignRequest)
}.getOrElse {
loading(false)
// TODO show alert
uiMessageSender.showErrorDialog(VisaAPIError)
return@launch
}
val result = tangemSdkManager.activateVisaCard(
mode = VisaCardActivationTaskMode.SignOnly(dataToSignByCardWallet = dataToSignByCardWallet),
activationInput = params.activationInput,
) as? CompletionResult.Success ?: run {
loading(false)
// TODO show alert
return@launch
)
val resultData = when (result) {
is CompletionResult.Failure -> {
loading(false)
uiMessageSender.showErrorDialog(result.error.universalError)
return@launch
}
is CompletionResult.Success -> result.data
}
runCatching {
visaActivationRepository.activateCard(result.data.signedActivationData)
visaActivationRepository.activateCard(resultData.signedActivationData)
}.onFailure {
loading(false)
// TODO show alert
uiMessageSender.showErrorDialog(VisaAPIError)
return@launch
}