From 64c7c64b3a7325eddea7dee6ceba803f1b144d18 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 17 Sep 2025 15:15:55 +0500 Subject: [PATCH] Updated on 2026-08-14 --- core/ui/src/main/res/drawable/img_aave_22.xml | 18 ++ .../YieldSupplyDepositedWarningComponent.kt | 23 +++ ...ultYieldSupplyDepositedWarningComponent.kt | 39 +++++ .../di/YieldSupplyDepositedWarningModule.kt | 34 ++++ .../model/YieldSupplyDepositedWarningModel.kt | 35 ++++ .../ui/YieldSupplyDepositedWarningContent.kt | 159 ++++++++++++++++++ .../ui/YieldSupplyDepositedWarningUM.kt | 9 + 7 files changed, 317 insertions(+) create mode 100644 core/ui/src/main/res/drawable/img_aave_22.xml create mode 100644 features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/YieldSupplyDepositedWarningComponent.kt create mode 100644 features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/DefaultYieldSupplyDepositedWarningComponent.kt create mode 100644 features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/di/YieldSupplyDepositedWarningModule.kt create mode 100644 features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/model/YieldSupplyDepositedWarningModel.kt create mode 100644 features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/ui/YieldSupplyDepositedWarningContent.kt create mode 100644 features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/ui/YieldSupplyDepositedWarningUM.kt diff --git a/core/ui/src/main/res/drawable/img_aave_22.xml b/core/ui/src/main/res/drawable/img_aave_22.xml new file mode 100644 index 0000000000..7ae7a56a34 --- /dev/null +++ b/core/ui/src/main/res/drawable/img_aave_22.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/YieldSupplyDepositedWarningComponent.kt b/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/YieldSupplyDepositedWarningComponent.kt new file mode 100644 index 0000000000..de39187872 --- /dev/null +++ b/features/yield-supply/api/src/main/java/com/tangem/features/yield/supply/api/YieldSupplyDepositedWarningComponent.kt @@ -0,0 +1,23 @@ +package com.tangem.features.yield.supply.api + +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.factory.ComponentFactory +import com.tangem.core.ui.decompose.ComposableBottomSheetComponent +import com.tangem.domain.models.currency.CryptoCurrency + +interface YieldSupplyDepositedWarningComponent : ComposableBottomSheetComponent { + + data class Params( + val cryptoCurrency: CryptoCurrency, + val modelCallback: ModelCallback, + val onDismiss: () -> Unit, + ) + + interface ModelCallback { + fun onYieldSupplyWarningAcknowledged() + } + + interface Factory : ComponentFactory { + override fun create(context: AppComponentContext, params: Params): YieldSupplyDepositedWarningComponent + } +} \ No newline at end of file diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/DefaultYieldSupplyDepositedWarningComponent.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/DefaultYieldSupplyDepositedWarningComponent.kt new file mode 100644 index 0000000000..64aea7a635 --- /dev/null +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/DefaultYieldSupplyDepositedWarningComponent.kt @@ -0,0 +1,39 @@ +package com.tangem.features.yield.supply.impl.warning + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.model.getOrCreateModel +import com.tangem.features.yield.supply.api.YieldSupplyDepositedWarningComponent +import com.tangem.features.yield.supply.impl.warning.model.YieldSupplyDepositedWarningModel +import com.tangem.features.yield.supply.impl.warning.ui.YieldSupplyDepositedWarningContent +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject + +internal class DefaultYieldSupplyDepositedWarningComponent @AssistedInject constructor( + @Assisted private val appComponentContext: AppComponentContext, + @Assisted private val params: YieldSupplyDepositedWarningComponent.Params, +) : AppComponentContext by appComponentContext, YieldSupplyDepositedWarningComponent { + + private val model: YieldSupplyDepositedWarningModel = getOrCreateModel(params = params) + + override fun dismiss() { + params.onDismiss() + } + + @Composable + override fun BottomSheet() { + val state by model.state.collectAsStateWithLifecycle() + YieldSupplyDepositedWarningContent(warningUM = state, onDismiss = params.onDismiss) + } + + @AssistedFactory + interface Factory : YieldSupplyDepositedWarningComponent.Factory { + override fun create( + context: AppComponentContext, + params: YieldSupplyDepositedWarningComponent.Params, + ): DefaultYieldSupplyDepositedWarningComponent + } +} \ No newline at end of file diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/di/YieldSupplyDepositedWarningModule.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/di/YieldSupplyDepositedWarningModule.kt new file mode 100644 index 0000000000..a066bb08d7 --- /dev/null +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/di/YieldSupplyDepositedWarningModule.kt @@ -0,0 +1,34 @@ +package com.tangem.features.yield.supply.impl.warning.di + +import com.tangem.core.decompose.di.ModelComponent +import com.tangem.core.decompose.model.Model +import com.tangem.features.yield.supply.api.YieldSupplyDepositedWarningComponent +import com.tangem.features.yield.supply.impl.warning.DefaultYieldSupplyDepositedWarningComponent +import com.tangem.features.yield.supply.impl.warning.model.YieldSupplyDepositedWarningModel +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal interface YieldSupplyDepositedWarningModule { + @Binds + @Singleton + fun provideYieldSupplyWarningComponentFactory( + impl: DefaultYieldSupplyDepositedWarningComponent.Factory, + ): YieldSupplyDepositedWarningComponent.Factory +} + +@Module +@InstallIn(ModelComponent::class) +internal interface YieldSupplyDepositedWarningModelModule { + + @Binds + @IntoMap + @ClassKey(YieldSupplyDepositedWarningModel::class) + fun provideYieldSupplyWarningModel(impl: YieldSupplyDepositedWarningModel): Model +} \ No newline at end of file diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/model/YieldSupplyDepositedWarningModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/model/YieldSupplyDepositedWarningModel.kt new file mode 100644 index 0000000000..038224d072 --- /dev/null +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/model/YieldSupplyDepositedWarningModel.kt @@ -0,0 +1,35 @@ +package com.tangem.features.yield.supply.impl.warning.model + +import androidx.compose.runtime.Stable +import com.tangem.core.decompose.di.ModelScoped +import com.tangem.core.decompose.model.Model +import com.tangem.core.decompose.model.ParamsContainer +import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter +import com.tangem.features.yield.supply.api.YieldSupplyDepositedWarningComponent +import com.tangem.features.yield.supply.impl.warning.ui.YieldSupplyDepositedWarningUM +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import javax.inject.Inject + +@Stable +@ModelScoped +internal class YieldSupplyDepositedWarningModel @Inject constructor( + paramsContainer: ParamsContainer, + override val dispatchers: CoroutineDispatcherProvider, +) : Model() { + + private val params = + paramsContainer.require() + + private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter) + + internal val state: StateFlow + field = MutableStateFlow( + YieldSupplyDepositedWarningUM( + iconState = iconStateConverter.convert(params.cryptoCurrency), + onWarningAcknowledged = params.modelCallback::onYieldSupplyWarningAcknowledged, + network = params.cryptoCurrency.name, + ), + ) +} \ No newline at end of file diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/ui/YieldSupplyDepositedWarningContent.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/ui/YieldSupplyDepositedWarningContent.kt new file mode 100644 index 0000000000..6f1917fa96 --- /dev/null +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/ui/YieldSupplyDepositedWarningContent.kt @@ -0,0 +1,159 @@ +package com.tangem.features.yield.supply.impl.warning.ui + +import android.content.res.Configuration +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import androidx.compose.ui.unit.dp +import com.tangem.core.ui.R as CoreUiR +import com.tangem.core.ui.components.SecondaryButton +import com.tangem.core.ui.components.SpacerH +import com.tangem.core.ui.components.SpacerH24 +import com.tangem.core.ui.components.SpacerH8 +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent +import com.tangem.core.ui.components.bottomsheets.modal.TangemModalBottomSheetTitle +import com.tangem.core.ui.components.bottomsheets.modal.TangemModalBottomSheetWithFooter +import com.tangem.core.ui.components.currency.icon.CurrencyIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIconState +import com.tangem.core.ui.extensions.stringResourceSafe +import com.tangem.core.ui.res.TangemColorPalette +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.yield.supply.impl.R + +@Composable +internal fun YieldSupplyDepositedWarningContent(warningUM: YieldSupplyDepositedWarningUM, onDismiss: () -> Unit) { + TangemModalBottomSheetWithFooter( + config = TangemBottomSheetConfig( + isShown = true, + onDismissRequest = onDismiss, + content = TangemBottomSheetConfigContent.Empty, + ), + containerColor = TangemTheme.colors.background.primary, + onBack = null, + title = { + TangemModalBottomSheetTitle( + endIconRes = CoreUiR.drawable.ic_close_24, + onEndClick = onDismiss, + ) + }, + content = { + Content(warningUM) + }, + footer = { + SecondaryButton( + modifier = Modifier + .padding(horizontal = 16.dp) + .fillMaxWidth(), + text = stringResourceSafe(CoreUiR.string.balance_hidden_got_it_button), + onClick = onDismiss, + ) + }, + ) +} + +@Composable +private fun Content(warningUM: YieldSupplyDepositedWarningUM) { + Column( + modifier = Modifier + .fillMaxWidth() + .background(color = TangemTheme.colors.background.primary) + .padding( + start = 16.dp, + end = 16.dp, + bottom = 16.dp, + ), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Box( + modifier = Modifier + .size(height = 56.dp, width = 80.dp), + contentAlignment = Alignment.Center, + ) { + CurrencyIcon( + modifier = Modifier + .align(Alignment.CenterStart) + .size(48.dp), + state = warningUM.iconState, + shouldDisplayNetwork = true, + iconSize = 48.dp, + ) + Box( + modifier = Modifier + .size(54.dp) + .align(Alignment.CenterEnd) + .background(TangemTheme.colors.background.primary, CircleShape), + ) + Image( + painter = painterResource(id = CoreUiR.drawable.img_aave_22), + contentDescription = null, + modifier = Modifier + .padding(3.dp) + .align(Alignment.CenterEnd) + .size(48.dp), + ) + } + + SpacerH24() + + Text( + textAlign = TextAlign.Center, + text = stringResourceSafe(R.string.yield_module_explore_sheet_title, warningUM.network), + style = TangemTheme.typography.h3, + color = TangemTheme.colors.text.primary1, + ) + + SpacerH8() + + Text( + textAlign = TextAlign.Center, + text = stringResourceSafe(R.string.yield_module_explore_sheet_description), + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.secondary, + ) + + SpacerH(8.dp) + } +} + +@Composable +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun PreviewYieldSupplyDepositedWarningContent( + @PreviewParameter(YieldSupplyWarningContentProvider::class) warningUM: YieldSupplyDepositedWarningUM, +) { + TangemThemePreview { + YieldSupplyDepositedWarningContent(warningUM = warningUM, onDismiss = {}) + } +} + +private class YieldSupplyWarningContentProvider : PreviewParameterProvider { + private val iconState = CurrencyIconState.TokenIcon( + url = null, + topBadgeIconResId = null, + fallbackTint = TangemColorPalette.Black, + fallbackBackground = TangemColorPalette.Meadow, + isGrayscale = false, + showCustomBadge = false, + ) + + override val values: Sequence + get() = sequenceOf( + YieldSupplyDepositedWarningUM( + iconState = iconState, + onWarningAcknowledged = {}, + network = "Ethereum", + ), + ) +} \ No newline at end of file diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/ui/YieldSupplyDepositedWarningUM.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/ui/YieldSupplyDepositedWarningUM.kt new file mode 100644 index 0000000000..b675c74ac6 --- /dev/null +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/warning/ui/YieldSupplyDepositedWarningUM.kt @@ -0,0 +1,9 @@ +package com.tangem.features.yield.supply.impl.warning.ui + +import com.tangem.core.ui.components.currency.icon.CurrencyIconState + +internal data class YieldSupplyDepositedWarningUM( + val network: String, + val iconState: CurrencyIconState, + val onWarningAcknowledged: () -> Unit, +) \ No newline at end of file