Updated on 2026-08-14
This commit is contained in:
parent
87987689d3
commit
9d3759986a
4 changed files with 20 additions and 28 deletions
|
|
@ -19,6 +19,7 @@ dependencies {
|
|||
implementation(projects.core.navigation)
|
||||
implementation(projects.core.utils)
|
||||
implementation(projects.core.ui)
|
||||
implementation(projects.common.routing)
|
||||
|
||||
/** Domain modules **/
|
||||
implementation(projects.domain.appCurrency)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ import androidx.compose.animation.Crossfade
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.tangem.core.navigation.ReduxNavController
|
||||
import com.tangem.common.routing.AppRouter
|
||||
|
||||
import com.tangem.core.ui.UiDependencies
|
||||
import com.tangem.core.ui.components.SystemBarsEffect
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
|
|
@ -28,7 +29,7 @@ class SwapFragment : ComposeFragment() {
|
|||
override lateinit var uiDependencies: UiDependencies
|
||||
|
||||
@Inject
|
||||
lateinit var reduxNavController: ReduxNavController
|
||||
lateinit var appRouter: AppRouter
|
||||
|
||||
private val viewModel by viewModels<SwapViewModel>()
|
||||
|
||||
|
|
@ -37,9 +38,8 @@ class SwapFragment : ComposeFragment() {
|
|||
lifecycle.addObserver(viewModel)
|
||||
viewModel.setRouter(
|
||||
SwapRouter(
|
||||
fragmentManager = WeakReference(parentFragmentManager),
|
||||
customTabsManager = CustomTabsManager(WeakReference(context)),
|
||||
reduxNavController = reduxNavController,
|
||||
router = appRouter,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -84,8 +84,4 @@ class SwapFragment : ComposeFragment() {
|
|||
lifecycle.removeObserver(viewModel)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val CURRENCY_BUNDLE_KEY = "swap_currency"
|
||||
}
|
||||
}
|
||||
|
|
@ -3,20 +3,14 @@ package com.tangem.feature.swap.router
|
|||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.tangem.core.navigation.AppScreen
|
||||
import com.tangem.core.navigation.NavigationAction
|
||||
import com.tangem.core.navigation.ReduxNavController
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.common.routing.AppRouter
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.features.tokendetails.navigation.TokenDetailsRouter
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
internal class SwapRouter(
|
||||
private val fragmentManager: WeakReference<FragmentManager>,
|
||||
private val customTabsManager: CustomTabsManager,
|
||||
private val reduxNavController: ReduxNavController,
|
||||
private val router: AppRouter,
|
||||
) {
|
||||
|
||||
var currentScreen by mutableStateOf(SwapNavScreen.Main)
|
||||
|
|
@ -30,7 +24,7 @@ internal class SwapRouter(
|
|||
if (currentScreen == SwapNavScreen.SelectToken) {
|
||||
currentScreen = SwapNavScreen.Main
|
||||
} else {
|
||||
fragmentManager.get()?.popBackStack()
|
||||
router.pop()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,13 +33,10 @@ internal class SwapRouter(
|
|||
}
|
||||
|
||||
fun openTokenDetails(userWalletId: UserWalletId, currency: CryptoCurrency) {
|
||||
reduxNavController.navigate(
|
||||
action = NavigationAction.NavigateTo(
|
||||
screen = AppScreen.WalletDetails,
|
||||
bundle = bundleOf(
|
||||
TokenDetailsRouter.USER_WALLET_ID_KEY to userWalletId.stringValue,
|
||||
TokenDetailsRouter.CRYPTO_CURRENCY_KEY to currency,
|
||||
),
|
||||
router.push(
|
||||
AppRoute.CurrencyDetails(
|
||||
userWalletId = userWalletId,
|
||||
currency = currency,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package com.tangem.feature.swap.viewmodels
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.*
|
||||
import arrow.core.Either
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.common.routing.bundle.unbundle
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.core.analytics.models.AnalyticsParam
|
||||
import com.tangem.core.analytics.models.Basic
|
||||
|
|
@ -32,7 +35,6 @@ import com.tangem.feature.swap.domain.models.domain.*
|
|||
import com.tangem.feature.swap.domain.models.formatToUIRepresentation
|
||||
import com.tangem.feature.swap.domain.models.ui.*
|
||||
import com.tangem.feature.swap.models.*
|
||||
import com.tangem.feature.swap.presentation.SwapFragment
|
||||
import com.tangem.feature.swap.router.SwapNavScreen
|
||||
import com.tangem.feature.swap.router.SwapRouter
|
||||
import com.tangem.feature.swap.ui.StateBuilder
|
||||
|
|
@ -70,8 +72,10 @@ internal class SwapViewModel @Inject constructor(
|
|||
savedStateHandle: SavedStateHandle,
|
||||
) : ViewModel(), DefaultLifecycleObserver {
|
||||
|
||||
private val initialCryptoCurrency: CryptoCurrency =
|
||||
savedStateHandle[SwapFragment.CURRENCY_BUNDLE_KEY] ?: error("no expected parameter CryptoCurrency found`")
|
||||
private val initialCryptoCurrency: CryptoCurrency = savedStateHandle.get<Bundle>(AppRoute.Swap.CURRENCY_BUNDLE_KEY)
|
||||
?.let { it.unbundle(CryptoCurrency.serializer()) }
|
||||
?: error("no expected parameter CryptoCurrency found`")
|
||||
|
||||
private lateinit var initialCryptoCurrencyStatus: CryptoCurrencyStatus
|
||||
|
||||
private var isBalanceHidden = true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue