Updated on 2026-08-14

This commit is contained in:
Tangem 2025-07-15 13:16:30 +04:00
parent aed332c720
commit fb32e4d5da
21 changed files with 31 additions and 366 deletions

View file

@ -4,16 +4,11 @@ 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.common.routing.RoutingFeatureToggle
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.ObserveAndClearNFTCacheIfNeedUseCase
@ -27,7 +22,6 @@ import com.tangem.domain.wallets.models.isMultiCurrency
import com.tangem.domain.wallets.usecase.GetSelectedWalletUseCase
import com.tangem.domain.wallets.usecase.GetWalletsUseCase
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
import com.tangem.feature.wallet.presentation.deeplink.WalletDeepLinksHandler
import com.tangem.feature.wallet.presentation.router.InnerWalletRouter
import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.SelectedWalletAnalyticsSender
@ -73,7 +67,6 @@ internal class WalletModel @Inject constructor(
private val isWalletsScrollPreviewEnabled: IsWalletsScrollPreviewEnabled,
private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
private val selectedWalletAnalyticsSender: SelectedWalletAnalyticsSender,
private val walletDeepLinksHandler: WalletDeepLinksHandler,
private val walletNameMigrationUseCase: WalletNameMigrationUseCase,
private val refreshMultiCurrencyWalletQuotesUseCase: RefreshMultiCurrencyWalletQuotesUseCase,
private val shouldAskPermissionUseCase: ShouldAskPermissionUseCase,
@ -81,12 +74,9 @@ internal class WalletModel @Inject constructor(
private val tokenListStore: MultiWalletTokenListStore,
private val onrampStatusFactory: OnrampStatusFactory,
private val analyticsEventsHandler: AnalyticsEventHandler,
private val deepLinksRegistry: DeepLinksRegistry,
private val fetchCurrencyStatusUseCase: FetchCurrencyStatusUseCase,
private val walletContentFetcher: WalletContentFetcher,
private val tokensFeatureToggles: TokensFeatureToggles,
private val appRouter: AppRouter,
private val routingFeatureToggle: RoutingFeatureToggle,
private val observeAndClearNFTCacheIfNeedUseCase: ObserveAndClearNFTCacheIfNeedUseCase,
private val walletDeepLinkActionListener: WalletDeepLinkActionListener,
val screenLifecycleProvider: ScreenLifecycleProvider,
@ -241,12 +231,6 @@ internal class WalletModel @Inject constructor(
selectedWalletAnalyticsSender.send(selectedWallet)
}
if (!routingFeatureToggle.isDeepLinkNavigationEnabled) {
// Registering here, because `WalletDeepLinksHandler` unregisters deeplink when scope is cancelled
// This is temporary solution, will be removed with complete deeplink navigation overhaul
addReferralDeepLink(selectedWallet)
walletDeepLinksHandler.registerForWallet(scope = modelScope, userWallet = selectedWallet)
}
subscribeOnExpressTransactionsUpdates(selectedWallet)
observeAndClearNFTCacheIfNeedUseCase(selectedWallet)
}
@ -268,20 +252,6 @@ internal class WalletModel @Inject constructor(
}
}
private fun addReferralDeepLink(userWallet: UserWallet) {
deepLinksRegistry.register(
ReferralDeepLink(
onReceive = {
if (userWallet !is UserWallet.Cold || 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() {

View file

@ -1,73 +0,0 @@
package com.tangem.feature.wallet.presentation.deeplink
import com.tangem.common.routing.AppRoute
import com.tangem.common.routing.AppRouter
import com.tangem.core.deeplink.DeepLink
import com.tangem.core.deeplink.DeepLinksRegistry
import com.tangem.core.deeplink.global.SellCurrencyDeepLink
import com.tangem.domain.tokens.GetCryptoCurrencyUseCase
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.utils.coroutines.launchOnCancellation
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
@Suppress("LongParameterList")
internal class WalletDeepLinksHandler @Inject constructor(
private val deepLinksRegistry: DeepLinksRegistry,
private val getCryptoCurrencyUseCase: GetCryptoCurrencyUseCase,
private val router: AppRouter,
) {
private var deepLinksMap = mutableMapOf<UserWalletId, List<DeepLink>>()
fun registerForWallet(scope: CoroutineScope, userWallet: UserWallet) {
val deepLinks = deepLinksMap.getOrPut(userWallet.walletId) {
getDeepLinks(userWallet, scope)
}
deepLinksRegistry.unregisterByIds(deepLinks.map { it.id })
deepLinksRegistry.register(deepLinks = deepLinks)
// When navigation to another screen scope is Cancelled and deeplinks are hot handled
scope.launchOnCancellation {
deepLinksRegistry.unregister(deepLinks)
}
}
private fun getDeepLinks(userWallet: UserWallet, scope: CoroutineScope): List<DeepLink> {
val sellCurrencyDeepLink = SellCurrencyDeepLink(
onReceive = { data ->
scope.launch {
onSellCurrencyDeepLink(userWallet, data)
}
},
shouldHandleDelayed = true,
)
return buildList {
add(sellCurrencyDeepLink)
}
}
private suspend fun onSellCurrencyDeepLink(userWallet: UserWallet, data: SellCurrencyDeepLink.Data) {
val cryptoCurrency = getCryptoCurrencyUseCase(userWallet, data.currencyId).getOrNull()
if (cryptoCurrency == null) {
Timber.e("onSellCurrencyDeepLink cryptoCurrency is null")
return
}
val route = AppRoute.Send(
currency = cryptoCurrency,
userWalletId = userWallet.walletId,
transactionId = data.transactionId,
destinationAddress = data.depositWalletAddress,
amount = data.baseCurrencyAmount,
tag = data.depositWalletAddressTag,
)
router.push(route)
}
}

View file

@ -1,8 +1,6 @@
package com.tangem.feature.wallet.presentation.wallet.loaders.implementors
import com.tangem.common.routing.RoutingFeatureToggle
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.deeplink.DeepLinksRegistry
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.nft.GetNFTCollectionsUseCase
import com.tangem.domain.promo.GetStoryContentUseCase
@ -40,10 +38,8 @@ internal class MultiWalletContentLoader(
private val runPolkadotAccountHealthCheckUseCase: RunPolkadotAccountHealthCheckUseCase,
private val shouldSaveUserWalletsUseCase: ShouldSaveUserWalletsUseCase,
private val getStoryContentUseCase: GetStoryContentUseCase,
private val deepLinksRegistry: DeepLinksRegistry,
private val walletsRepository: WalletsRepository,
private val currenciesRepository: CurrenciesRepository,
private val routingFeatureToggle: RoutingFeatureToggle,
) : WalletContentLoader(id = userWallet.walletId) {
override fun create(): List<WalletSubscriber> {
@ -58,8 +54,6 @@ internal class MultiWalletContentLoader(
getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase,
applyTokenListSortingUseCase = applyTokenListSortingUseCase,
runPolkadotAccountHealthCheckUseCase = runPolkadotAccountHealthCheckUseCase,
deepLinksRegistry = deepLinksRegistry,
routingFeatureToggle = routingFeatureToggle,
).let(::add)
WalletNFTListSubscriber(

View file

@ -1,8 +1,6 @@
package com.tangem.feature.wallet.presentation.wallet.loaders.implementors
import com.tangem.common.routing.RoutingFeatureToggle
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.deeplink.DeepLinksRegistry
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.nft.GetNFTCollectionsUseCase
import com.tangem.domain.promo.GetStoryContentUseCase
@ -37,10 +35,8 @@ internal class MultiWalletContentLoaderFactory @Inject constructor(
private val runPolkadotAccountHealthCheckUseCase: RunPolkadotAccountHealthCheckUseCase,
private val shouldSaveUserWalletsUseCase: ShouldSaveUserWalletsUseCase,
private val getStoryContentUseCase: GetStoryContentUseCase,
private val deepLinksRegistry: DeepLinksRegistry,
private val walletsRepository: WalletsRepository,
private val getNFTCollectionsUseCase: GetNFTCollectionsUseCase,
private val routingFeatureToggle: RoutingFeatureToggle,
private val currenciesRepository: CurrenciesRepository,
) {
@ -60,10 +56,8 @@ internal class MultiWalletContentLoaderFactory @Inject constructor(
runPolkadotAccountHealthCheckUseCase = runPolkadotAccountHealthCheckUseCase,
getStoryContentUseCase = getStoryContentUseCase,
shouldSaveUserWalletsUseCase = shouldSaveUserWalletsUseCase,
deepLinksRegistry = deepLinksRegistry,
walletsRepository = walletsRepository,
getNFTCollectionsUseCase = getNFTCollectionsUseCase,
routingFeatureToggle = routingFeatureToggle,
currenciesRepository = currenciesRepository,
)
}

View file

@ -1,7 +1,5 @@
package com.tangem.feature.wallet.presentation.wallet.loaders.implementors
import com.tangem.common.routing.RoutingFeatureToggle
import com.tangem.core.deeplink.DeepLinksRegistry
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.promo.GetStoryContentUseCase
import com.tangem.domain.tokens.RunPolkadotAccountHealthCheckUseCase
@ -32,8 +30,6 @@ internal class SingleWalletWithTokenContentLoader(
private val runPolkadotAccountHealthCheckUseCase: RunPolkadotAccountHealthCheckUseCase,
private val shouldSaveUserWalletsUseCase: ShouldSaveUserWalletsUseCase,
private val getStoryContentUseCase: GetStoryContentUseCase,
private val deepLinksRegistry: DeepLinksRegistry,
private val routingFeatureToggle: RoutingFeatureToggle,
) : WalletContentLoader(id = userWallet.walletId) {
override fun create(): List<WalletSubscriber> {
@ -47,8 +43,6 @@ internal class SingleWalletWithTokenContentLoader(
tokenListStore = tokenListStore,
getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase,
runPolkadotAccountHealthCheckUseCase = runPolkadotAccountHealthCheckUseCase,
deepLinksRegistry = deepLinksRegistry,
routingFeatureToggle = routingFeatureToggle,
).let(::add)
MultiWalletWarningsSubscriber(
userWallet = userWallet,

View file

@ -1,13 +1,12 @@
package com.tangem.feature.wallet.presentation.wallet.loaders.implementors
import com.tangem.common.routing.RoutingFeatureToggle
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.deeplink.DeepLinksRegistry
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.promo.GetStoryContentUseCase
import com.tangem.domain.tokens.RunPolkadotAccountHealthCheckUseCase
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.usecase.ShouldSaveUserWalletsUseCase
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsSingleEventSender
@ -15,7 +14,6 @@ import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarnin
import com.tangem.feature.wallet.presentation.wallet.domain.MultiWalletTokenListStore
import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker
import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
import javax.inject.Inject
// TODO: Refactor
@ -33,8 +31,6 @@ internal class SingleWalletWithTokenContentLoaderFactory @Inject constructor(
private val runPolkadotAccountHealthCheckUseCase: RunPolkadotAccountHealthCheckUseCase,
private val shouldSaveUserWalletsUseCase: ShouldSaveUserWalletsUseCase,
private val getStoryContentUseCase: GetStoryContentUseCase,
private val deepLinksRegistry: DeepLinksRegistry,
private val routingFeatureToggle: RoutingFeatureToggle,
) {
fun create(userWallet: UserWallet, clickIntents: WalletClickIntents): SingleWalletWithTokenContentLoader {
@ -52,8 +48,6 @@ internal class SingleWalletWithTokenContentLoaderFactory @Inject constructor(
runPolkadotAccountHealthCheckUseCase = runPolkadotAccountHealthCheckUseCase,
getStoryContentUseCase = getStoryContentUseCase,
shouldSaveUserWalletsUseCase = shouldSaveUserWalletsUseCase,
deepLinksRegistry = deepLinksRegistry,
routingFeatureToggle = routingFeatureToggle,
)
}
}

View file

@ -1,10 +1,6 @@
package com.tangem.feature.wallet.presentation.wallet.subscribers
import arrow.core.getOrElse
import com.tangem.common.routing.RoutingFeatureToggle
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
@ -39,8 +35,6 @@ internal abstract class BasicTokenListSubscriber(
private val walletWithFundsChecker: WalletWithFundsChecker,
private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
private val runPolkadotAccountHealthCheckUseCase: RunPolkadotAccountHealthCheckUseCase,
private val deepLinksRegistry: DeepLinksRegistry,
private val routingFeatureToggle: RoutingFeatureToggle,
) : WalletSubscriber() {
private val sendAnalyticsJobHolder = JobHolder()
@ -48,6 +42,8 @@ internal abstract class BasicTokenListSubscriber(
protected abstract fun tokenListFlow(coroutineScope: CoroutineScope): LceFlow<TokenListError, TokenList>
protected abstract suspend fun onTokenListReceived(maybeTokenList: Lce<TokenListError, TokenList>)
override fun create(coroutineScope: CoroutineScope): Flow<*> {
return combine(
flow = tokenListFlow(coroutineScope)
@ -114,21 +110,6 @@ internal abstract class BasicTokenListSubscriber(
}
}
protected open suspend fun onTokenListReceived(maybeTokenList: Lce<TokenListError, TokenList>) {
if (!routingFeatureToggle.isDeepLinkNavigationEnabled) {
/* no-op */
// Handling sell deeplink requires full content in order to correctly open Send screen
if (maybeTokenList.getOrNull(false) != null) {
deepLinksRegistry.triggerDelayedDeeplink(deepLinkClass = SellCurrencyDeepLink::class.java)
}
// Handling referral deeplink requires only selected wallet to be loaded
// This is temporary solution, will be removed with complete deeplink navigation overhaul
if (maybeTokenList.getOrNull(true) != null) {
deepLinksRegistry.triggerDelayedDeeplink(deepLinkClass = ReferralDeepLink::class.java)
}
}
}
private suspend fun sendTokenListAnalytics(maybeTokenList: Lce<TokenListError, TokenList>) {
val displayedState = stateHolder.getWalletStateIfSelected(userWallet.walletId)

View file

@ -1,7 +1,5 @@
package com.tangem.feature.wallet.presentation.wallet.subscribers
import com.tangem.common.routing.RoutingFeatureToggle
import com.tangem.core.deeplink.DeepLinksRegistry
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.core.lce.Lce
import com.tangem.domain.core.lce.LceFlow
@ -30,8 +28,6 @@ internal class MultiWalletTokenListSubscriber(
walletWithFundsChecker: WalletWithFundsChecker,
getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
runPolkadotAccountHealthCheckUseCase: RunPolkadotAccountHealthCheckUseCase,
deepLinksRegistry: DeepLinksRegistry,
routingFeatureToggle: RoutingFeatureToggle,
) : BasicTokenListSubscriber(
userWallet = userWallet,
stateHolder = stateHolder,
@ -40,8 +36,6 @@ internal class MultiWalletTokenListSubscriber(
walletWithFundsChecker = walletWithFundsChecker,
getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase,
runPolkadotAccountHealthCheckUseCase = runPolkadotAccountHealthCheckUseCase,
deepLinksRegistry = deepLinksRegistry,
routingFeatureToggle = routingFeatureToggle,
) {
override fun tokenListFlow(coroutineScope: CoroutineScope): LceFlow<TokenListError, TokenList> {
@ -52,7 +46,6 @@ internal class MultiWalletTokenListSubscriber(
override suspend fun onTokenListReceived(maybeTokenList: Lce<TokenListError, TokenList>) {
updateSortingIfNeeded(maybeTokenList)
super.onTokenListReceived(maybeTokenList)
}
private suspend fun updateSortingIfNeeded(maybeTokenList: Lce<*, TokenList>) {

View file

@ -1,8 +1,7 @@
package com.tangem.feature.wallet.presentation.wallet.subscribers
import com.tangem.common.routing.RoutingFeatureToggle
import com.tangem.core.deeplink.DeepLinksRegistry
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.core.lce.Lce
import com.tangem.domain.core.lce.LceFlow
import com.tangem.domain.tokens.RunPolkadotAccountHealthCheckUseCase
import com.tangem.domain.tokens.error.TokenListError
@ -25,8 +24,6 @@ internal class SingleWalletWithTokenListSubscriber(
walletWithFundsChecker: WalletWithFundsChecker,
getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase,
runPolkadotAccountHealthCheckUseCase: RunPolkadotAccountHealthCheckUseCase,
deepLinksRegistry: DeepLinksRegistry,
routingFeatureToggle: RoutingFeatureToggle,
) : BasicTokenListSubscriber(
userWallet = userWallet,
stateHolder = stateHolder,
@ -35,8 +32,6 @@ internal class SingleWalletWithTokenListSubscriber(
walletWithFundsChecker = walletWithFundsChecker,
getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase,
runPolkadotAccountHealthCheckUseCase = runPolkadotAccountHealthCheckUseCase,
deepLinksRegistry = deepLinksRegistry,
routingFeatureToggle = routingFeatureToggle,
) {
override fun tokenListFlow(coroutineScope: CoroutineScope): LceFlow<TokenListError, TokenList> {
@ -44,4 +39,6 @@ internal class SingleWalletWithTokenListSubscriber(
return tokenListStore.getOrThrow(userWallet.walletId)
}
override suspend fun onTokenListReceived(maybeTokenList: Lce<TokenListError, TokenList>) = Unit
}