Updated on 2026-08-14
This commit is contained in:
parent
fa125539b4
commit
96e30660e8
7 changed files with 116 additions and 21 deletions
|
|
@ -5,7 +5,7 @@ import com.tangem.core.ui.extensions.TextReference
|
|||
|
||||
internal data class YieldSupplyActiveContentUM(
|
||||
val totalEarnings: TextReference,
|
||||
val availableBalance: TextReference,
|
||||
val availableBalance: TextReference?,
|
||||
val providerTitle: TextReference,
|
||||
val subtitle: TextReference,
|
||||
val subtitleLink: TextReference,
|
||||
|
|
|
|||
|
|
@ -10,17 +10,20 @@ import com.tangem.core.ui.extensions.stringReference
|
|||
import com.tangem.core.ui.extensions.wrappedList
|
||||
import com.tangem.core.ui.format.bigdecimal.crypto
|
||||
import com.tangem.core.ui.format.bigdecimal.format
|
||||
import com.tangem.domain.yield.supply.usecase.YieldSupplyGetProtocolBalanceUseCase
|
||||
import com.tangem.features.yield.supply.impl.R
|
||||
import com.tangem.features.yield.supply.impl.subcomponents.active.YieldSupplyActiveComponent
|
||||
import com.tangem.features.yield.supply.impl.subcomponents.active.entity.YieldSupplyActiveContentUM
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@ModelScoped
|
||||
internal class YieldSupplyActiveModel @Inject constructor(
|
||||
paramsContainer: ParamsContainer,
|
||||
override val dispatchers: CoroutineDispatcherProvider,
|
||||
private val yieldSupplyGetProtocolBalanceUseCase: YieldSupplyGetProtocolBalanceUseCase,
|
||||
) : Model() {
|
||||
|
||||
private val params: YieldSupplyActiveComponent.Params = paramsContainer.require()
|
||||
|
|
@ -32,11 +35,7 @@ internal class YieldSupplyActiveModel @Inject constructor(
|
|||
field = MutableStateFlow(
|
||||
YieldSupplyActiveContentUM(
|
||||
totalEarnings = stringReference("0"),
|
||||
availableBalance = stringReference(
|
||||
cryptoCurrencyStatusFlow.value.value.amount.format {
|
||||
crypto(cryptoCurrency = cryptoCurrencyStatusFlow.value.currency)
|
||||
},
|
||||
),
|
||||
availableBalance = null,
|
||||
providerTitle = resourceReference(R.string.yield_module_provider),
|
||||
subtitle = resourceReference(
|
||||
id = R.string.yield_module_earn_sheet_provider_description,
|
||||
|
|
@ -49,10 +48,31 @@ internal class YieldSupplyActiveModel @Inject constructor(
|
|||
|
||||
init {
|
||||
subscribeOnCurrencyUpdates()
|
||||
|
||||
modelScope.launch {
|
||||
val protocolBalance = yieldSupplyGetProtocolBalanceUseCase(
|
||||
userWalletId = params.userWallet.walletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
).getOrNull()
|
||||
|
||||
stringReference(
|
||||
protocolBalance.format {
|
||||
crypto(
|
||||
symbol = AAVEV3_PREFIX + cryptoCurrency.symbol,
|
||||
decimals = cryptoCurrency.decimals,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun subscribeOnCurrencyUpdates() {
|
||||
cryptoCurrencyStatusFlow.onEach { cryptoCurrencyStatus ->
|
||||
val protocolBalance = yieldSupplyGetProtocolBalanceUseCase(
|
||||
userWalletId = params.userWallet.walletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
).getOrNull()
|
||||
|
||||
val approvalNotification = if (cryptoCurrencyStatus.value.yieldSupplyStatus?.isAllowedToSpend != true) {
|
||||
NotificationUM.Error(
|
||||
title = resourceReference(R.string.yield_module_approve_needed_notification_title),
|
||||
|
|
@ -67,8 +87,24 @@ internal class YieldSupplyActiveModel @Inject constructor(
|
|||
null
|
||||
}
|
||||
|
||||
uiState.update { it.copy(notificationUM = approvalNotification) }
|
||||
uiState.update {
|
||||
it.copy(
|
||||
notificationUM = approvalNotification,
|
||||
availableBalance = stringReference(
|
||||
protocolBalance.format {
|
||||
crypto(
|
||||
symbol = AAVEV3_PREFIX + cryptoCurrency.symbol,
|
||||
decimals = cryptoCurrency.decimals,
|
||||
)
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
}.flowOn(dispatchers.default)
|
||||
.launchIn(modelScope)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val AAVEV3_PREFIX = "a"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.features.yield.supply.impl.subcomponents.active.ui
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
|
|
@ -22,10 +23,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
|
|||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.tangem.common.ui.notifications.NotificationUM
|
||||
import com.tangem.core.ui.components.ResizableText
|
||||
import com.tangem.core.ui.components.SpacerH4
|
||||
import com.tangem.core.ui.components.SpacerH8
|
||||
import com.tangem.core.ui.components.SpacerWMax
|
||||
import com.tangem.core.ui.components.*
|
||||
import com.tangem.core.ui.components.notifications.Notification
|
||||
import com.tangem.core.ui.extensions.*
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
|
|
@ -152,7 +150,7 @@ private fun DescriptionText(state: YieldSupplyActiveContentUM) {
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun InfoRow(title: TextReference, info: TextReference) {
|
||||
private fun InfoRow(title: TextReference, info: TextReference?) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier.padding(horizontal = 4.dp, vertical = 12.dp),
|
||||
|
|
@ -163,11 +161,21 @@ private fun InfoRow(title: TextReference, info: TextReference) {
|
|||
color = TangemTheme.colors.text.primary1,
|
||||
)
|
||||
SpacerWMax()
|
||||
Text(
|
||||
text = info.resolveReference(),
|
||||
style = TangemTheme.typography.body1,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
|
||||
AnimatedContent(info) { currentInfo ->
|
||||
if (currentInfo != null) {
|
||||
Text(
|
||||
text = currentInfo.resolveReference(),
|
||||
style = TangemTheme.typography.body1,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
} else {
|
||||
TextShimmer(
|
||||
text = title.resolveReference(),
|
||||
style = TangemTheme.typography.body1,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue