Updated on 2026-08-14
This commit is contained in:
parent
16004fe75a
commit
19341c536e
6 changed files with 139 additions and 4 deletions
|
|
@ -0,0 +1,42 @@
|
|||
package com.tangem.features.swap.v2.impl.amount
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.tangem.core.decompose.context.AppComponentContext
|
||||
import com.tangem.core.decompose.model.getOrCreateModel
|
||||
import com.tangem.core.ui.decompose.ComposableContentComponent
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
|
||||
import com.tangem.features.swap.v2.impl.amount.model.SwapAmountModel
|
||||
import com.tangem.features.swap.v2.impl.amount.ui.SwapAmountContent
|
||||
import com.tangem.features.swap.v2.impl.common.SwapNavigationModelCallback
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
|
||||
internal class SwapAmountComponent @AssistedInject constructor(
|
||||
@Assisted appComponentContext: AppComponentContext,
|
||||
@Assisted private val params: SwapAmountComponentParams.AmountParams,
|
||||
) : ComposableContentComponent, AppComponentContext by appComponentContext {
|
||||
|
||||
private val model: SwapAmountModel = getOrCreateModel(params = params)
|
||||
|
||||
fun updateState(amountUM: SwapAmountUM) = model.updateState(amountUM)
|
||||
|
||||
@Composable
|
||||
override fun Content(modifier: Modifier) {
|
||||
val amountUM by model.uiState.collectAsStateWithLifecycle()
|
||||
|
||||
SwapAmountContent(
|
||||
amountUM = amountUM,
|
||||
modifier = Modifier.background(TangemTheme.colors.background.tertiary),
|
||||
clickIntents = model,
|
||||
)
|
||||
}
|
||||
|
||||
interface ModelCallback : SwapNavigationModelCallback {
|
||||
fun onAmountResult(amountUM: SwapAmountUM)
|
||||
}
|
||||
}
|
||||
|
|
@ -30,8 +30,6 @@ internal sealed class SwapAmountComponentParams {
|
|||
val secondaryCryptoCurrency: CryptoCurrency?,
|
||||
val callback: SwapAmountComponent.ModelCallback,
|
||||
val currentRoute: Flow<SwapRoute.Amount>,
|
||||
val onBackClick: () -> Unit,
|
||||
val onNextClick: () -> Unit,
|
||||
) : SwapAmountComponentParams()
|
||||
|
||||
data class AmountBlockParams(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.tangem.features.swap.v2.impl.amount.di
|
||||
|
||||
import com.tangem.core.decompose.di.ModelComponent
|
||||
import com.tangem.core.decompose.model.Model
|
||||
import com.tangem.features.swap.v2.impl.amount.model.SwapAmountModel
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.multibindings.ClassKey
|
||||
import dagger.multibindings.IntoMap
|
||||
|
||||
@InstallIn(ModelComponent::class)
|
||||
@Module
|
||||
internal interface SwapAmountModule {
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ClassKey(SwapAmountModel::class)
|
||||
fun provideSwapAmountModel(impl: SwapAmountModel): Model
|
||||
}
|
||||
|
|
@ -477,7 +477,7 @@ internal class SwapAmountModel @Inject constructor(
|
|||
// ),
|
||||
// )
|
||||
// }
|
||||
params.onBackClick()
|
||||
params.callback.onBackClick()
|
||||
},
|
||||
primaryButton = NavigationButton(
|
||||
textReference = if (route.isEditMode) {
|
||||
|
|
@ -488,7 +488,7 @@ internal class SwapAmountModel @Inject constructor(
|
|||
isEnabled = state.isPrimaryButtonEnabled,
|
||||
onClick = {
|
||||
saveResult()
|
||||
params.onNextClick()
|
||||
params.callback.onNextClick()
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
package com.tangem.features.swap.v2.impl.amount.ui.preview
|
||||
|
||||
import com.tangem.common.ui.amountScreen.preview.AmountStatePreviewData
|
||||
import com.tangem.core.ui.components.atoms.text.TextEllipsis
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.express.models.ExpressRateType
|
||||
import com.tangem.domain.swap.models.SwapCurrencies
|
||||
import com.tangem.domain.swap.models.SwapDirection
|
||||
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
|
||||
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountType
|
||||
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
|
||||
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
||||
internal data object SwapAmountContentPreview {
|
||||
|
||||
val emptyState = SwapAmountUM.Content(
|
||||
isPrimaryButtonEnabled = false,
|
||||
primaryAmount = SwapAmountFieldUM.Empty(
|
||||
amountType = SwapAmountType.From,
|
||||
),
|
||||
secondaryAmount = SwapAmountFieldUM.Empty(
|
||||
amountType = SwapAmountType.To,
|
||||
),
|
||||
swapDirection = SwapDirection.Direct,
|
||||
selectedAmountType = SwapAmountType.From,
|
||||
swapCurrencies = SwapCurrencies.EMPTY,
|
||||
swapQuotes = persistentListOf(),
|
||||
selectedQuote = SwapQuoteUM.Empty,
|
||||
primaryCryptoCurrencyStatus = null,
|
||||
secondaryCryptoCurrencyStatus = null,
|
||||
swapRateType = ExpressRateType.Float,
|
||||
appCurrency = AppCurrency.Default,
|
||||
)
|
||||
|
||||
val defaultState = SwapAmountUM.Content(
|
||||
primaryAmount = SwapAmountFieldUM.Content(
|
||||
amountType = SwapAmountType.From,
|
||||
amountField = AmountStatePreviewData.amountState.copy(
|
||||
availableBalance = stringReference("Balance: 100 BTC"),
|
||||
),
|
||||
title = stringReference("Tether"),
|
||||
subtitle = stringReference("Balance: 100 BTC"),
|
||||
priceImpact = null,
|
||||
isClickEnabled = false,
|
||||
subtitleEllipsis = TextEllipsis.OffsetEnd(3),
|
||||
),
|
||||
secondaryAmount = SwapAmountFieldUM.Content(
|
||||
amountType = SwapAmountType.To,
|
||||
amountField = AmountStatePreviewData.amountState.copy(
|
||||
title = stringReference("Amount to receive"),
|
||||
availableBalance = TextReference.EMPTY,
|
||||
),
|
||||
title = stringReference("Shiba Inu"),
|
||||
priceImpact = stringReference("(-10%)"),
|
||||
subtitle = TextReference.EMPTY,
|
||||
isClickEnabled = false,
|
||||
subtitleEllipsis = TextEllipsis.OffsetEnd(3),
|
||||
),
|
||||
appCurrency = AppCurrency.Default,
|
||||
swapDirection = SwapDirection.Direct,
|
||||
selectedAmountType = SwapAmountType.From,
|
||||
swapCurrencies = SwapCurrencies.EMPTY,
|
||||
swapQuotes = persistentListOf(),
|
||||
selectedQuote = SwapQuoteUM.Empty,
|
||||
primaryCryptoCurrencyStatus = null,
|
||||
secondaryCryptoCurrencyStatus = null,
|
||||
swapRateType = ExpressRateType.Float,
|
||||
isPrimaryButtonEnabled = true,
|
||||
)
|
||||
}
|
||||
|
|
@ -4,4 +4,6 @@ import com.tangem.features.swap.v2.impl.common.entity.NavigationUM
|
|||
|
||||
internal interface SwapNavigationModelCallback {
|
||||
fun onNavigationResult(navigationUM: NavigationUM)
|
||||
fun onBackClick()
|
||||
fun onNextClick()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue