Updated on 2026-08-14
This commit is contained in:
parent
3a5144403b
commit
eeb74486ef
5 changed files with 89 additions and 186 deletions
|
|
@ -85,7 +85,7 @@ import com.tangem.domain.transaction.error.OpenTrustlineError
|
|||
import com.tangem.domain.transaction.error.SendTransactionError
|
||||
import com.tangem.domain.transaction.usecase.*
|
||||
import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase
|
||||
import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase
|
||||
import com.tangem.domain.txhistory.usecase.GetFixedTxHistoryItemsUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetExploreUrlUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetWalletIconUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetExtendedPublicKeyForCurrencyUseCase
|
||||
|
|
@ -197,7 +197,7 @@ internal class TokenDetailsModel @Inject constructor(
|
|||
private val swapFeedbackUseCase: SwapFeedbackUseCase,
|
||||
private val swapFeatureToggles: SwapFeatureToggles,
|
||||
private val quickTopUpBlockFactory: QuickTopUpBlockFactory,
|
||||
private val getTxHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase,
|
||||
private val getFixedTxHistoryItemsUseCase: GetFixedTxHistoryItemsUseCase,
|
||||
private val checkOnrampAvailabilityUseCase: CheckOnrampAvailabilityUseCase,
|
||||
) : Model(),
|
||||
TokenDetailsClickIntents,
|
||||
|
|
@ -1424,12 +1424,18 @@ internal class TokenDetailsModel @Inject constructor(
|
|||
emit(null)
|
||||
return@flow
|
||||
}
|
||||
val txCount = getTxHistoryItemsCountUseCase(userWalletId, cryptoCurrency)
|
||||
val isHistoryEmpty = getFixedTxHistoryItemsUseCase.getSync(
|
||||
userWalletId = userWalletId,
|
||||
currency = cryptoCurrency,
|
||||
).fold(
|
||||
ifLeft = { true },
|
||||
ifRight = { it.isEmpty() },
|
||||
)
|
||||
val availability = checkOnrampAvailabilityUseCase(userWallet)
|
||||
emit(
|
||||
quickTopUpBlockFactory.build(
|
||||
currencyStatus = status,
|
||||
isTxHistoryEmpty = txCount,
|
||||
isHistoryEmpty = isHistoryEmpty,
|
||||
onrampAvailability = availability,
|
||||
onPresetClick = ::onQuickTopUpClick,
|
||||
onOtherClick = ::onQuickTopUpOtherClick,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import com.tangem.core.ui.extensions.stringReference
|
|||
import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
||||
import com.tangem.domain.onramp.model.OnrampAvailability
|
||||
import com.tangem.domain.onramp.model.error.OnrampError
|
||||
import com.tangem.domain.txhistory.models.TxHistoryStateError
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.QuickTopUpBlockUM
|
||||
import com.tangem.features.tokendetails.TokenDetailsFeatureToggles
|
||||
import com.tangem.utils.extensions.isZero
|
||||
|
|
@ -21,7 +20,7 @@ internal class QuickTopUpBlockFactory @Inject constructor(
|
|||
|
||||
fun build(
|
||||
currencyStatus: CryptoCurrencyStatus,
|
||||
isTxHistoryEmpty: Either<TxHistoryStateError, Int>,
|
||||
isHistoryEmpty: Boolean,
|
||||
onrampAvailability: Either<OnrampError, OnrampAvailability>,
|
||||
onPresetClick: (BigDecimal, String) -> Unit,
|
||||
onOtherClick: () -> Unit,
|
||||
|
|
@ -31,10 +30,6 @@ internal class QuickTopUpBlockFactory @Inject constructor(
|
|||
val amount = currencyStatus.value.amount
|
||||
if (amount == null || !amount.isZero()) return null
|
||||
|
||||
val isHistoryEmpty = isTxHistoryEmpty.fold(
|
||||
ifLeft = { it is TxHistoryStateError.EmptyTxHistories },
|
||||
ifRight = { it == 0 },
|
||||
)
|
||||
if (!isHistoryEmpty) return null
|
||||
|
||||
val currency = when (val availability = onrampAvailability.getOrNull()) {
|
||||
|
|
|
|||
|
|
@ -1,102 +1,75 @@
|
|||
package com.tangem.feature.tokendetails.presentation.tokendetails.ui
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.BlendMode
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.util.fastForEach
|
||||
import com.tangem.core.res.R
|
||||
import com.tangem.core.ui.ds.button.PrimaryInverseTangemButton
|
||||
import com.tangem.core.ui.ds.button.TangemButtonShape
|
||||
import com.tangem.core.ui.ds.button.TangemButtonSize
|
||||
import com.tangem.core.ui.ds.message.TangemMessageEffect
|
||||
import com.tangem.core.ui.ds.message.messageEffectBackground
|
||||
import com.tangem.core.ui.extensions.combinedReference
|
||||
import com.tangem.core.ui.extensions.resolveReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.utils.StringsSigns
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreviewRedesign
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.QuickTopUpBlockUM
|
||||
import com.tangem.utils.StringsSigns
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
||||
private val quickTopUpGradientBrush = Brush.linearGradient(
|
||||
colors = listOf(Color(0xFFEDE5F3), Color(0xFFD7EDD9)),
|
||||
start = Offset(0f, 0f),
|
||||
end = Offset(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY),
|
||||
)
|
||||
|
||||
private val quickTopUpBorderBrush = Brush.sweepGradient(
|
||||
listOf(
|
||||
Color(0x0D000000),
|
||||
Color(0x26000000),
|
||||
Color(0x0D000000),
|
||||
Color(0x26000000),
|
||||
),
|
||||
)
|
||||
|
||||
@Composable
|
||||
internal fun QuickTopUpBlock(state: QuickTopUpBlockUM, modifier: Modifier = Modifier) {
|
||||
val shape = RoundedCornerShape(TangemTheme.dimens.radius20)
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(shape)
|
||||
.background(brush = quickTopUpGradientBrush)
|
||||
.border(width = 1.dp, brush = quickTopUpBorderBrush, shape = shape),
|
||||
) {
|
||||
Box(modifier = modifier.fillMaxWidth()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.matchParentSize()
|
||||
.messageEffectBackground(
|
||||
messageEffect = TangemMessageEffect.Magic,
|
||||
radius = TangemTheme.dimens2.x6,
|
||||
contentColor = TangemTheme.colors2.surface.level3,
|
||||
),
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier.padding(TangemTheme.dimens.spacing12),
|
||||
verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing16),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(TangemTheme.dimens2.x3),
|
||||
verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens2.x4),
|
||||
) {
|
||||
val textColor = TangemTheme.colors.text.primary1
|
||||
val titleColor = TangemTheme.colors2.text.neutral.primary
|
||||
Text(
|
||||
text = combinedReference(
|
||||
stringReference("${StringsSigns.LIGHTNING} "),
|
||||
resourceReference(R.string.quick_top_up_title),
|
||||
).resolveReference(),
|
||||
style = TangemTheme.typography.subtitle1.copy(fontWeight = FontWeight.SemiBold),
|
||||
style = TangemTheme.typography2.bodySemibold16,
|
||||
modifier = Modifier.graphicsLayer {
|
||||
colorFilter = ColorFilter.tint(textColor, BlendMode.SrcIn)
|
||||
colorFilter = ColorFilter.tint(titleColor, BlendMode.SrcIn)
|
||||
},
|
||||
)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing6),
|
||||
horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens2.x1_5),
|
||||
) {
|
||||
state.amounts.fastForEach { amountUM ->
|
||||
Button(
|
||||
PrimaryInverseTangemButton(
|
||||
text = amountUM.displayValue,
|
||||
onClick = amountUM.onClick,
|
||||
shape = CircleShape,
|
||||
contentPadding = PaddingValues(
|
||||
horizontal = TangemTheme.dimens.spacing12,
|
||||
vertical = TangemTheme.dimens.spacing0,
|
||||
),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = TangemTheme.colors.background.primary,
|
||||
contentColor = TangemTheme.colors.text.primary1,
|
||||
),
|
||||
modifier = Modifier.heightIn(TangemTheme.dimens.size36),
|
||||
elevation = null,
|
||||
) {
|
||||
Text(
|
||||
text = amountUM.displayValue.resolveReference(),
|
||||
style = TangemTheme.typography.subtitle1.copy(fontWeight = FontWeight.SemiBold),
|
||||
)
|
||||
}
|
||||
size = TangemButtonSize.X9,
|
||||
shape = TangemButtonShape.Rounded,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -104,6 +77,7 @@ internal fun QuickTopUpBlock(state: QuickTopUpBlockUM, modifier: Modifier = Modi
|
|||
}
|
||||
|
||||
@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||
@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Composable
|
||||
private fun QuickTopUpBlock_Preview() {
|
||||
TangemThemePreviewRedesign {
|
||||
|
|
@ -129,7 +103,7 @@ private fun QuickTopUpBlock_Preview() {
|
|||
),
|
||||
),
|
||||
),
|
||||
modifier = Modifier.padding(TangemTheme.dimens.spacing12),
|
||||
modifier = Modifier.padding(TangemTheme.dimens2.x3),
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue