diff --git a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt index fc56ae10a0..2f712579cc 100644 --- a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt +++ b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/DeepLinksRegistry.kt @@ -44,9 +44,9 @@ interface DeepLinksRegistry { /** * Triggers run last launched [Intent] with deeplink handlers that can handle delayed deeplink - * after handle [Intent] clear that and second time no intent will be handled + * of specific [deepLinkClass] after handle [Intent] clear that and second time no intent will be handled */ - fun triggerDelayedDeeplink() + fun triggerDelayedDeeplink(deepLinkClass: Class) fun cancelDelayedDeeplink() } \ No newline at end of file diff --git a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/impl/DefaultDeepLinksRegistry.kt b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/impl/DefaultDeepLinksRegistry.kt index 63f6f60d78..da6b6acfd8 100644 --- a/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/impl/DefaultDeepLinksRegistry.kt +++ b/core/deep-links/src/main/kotlin/com/tangem/core/deeplink/impl/DefaultDeepLinksRegistry.kt @@ -105,16 +105,18 @@ internal class DefaultDeepLinksRegistry : DeepLinksRegistry { val intent = lastIntent val received = intent?.data ?: return var hasMatch = false - registries.forEach { deepLink -> - if (!deepLink.shouldHandleDelayed) return@forEach - val expected = deepLink.uri.toUri() - if (!isMatches(expected, received)) return@forEach - hasMatch = true + registries + .filterIsInstance(deepLinkClass) + .forEach { deepLink -> + if (!deepLink.shouldHandleDelayed) return@forEach + val expected = deepLink.uri.toUri() + if (!isMatches(expected, received)) return@forEach + hasMatch = true - val params = getParams(expected, received) - logMatch(hasMatch, expected, received, params) - deepLink.onReceive(params) - } + val params = getParams(expected, received) + logMatch(hasMatch, expected, received, params) + deepLink.onReceive(params) + } if (!hasMatch) { logMatch(hasMatch, null, received, null) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt index 23569c3eee..817d98825d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt @@ -4,11 +4,15 @@ import androidx.compose.runtime.Stable import arrow.core.getOrElse import com.arkivanov.decompose.router.slot.activate import com.arkivanov.decompose.router.slot.dismiss +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.event.MainScreenAnalyticsEvent import com.tangem.core.decompose.di.ModelScoped import com.tangem.core.decompose.model.Model +import com.tangem.core.deeplink.DeepLinksRegistry +import com.tangem.core.deeplink.global.ReferralDeepLink import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.nft.FetchNFTCollectionsUseCase @@ -82,7 +86,9 @@ internal class WalletModel @Inject constructor( private val analyticsEventsHandler: AnalyticsEventHandler, private val fetchNFTCollectionsUseCase: FetchNFTCollectionsUseCase, private val walletsRepository: WalletsRepository, + private val deepLinksRegistry: DeepLinksRegistry, private val fetchCurrencyStatusUseCase: FetchCurrencyStatusUseCase, + private val appRouter: AppRouter, val screenLifecycleProvider: ScreenLifecycleProvider, val innerWalletRouter: InnerWalletRouter, ) : Model() { @@ -223,6 +229,7 @@ internal class WalletModel @Inject constructor( selectedWalletAnalyticsSender.send(selectedWallet) } + addReferralDeepLink(selectedWallet) walletDeepLinksHandler.registerForWallet(scope = modelScope, userWallet = selectedWallet) } .flowOn(dispatchers.main) @@ -230,6 +237,20 @@ internal class WalletModel @Inject constructor( } } + private fun addReferralDeepLink(userWallet: UserWallet) { + deepLinksRegistry.register( + ReferralDeepLink( + onReceive = { + if (userWallet.cardTypesResolver.isTangemWallet()) { + appRouter.push( + AppRoute.ReferralProgram(userWalletId = userWallet.walletId), + ) + } + }, + ), + ) + } + // We need to update the current wallet quotes if the application was in the background for more than 10 seconds // and then returned to the foreground private fun subscribeToScreenBackgroundState() { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/deeplink/WalletDeepLinksHandler.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/deeplink/WalletDeepLinksHandler.kt index 241307e17c..a0b28f06fd 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/deeplink/WalletDeepLinksHandler.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/deeplink/WalletDeepLinksHandler.kt @@ -6,9 +6,7 @@ import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.deeplink.DeepLink import com.tangem.core.deeplink.DeepLinksRegistry import com.tangem.core.deeplink.global.BuyCurrencyDeepLink -import com.tangem.core.deeplink.global.ReferralDeepLink import com.tangem.core.deeplink.global.SellCurrencyDeepLink -import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.tokens.GetCryptoCurrencyUseCase import com.tangem.domain.tokens.model.analytics.TokenScreenAnalyticsEvent import com.tangem.domain.wallets.models.UserWallet @@ -56,7 +54,6 @@ internal class WalletDeepLinksHandler @Inject constructor( ) return buildList { - addReferralDeepLink(userWallet) add(sellCurrencyDeepLink) if (onrampFeatureToggles.isFeatureEnabled || !userWallet.isMultiCurrency) { add( @@ -98,18 +95,4 @@ internal class WalletDeepLinksHandler @Inject constructor( analyticsEventHandler.send(TokenScreenAnalyticsEvent.Bought(cryptoCurrency.symbol)) } } - - private fun MutableList.addReferralDeepLink(userWallet: UserWallet) { - add( - ReferralDeepLink( - onReceive = { - if (userWallet.cardTypesResolver.isTangemWallet()) { - router.push( - AppRoute.ReferralProgram(userWalletId = userWallet.walletId), - ) - } - }, - ), - ) - } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/BasicTokenListSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/BasicTokenListSubscriber.kt index 34389c69a8..88c53fd3cf 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/BasicTokenListSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/BasicTokenListSubscriber.kt @@ -2,6 +2,8 @@ package com.tangem.feature.wallet.presentation.wallet.subscribers import arrow.core.getOrElse import com.tangem.core.deeplink.DeepLinksRegistry +import com.tangem.core.deeplink.global.ReferralDeepLink +import com.tangem.core.deeplink.global.SellCurrencyDeepLink import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.core.lce.Lce @@ -114,7 +116,10 @@ internal abstract class BasicTokenListSubscriber( protected open suspend fun onTokenListReceived(maybeTokenList: Lce) { /* no-op */ if (maybeTokenList.getOrNull(false) != null) { - deepLinksRegistry.triggerDelayedDeeplink() + deepLinksRegistry.triggerDelayedDeeplink(deepLinkClass = SellCurrencyDeepLink::class.java) + } + if (maybeTokenList.getOrNull(true) != null) { + deepLinksRegistry.triggerDelayedDeeplink(deepLinkClass = ReferralDeepLink::class.java) } }