Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-07 15:08:26 +03:00
commit 2a5e3fa7eb
220 changed files with 5932 additions and 1815 deletions

View file

@ -113,6 +113,7 @@ data class TxFee(
val decimals: Int,
val cryptoSymbol: String,
val feeType: FeeType,
val gasPremium: Long?,
)
enum class FeeType {

View file

@ -888,6 +888,21 @@ internal class SwapInteractorImpl @Inject constructor(
gasLimit = fee.gasLimit.toLong(),
)
}
blockchain == Blockchain.Filecoin -> {
val gasUnitPrice = fee.feeValue.divide(
BigDecimal(fee.gasLimit),
Blockchain.Filecoin.decimals(),
RoundingMode.HALF_UP,
)
Fee.Filecoin(
amount = feeAmount,
gasUnitPrice = gasUnitPrice
.movePointRight(Blockchain.Filecoin.decimals())
.toLong(),
gasLimit = fee.gasLimit.toLong(),
gasPremium = requireNotNull(fee.gasPremium),
)
}
else -> Fee.Common(feeAmount)
}
}
@ -1579,6 +1594,7 @@ internal class SwapInteractorImpl @Inject constructor(
decimals = minFee.fee.decimals,
cryptoSymbol = minFee.fee.currencySymbol,
feeType = FeeType.NORMAL,
gasPremium = (minFee as? ProxyFee.Filecoin)?.gasPremium,
),
priorityFee = TxFee(
feeValue = priorityFeeValue,
@ -1591,6 +1607,7 @@ internal class SwapInteractorImpl @Inject constructor(
decimals = normalFee.fee.decimals,
cryptoSymbol = normalFee.fee.currencySymbol,
feeType = FeeType.PRIORITY,
gasPremium = (normalFee as? ProxyFee.Filecoin)?.gasPremium,
),
)
}
@ -1633,6 +1650,7 @@ internal class SwapInteractorImpl @Inject constructor(
decimals = singleFee.fee.decimals,
cryptoSymbol = singleFee.fee.currencySymbol,
feeType = FeeType.NORMAL,
gasPremium = (singleFee as? ProxyFee.Filecoin)?.gasPremium,
),
)
}
@ -1688,6 +1706,7 @@ internal class SwapInteractorImpl @Inject constructor(
decimals = normalFee.amount.decimals,
cryptoSymbol = normalFee.amount.currencySymbol,
feeType = FeeType.NORMAL,
gasPremium = (normalFee as? Fee.Filecoin)?.gasPremium,
),
priorityFee = TxFee(
feeValue = feePriority,
@ -1700,6 +1719,7 @@ internal class SwapInteractorImpl @Inject constructor(
decimals = priorityFee.amount.decimals,
cryptoSymbol = priorityFee.amount.currencySymbol,
feeType = FeeType.PRIORITY,
gasPremium = (priorityFee as? Fee.Filecoin)?.gasPremium,
),
)
}
@ -1731,6 +1751,7 @@ internal class SwapInteractorImpl @Inject constructor(
decimals = normal.amount.decimals,
cryptoSymbol = normal.amount.currencySymbol,
feeType = FeeType.NORMAL,
gasPremium = (normal as? Fee.Filecoin)?.gasPremium,
),
)
}
@ -1778,6 +1799,7 @@ internal class SwapInteractorImpl @Inject constructor(
is Fee.Ethereum -> gasLimit.toInt()
is Fee.VeChain -> gasLimit.toInt()
is Fee.Aptos -> gasLimit.toInt()
is Fee.Filecoin -> gasLimit.toInt()
else -> 0
}
}

View file

@ -0,0 +1,20 @@
package com.tangem.feature.swap.preview
import com.tangem.core.ui.extensions.stringReference
import com.tangem.feature.swap.domain.models.ui.FeeType
import com.tangem.feature.swap.models.states.FeeItemState
object FeeItemStatePreview {
val state = FeeItemState.Content(
feeType = FeeType.NORMAL,
title = stringReference("Fee"),
amountCrypto = "1000",
symbolCrypto = "MATIC",
amountFiatFormatted = "(1000$)",
isClickable = false,
onClick = {},
)
val stateClickable = state.copy(isClickable = true)
}

View file

@ -1,20 +1,21 @@
package com.tangem.feature.swap.ui
import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.tooling.preview.Preview
import com.tangem.core.ui.components.SpacerH24
import com.tangem.core.ui.components.rows.SimpleActionRow
import com.tangem.core.ui.extensions.resolveReference
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.tangem.core.ui.components.inputrow.InputRowDefault
import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.feature.swap.domain.models.ui.FeeType
import com.tangem.feature.swap.models.states.FeeItemState
import com.tangem.feature.swap.presentation.R
import com.tangem.feature.swap.preview.FeeItemStatePreview
@Composable
fun FeeItemBlock(state: FeeItemState) {
@ -25,53 +26,37 @@ fun FeeItemBlock(state: FeeItemState) {
@Composable
fun FeeItem(state: FeeItemState.Content) {
Box(
val description = "${state.amountCrypto}${state.symbolCrypto} (${state.amountFiatFormatted})"
val icon = R.drawable.ic_chevron_right_24.takeIf { state.isClickable }
InputRowDefault(
title = state.title,
text = stringReference(description),
iconRes = icon,
modifier = Modifier
.background(
color = TangemTheme.colors.background.action,
shape = TangemTheme.shapes.roundedCornersXMedium,
)
.clip(shape = TangemTheme.shapes.roundedCornersXMedium)
.background(color = TangemTheme.colors.background.action)
.clickable(
enabled = state.isClickable,
onClick = state.onClick,
)
.fillMaxWidth()
.defaultMinSize(minHeight = TangemTheme.dimens.size68),
) {
val description = "${state.amountCrypto}${state.symbolCrypto} (${state.amountFiatFormatted})"
SimpleActionRow(
modifier = Modifier.padding(
start = TangemTheme.dimens.spacing12,
top = TangemTheme.dimens.spacing12,
),
title = state.title.resolveReference(),
description = description,
isClickable = state.isClickable,
)
)
}
// region Preview
@Preview(showBackground = true, widthDp = 360)
@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun FeeItem_Preview(@PreviewParameter(FeeItemPreviewProvider::class) data: FeeItemState.Content) {
TangemThemePreview {
FeeItem(data)
}
}
@Preview
@Composable
private fun FeeItemPreview() {
val state = FeeItemState.Content(
feeType = FeeType.NORMAL,
title = stringReference("Fee"),
amountCrypto = "1000",
symbolCrypto = "MATIC",
amountFiatFormatted = "(1000$)",
isClickable = false,
onClick = {},
)
Column {
TangemThemePreview(isDark = false) {
FeeItem(state = state)
}
SpacerH24()
TangemThemePreview(isDark = true) {
FeeItem(state = state)
}
}
}
private class FeeItemPreviewProvider : PreviewParameterProvider<FeeItemState.Content> {
override val values: Sequence<FeeItemState.Content>
get() = sequenceOf(
FeeItemStatePreview.state,
FeeItemStatePreview.state.copy(isClickable = true),
)
}
// endregion

View file

@ -263,7 +263,7 @@ private fun ProviderLoadingState(modifier: Modifier = Modifier) {
Column {
Text(
text = stringResource(R.string.express_provider),
style = TangemTheme.typography.caption2,
style = TangemTheme.typography.subtitle2,
color = TangemTheme.colors.text.secondary,
modifier = Modifier.padding(start = TangemTheme.dimens.spacing12),
)