Updated on 2026-08-14
This commit is contained in:
parent
775a03b038
commit
1bb825744e
3 changed files with 51 additions and 30 deletions
|
|
@ -3,6 +3,7 @@ package com.tangem.data.pay
|
|||
import com.tangem.common.card.FirmwareVersion
|
||||
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.isLocked
|
||||
import com.tangem.domain.models.wallet.isMultiCurrency
|
||||
import com.tangem.domain.pay.TangemPayEligibilityManager
|
||||
|
|
@ -40,6 +41,12 @@ internal class DefaultTangemPayEligibilityManager @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun getPossibleWalletsIds(shouldExcludePaeraCustomers: Boolean): List<UserWalletId> {
|
||||
return getPossibleWalletsForTangemPay().addPaeraCustomersData().mapNotNull {
|
||||
if (!it.isPaeraCustomer || !shouldExcludePaeraCustomers) it.userWallet.walletId else null
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getTangemPayAvailability(): Boolean {
|
||||
return onboardingRepository.checkCustomerEligibility()
|
||||
.also { isEligible -> if (!isEligible) reset() }
|
||||
|
|
@ -58,9 +65,13 @@ internal class DefaultTangemPayEligibilityManager @Inject constructor(
|
|||
|
||||
coroutineScope {
|
||||
val deferred = async {
|
||||
getPossibleWalletsForTangemPay()
|
||||
.addPaeraCustomersData()
|
||||
.also { cachedEligibleWallets = it }
|
||||
if (!checkTangemPayEligibility()) {
|
||||
emptyList()
|
||||
} else {
|
||||
getPossibleWalletsForTangemPay()
|
||||
.addPaeraCustomersData()
|
||||
.also { cachedEligibleWallets = it }
|
||||
}
|
||||
}
|
||||
eligibleWalletsDeferred = deferred
|
||||
try {
|
||||
|
|
@ -72,11 +83,7 @@ internal class DefaultTangemPayEligibilityManager @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun getPossibleWalletsForTangemPay(): List<UserWallet> {
|
||||
if (!checkTangemPayEligibility()) {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
private fun getPossibleWalletsForTangemPay(): List<UserWallet> {
|
||||
val wallets = if (hotWalletFeatureToggles.isHotWalletEnabled) {
|
||||
userWalletsListRepository.userWallets.value
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,21 @@
|
|||
package com.tangem.domain.pay
|
||||
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
|
||||
interface TangemPayEligibilityManager {
|
||||
|
||||
suspend fun getEligibleWallets(shouldExcludePaeraCustomers: Boolean): List<UserWallet>
|
||||
|
||||
/**
|
||||
* Returns all compatible user wallets without checking Tangem Pay eligibility, only used when opening deeplink
|
||||
* Remove after removing [TangemPayOnboardingComponent.Params.Deeplink]
|
||||
* */
|
||||
suspend fun getPossibleWalletsIds(shouldExcludePaeraCustomers: Boolean): List<UserWalletId>
|
||||
|
||||
suspend fun getTangemPayAvailability(): Boolean
|
||||
|
||||
suspend fun isPaeraCustomerForAnyWallet(): Boolean
|
||||
|
||||
fun reset()
|
||||
}
|
||||
|
|
@ -116,37 +116,41 @@ internal class TangemPayOnboardingModel @Inject constructor(
|
|||
|
||||
private fun onGetCardClick() {
|
||||
analytics.send(TangemPayAnalyticsEvents.GetCardClicked())
|
||||
// if user came from deeplink or banner in settings and already is a paera customer -> exclude this wallet
|
||||
val shouldExcludePaeraCustomers = params is TangemPayOnboardingComponent.Params.FromBannerInSettings ||
|
||||
params is TangemPayOnboardingComponent.Params.Deeplink
|
||||
modelScope.launch {
|
||||
val eligibleWalletsIds = eligibilityManager
|
||||
.getEligibleWallets(shouldExcludePaeraCustomers = shouldExcludePaeraCustomers)
|
||||
.map { it.walletId }
|
||||
if (eligibleWalletsIds.isEmpty()) {
|
||||
back()
|
||||
return@launch
|
||||
if (params is TangemPayOnboardingComponent.Params.Deeplink) {
|
||||
modelScope.launch {
|
||||
openWalletSelectorIfNeeds(
|
||||
walletsIds = eligibilityManager.getPossibleWalletsIds(shouldExcludePaeraCustomers = true),
|
||||
)
|
||||
}
|
||||
when (params) {
|
||||
is TangemPayOnboardingComponent.Params.ContinueOnboarding -> {
|
||||
checkCustomerInfo(params.userWalletId)
|
||||
} else {
|
||||
// if user came from banner in settings and already is a paera customer -> exclude this wallet
|
||||
val shouldExcludePaeraCustomers = params is TangemPayOnboardingComponent.Params.FromBannerInSettings
|
||||
modelScope.launch {
|
||||
val eligibleWalletsIds = eligibilityManager
|
||||
.getEligibleWallets(shouldExcludePaeraCustomers = shouldExcludePaeraCustomers)
|
||||
.map { it.walletId }
|
||||
if (eligibleWalletsIds.isEmpty()) {
|
||||
back()
|
||||
return@launch
|
||||
}
|
||||
is TangemPayOnboardingComponent.Params.FromBannerOnMain,
|
||||
is TangemPayOnboardingComponent.Params.Deeplink,
|
||||
is TangemPayOnboardingComponent.Params.FromBannerInSettings,
|
||||
-> {
|
||||
openWalletSelectorIfNeeds(eligibleWalletsIds)
|
||||
when (params) {
|
||||
is TangemPayOnboardingComponent.Params.ContinueOnboarding -> {
|
||||
checkCustomerInfo(params.userWalletId)
|
||||
}
|
||||
else -> {
|
||||
openWalletSelectorIfNeeds(eligibleWalletsIds)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun openWalletSelectorIfNeeds(eligibleWalletsIds: List<UserWalletId>) {
|
||||
if (eligibleWalletsIds.size == 1) {
|
||||
checkCustomerInfo(userWalletId = eligibleWalletsIds[0])
|
||||
private fun openWalletSelectorIfNeeds(walletsIds: List<UserWalletId>) {
|
||||
if (walletsIds.size == 1) {
|
||||
checkCustomerInfo(userWalletId = walletsIds[0])
|
||||
} else {
|
||||
analytics.send(TangemPayAnalyticsEvents.ChooseWalletPopup())
|
||||
bottomSheetNavigation.activate(TangemPayOnboardingNavigation.WalletSelector(eligibleWalletsIds))
|
||||
bottomSheetNavigation.activate(TangemPayOnboardingNavigation.WalletSelector(walletsIds))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue