Updated on 2026-08-14
This commit is contained in:
parent
c925d7cf61
commit
fe3b35379b
2 changed files with 18 additions and 2 deletions
|
|
@ -66,10 +66,12 @@ internal interface TangemPayDataModule {
|
|||
fun provideTangemPayMainScreenCustomerInfoUseCase(
|
||||
repository: OnboardingRepository,
|
||||
customerOrderRepository: CustomerOrderRepository,
|
||||
tangemPayOnboardingRepository: OnboardingRepository,
|
||||
): TangemPayMainScreenCustomerInfoUseCase {
|
||||
return TangemPayMainScreenCustomerInfoUseCase(
|
||||
repository = repository,
|
||||
customerOrderRepository = customerOrderRepository,
|
||||
tangemPayOnboardingRepository = tangemPayOnboardingRepository,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,16 +23,22 @@ private const val TAG = "TangemPayMainScreenCustomerInfoUseCase"
|
|||
class TangemPayMainScreenCustomerInfoUseCase(
|
||||
private val repository: OnboardingRepository,
|
||||
private val customerOrderRepository: CustomerOrderRepository,
|
||||
private val tangemPayOnboardingRepository: OnboardingRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
): Either<TangemPayCustomerInfoError, MainScreenCustomerInfo> = catch(
|
||||
block = {
|
||||
Timber.tag(TAG).d("checkCustomerWallet")
|
||||
repository.checkCustomerWallet(userWalletId)
|
||||
.fold(
|
||||
ifLeft = { TangemPayCustomerInfoError.UnknownError.left() },
|
||||
ifLeft = { error ->
|
||||
Timber.tag(TAG).e("Failed to check customer wallet ${error.javaClass.simpleName}")
|
||||
TangemPayCustomerInfoError.UnknownError.left()
|
||||
},
|
||||
ifRight = { hasTangemPay ->
|
||||
Timber.tag(TAG).i("checkCustomerWallet $hasTangemPay")
|
||||
if (hasTangemPay) {
|
||||
proceedWithPaeraCustomerResult(userWalletId)
|
||||
} else {
|
||||
|
|
@ -50,6 +56,9 @@ class TangemPayMainScreenCustomerInfoUseCase(
|
|||
private suspend fun proceedWithPaeraCustomerResult(
|
||||
userWalletId: UserWalletId,
|
||||
): Either<TangemPayCustomerInfoError, MainScreenCustomerInfo> {
|
||||
if (!tangemPayOnboardingRepository.isTangemPayInitialDataProduced(userWalletId)) {
|
||||
return TangemPayCustomerInfoError.RefreshNeededError.left()
|
||||
}
|
||||
val orderId = repository.getOrderId(userWalletId)
|
||||
return if (orderId != null) {
|
||||
proceedWithOrderId(userWalletId = userWalletId, orderId = orderId)
|
||||
|
|
@ -61,9 +70,14 @@ class TangemPayMainScreenCustomerInfoUseCase(
|
|||
private suspend fun proceedWithoutOrder(
|
||||
userWalletId: UserWalletId,
|
||||
): Either<TangemPayCustomerInfoError, MainScreenCustomerInfo> {
|
||||
Timber.tag(TAG).d("proceedWithoutOrder")
|
||||
return repository.getCustomerInfo(userWalletId)
|
||||
.mapLeft { error -> error.mapErrorForCustomer() }
|
||||
.mapLeft { error ->
|
||||
Timber.tag(TAG).e("mapErrorForCustomer: $error")
|
||||
error.mapErrorForCustomer()
|
||||
}
|
||||
.map { customerInfo ->
|
||||
Timber.tag(TAG).d("customerInfo")
|
||||
if (customerInfo.cardInfo == null && customerInfo.isKycApproved) {
|
||||
// If order id wasn't saved -> start order creation and get customer info
|
||||
repository.createOrder(userWalletId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue