From e70595047c06f7412a8c5738331f113024164992 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 16 May 2025 12:25:41 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../deeplink/global/BuyCurrencyDeepLink.kt | 1 + .../onramp/deeplink/BuyDeepLinkHandler.kt | 10 ++++ .../deeplink/DefaultBuyDeepLinkHandler.kt | 48 +++++++++++++++++++ .../deeplink/di/OnrampDeeplinkModule.kt | 7 ++- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 features/onramp/api/src/main/kotlin/com/tangem/features/onramp/deeplink/BuyDeepLinkHandler.kt create mode 100644 features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/deeplink/DefaultBuyDeepLinkHandler.kt diff --git a/core/deep-links/global/src/main/kotlin/com/tangem/core/deeplink/global/BuyCurrencyDeepLink.kt b/core/deep-links/global/src/main/kotlin/com/tangem/core/deeplink/global/BuyCurrencyDeepLink.kt index 90f79f358c..ff3cdaf90f 100644 --- a/core/deep-links/global/src/main/kotlin/com/tangem/core/deeplink/global/BuyCurrencyDeepLink.kt +++ b/core/deep-links/global/src/main/kotlin/com/tangem/core/deeplink/global/BuyCurrencyDeepLink.kt @@ -2,6 +2,7 @@ package com.tangem.core.deeplink.global import com.tangem.core.deeplink.DeepLink +@Deprecated("Use BuyDeepLinkHandler") class BuyCurrencyDeepLink( val onReceive: () -> Unit, ) : DeepLink() { diff --git a/features/onramp/api/src/main/kotlin/com/tangem/features/onramp/deeplink/BuyDeepLinkHandler.kt b/features/onramp/api/src/main/kotlin/com/tangem/features/onramp/deeplink/BuyDeepLinkHandler.kt new file mode 100644 index 0000000000..75c2d61f29 --- /dev/null +++ b/features/onramp/api/src/main/kotlin/com/tangem/features/onramp/deeplink/BuyDeepLinkHandler.kt @@ -0,0 +1,10 @@ +package com.tangem.features.onramp.deeplink + +import kotlinx.coroutines.CoroutineScope + +interface BuyDeepLinkHandler { + + interface Factory { + fun create(coroutineScope: CoroutineScope): BuyDeepLinkHandler + } +} \ No newline at end of file diff --git a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/deeplink/DefaultBuyDeepLinkHandler.kt b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/deeplink/DefaultBuyDeepLinkHandler.kt new file mode 100644 index 0000000000..07c655873a --- /dev/null +++ b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/deeplink/DefaultBuyDeepLinkHandler.kt @@ -0,0 +1,48 @@ +package com.tangem.features.onramp.deeplink + +import arrow.core.getOrElse +import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.domain.tokens.GetCryptoCurrencyUseCase +import com.tangem.domain.tokens.model.analytics.TokenScreenAnalyticsEvent +import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase +import com.tangem.features.onramp.OnrampFeatureToggles +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch +import timber.log.Timber + +internal class DefaultBuyDeepLinkHandler @AssistedInject constructor( + @Assisted scope: CoroutineScope, + onrampFeatureToggles: OnrampFeatureToggles, + getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, + getCryptoCurrencyUseCase: GetCryptoCurrencyUseCase, + analyticsEventHandler: AnalyticsEventHandler, +) : BuyDeepLinkHandler { + + init { + // It is okay here, we are navigating from outside, and there is no other way to getting UserWallet + getSelectedWalletSyncUseCase().fold( + ifLeft = { + Timber.e("Error on getting user wallet: $it") + }, + ifRight = { userWallet -> + if (!onrampFeatureToggles.isFeatureEnabled && !userWallet.isMultiCurrency) { + scope.launch { + val cryptoCurrency = getCryptoCurrencyUseCase(userWallet.walletId).getOrElse { + Timber.e("Error on getting cryptoCurrency: $it") + return@launch + } + analyticsEventHandler.send(TokenScreenAnalyticsEvent.Bought(cryptoCurrency.symbol)) + } + } + }, + ) + } + + @AssistedFactory + interface Factory : BuyDeepLinkHandler.Factory { + override fun create(coroutineScope: CoroutineScope): DefaultBuyDeepLinkHandler + } +} \ No newline at end of file diff --git a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/deeplink/di/OnrampDeeplinkModule.kt b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/deeplink/di/OnrampDeeplinkModule.kt index fc55367fe3..418baeccc3 100644 --- a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/deeplink/di/OnrampDeeplinkModule.kt +++ b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/deeplink/di/OnrampDeeplinkModule.kt @@ -1,7 +1,6 @@ package com.tangem.features.onramp.deeplink.di import com.tangem.features.onramp.deeplink.* -import com.tangem.features.onramp.deeplink.DefaultOnrampDeepLink import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -18,5 +17,9 @@ internal interface OnrampDeeplinkModule { @Binds @Singleton - fun bindFactoryV2(impl: DefaultOnrampDeepLinkHandler.Factory): OnrampDeepLinkHandler.Factory + fun bindOnrampDeepLinkHandlerFactory(impl: DefaultOnrampDeepLinkHandler.Factory): OnrampDeepLinkHandler.Factory + + @Binds + @Singleton + fun bindBuyDeepLinkHandler(impl: DefaultBuyDeepLinkHandler.Factory): BuyDeepLinkHandler.Factory } \ No newline at end of file