From abf5357f6aa7cfbb2e0593c9910d25b569c21391 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 20 May 2025 12:41:12 +0500 Subject: [PATCH] Updated on 2026-08-14 --- features/tokendetails/api/build.gradle.kts | 3 + .../deeplink/TokenDetailsDeepLinkHandler.kt | 10 +++ features/tokendetails/impl/build.gradle.kts | 1 + .../DefaultTokenDetailsDeepLinkHandler.kt | 88 +++++++++++++++++++ .../deeplink/di/TokenDetailsDeepLinkModule.kt | 20 +++++ 5 files changed, 122 insertions(+) create mode 100644 features/tokendetails/api/src/main/kotlin/com/tangem/features/tokendetails/deeplink/TokenDetailsDeepLinkHandler.kt create mode 100644 features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/deeplink/DefaultTokenDetailsDeepLinkHandler.kt create mode 100644 features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/deeplink/di/TokenDetailsDeepLinkModule.kt diff --git a/features/tokendetails/api/build.gradle.kts b/features/tokendetails/api/build.gradle.kts index dc22e4ffbb..09d9a1d7d0 100644 --- a/features/tokendetails/api/build.gradle.kts +++ b/features/tokendetails/api/build.gradle.kts @@ -17,4 +17,7 @@ dependencies { /** Domain models */ implementation(projects.domain.tokens.models) implementation(projects.domain.wallets.models) + + /** Compose */ + implementation(deps.compose.runtime) } \ No newline at end of file diff --git a/features/tokendetails/api/src/main/kotlin/com/tangem/features/tokendetails/deeplink/TokenDetailsDeepLinkHandler.kt b/features/tokendetails/api/src/main/kotlin/com/tangem/features/tokendetails/deeplink/TokenDetailsDeepLinkHandler.kt new file mode 100644 index 0000000000..5510648e3f --- /dev/null +++ b/features/tokendetails/api/src/main/kotlin/com/tangem/features/tokendetails/deeplink/TokenDetailsDeepLinkHandler.kt @@ -0,0 +1,10 @@ +package com.tangem.features.tokendetails.deeplink + +import kotlinx.coroutines.CoroutineScope + +interface TokenDetailsDeepLinkHandler { + + interface Factory { + fun create(coroutineScope: CoroutineScope, params: Map): TokenDetailsDeepLinkHandler + } +} \ No newline at end of file diff --git a/features/tokendetails/impl/build.gradle.kts b/features/tokendetails/impl/build.gradle.kts index b80dda2c34..3515424d77 100644 --- a/features/tokendetails/impl/build.gradle.kts +++ b/features/tokendetails/impl/build.gradle.kts @@ -87,6 +87,7 @@ dependencies { implementation(projects.domain.promo) implementation(projects.domain.promo.models) implementation(projects.domain.quotes) + implementation(projects.domain.notifications.models) /** Temp dependency to swap domain */ implementation(projects.features.swap.domain) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/deeplink/DefaultTokenDetailsDeepLinkHandler.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/deeplink/DefaultTokenDetailsDeepLinkHandler.kt new file mode 100644 index 0000000000..eaf2d83527 --- /dev/null +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/deeplink/DefaultTokenDetailsDeepLinkHandler.kt @@ -0,0 +1,88 @@ +package com.tangem.feature.tokendetails.deeplink + +import arrow.core.getOrElse +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.domain.notifications.models.NotificationType +import com.tangem.domain.tokens.GetCryptoCurrenciesUseCase +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase +import com.tangem.features.tokendetails.deeplink.TokenDetailsDeepLinkHandler +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 DefaultTokenDetailsDeepLinkHandler @AssistedInject constructor( + @Assisted private val params: Map, + @Assisted private val scope: CoroutineScope, + private val appRouter: AppRouter, + private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, + private val getCryptoCurrenciesUseCase: GetCryptoCurrenciesUseCase, +) : TokenDetailsDeepLinkHandler { + + init { + handleDeepLink() + } + + private fun handleDeepLink() { + // It is okay here, we are navigating from outside, and there is no other way to getting UserWallet + val userWalletId = params[WALLET_ID_KEY]?.let(::UserWalletId) + ?: getSelectedWalletSyncUseCase().getOrNull()?.walletId + + if (userWalletId == null) { + Timber.e("Error on getting user wallet") + return + } + + val networkId = params[NETWORK_ID_KEY] + val tokenId = params[TOKEN_ID_KEY] + val type = NotificationType.getType(params[TYPE_KEY]) + + if (type == NotificationType.Promo) { + scope.launch { + val cryptoCurrency = getCryptoCurrenciesUseCase(userWalletId = userWalletId).getOrElse { + Timber.e("Error on getting crypto currency list") + return@launch + }.firstOrNull { + it.id.rawNetworkId == networkId && it.id.rawCurrencyId?.value == tokenId + } + + if (cryptoCurrency == null) { + Timber.e( + """ + Could not get crypto currency for + |- $NETWORK_ID_KEY: $networkId + |- $TOKEN_ID_KEY: $tokenId + """.trimIndent(), + ) + return@launch + } + + appRouter.push( + AppRoute.CurrencyDetails( + userWalletId = userWalletId, + currency = cryptoCurrency, + ), + ) + } + } + } + + @AssistedFactory + interface Factory : TokenDetailsDeepLinkHandler.Factory { + override fun create( + coroutineScope: CoroutineScope, + params: Map, + ): DefaultTokenDetailsDeepLinkHandler + } + + private companion object { + const val WALLET_ID_KEY = "walletId" + const val NETWORK_ID_KEY = "network_id" + const val TYPE_KEY = "type" + const val TOKEN_ID_KEY = "token_id" + } +} \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/deeplink/di/TokenDetailsDeepLinkModule.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/deeplink/di/TokenDetailsDeepLinkModule.kt new file mode 100644 index 0000000000..0b2e70f86e --- /dev/null +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/deeplink/di/TokenDetailsDeepLinkModule.kt @@ -0,0 +1,20 @@ +package com.tangem.feature.tokendetails.deeplink.di + +import com.tangem.feature.tokendetails.deeplink.DefaultTokenDetailsDeepLinkHandler +import com.tangem.features.tokendetails.deeplink.TokenDetailsDeepLinkHandler +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal interface TokenDetailsDeepLinkModule { + + @Binds + @Singleton + fun bindWalletDeepLinkHandlerFactory( + impl: DefaultTokenDetailsDeepLinkHandler.Factory, + ): TokenDetailsDeepLinkHandler.Factory +} \ No newline at end of file