Updated on 2026-08-14
This commit is contained in:
commit
e96c236de5
32 changed files with 433 additions and 82 deletions
|
|
@ -38,6 +38,7 @@ class AmountStateConverter(
|
|||
private val iconStateConverter: CryptoCurrencyToIconStateConverter,
|
||||
private val isBalanceHidden: Boolean,
|
||||
private val accountTitleUM: AccountTitleUM,
|
||||
private val isMaxButtonVisible: Boolean = true,
|
||||
) : Converter<AmountParameters, AmountState> {
|
||||
|
||||
private val amountFieldConverter by lazy(LazyThreadSafetyMode.NONE) {
|
||||
|
|
@ -72,6 +73,7 @@ class AmountStateConverter(
|
|||
amountTextField = amountFieldConverter.convert(value.value),
|
||||
isPrimaryButtonEnabled = false,
|
||||
appCurrency = appCurrency,
|
||||
isMaxButtonVisible = isMaxButtonVisible,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ sealed class AmountState {
|
|||
* @param isEditingDisabled indicated whether amount is editable
|
||||
* @param reduceAmountBy reduces amount to be sent by specified value
|
||||
* @param isIgnoreReduce ignores reduce amount value
|
||||
* @param isMaxButtonVisible indicates whether the "Max" button is shown
|
||||
*/
|
||||
data class Data(
|
||||
override val isPrimaryButtonEnabled: Boolean,
|
||||
|
|
@ -37,6 +38,7 @@ sealed class AmountState {
|
|||
val isEditingDisabled: Boolean = false,
|
||||
val reduceAmountBy: BigDecimal = BigDecimal.ZERO,
|
||||
val isIgnoreReduce: Boolean = false,
|
||||
val isMaxButtonVisible: Boolean = true,
|
||||
) : AmountState()
|
||||
|
||||
data object Empty : AmountState() {
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ internal fun LazyListScope.amountFieldV2(
|
|||
@Composable
|
||||
private fun AmountInfo(amountUM: AmountState, onMaxAmountClick: () -> Unit, modifier: Modifier = Modifier) {
|
||||
val tokenIconState = (amountUM as? AmountState.Data)?.tokenIconState ?: CurrencyIconState.Loading
|
||||
val isMaxButtonVisible = (amountUM as? AmountState.Data)?.isMaxButtonVisible != false
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
|
|
@ -106,22 +107,24 @@ private fun AmountInfo(amountUM: AmountState, onMaxAmountClick: () -> Unit, modi
|
|||
amountUM = amountUM,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
Text(
|
||||
text = stringResourceSafe(R.string.send_max_amount),
|
||||
style = TangemTheme.typography.caption1,
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
modifier = Modifier
|
||||
.padding(end = 16.dp)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(TangemTheme.colors.button.secondary)
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = ripple(),
|
||||
onClick = onMaxAmountClick,
|
||||
)
|
||||
.padding(horizontal = 12.dp, vertical = 4.dp)
|
||||
.testTag(SendScreenTestTags.MAX_BUTTON),
|
||||
)
|
||||
if (isMaxButtonVisible) {
|
||||
Text(
|
||||
text = stringResourceSafe(R.string.send_max_amount),
|
||||
style = TangemTheme.typography.caption1,
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
modifier = Modifier
|
||||
.padding(end = 16.dp)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(TangemTheme.colors.button.secondary)
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = ripple(),
|
||||
onClick = onMaxAmountClick,
|
||||
)
|
||||
.padding(horizontal = 12.dp, vertical = 4.dp)
|
||||
.testTag(SendScreenTestTags.MAX_BUTTON),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
package com.tangem.common.ui.amountScreen.converters
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.tangem.common.ui.account.AccountTitleUM
|
||||
import com.tangem.common.ui.amountScreen.AmountScreenClickIntents
|
||||
import com.tangem.common.ui.amountScreen.models.AmountParameters
|
||||
import com.tangem.common.ui.amountScreen.models.AmountState
|
||||
import com.tangem.common.ui.amountScreen.models.EnterAmountBoundary
|
||||
import com.tangem.common.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter
|
||||
import com.tangem.core.ui.components.currency.icon.CurrencyIconState
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.math.BigDecimal
|
||||
|
||||
internal class AmountStateConverterTest {
|
||||
|
||||
private val currency = mockk<CryptoCurrency.Coin> {
|
||||
every { symbol } returns "ETH"
|
||||
every { decimals } returns 18
|
||||
every { name } returns "Ethereum"
|
||||
}
|
||||
private val status = CryptoCurrencyStatus(currency = currency, value = mockk(relaxed = true))
|
||||
private val iconStateConverter = mockk<CryptoCurrencyToIconStateConverter> {
|
||||
every { convert(any<CryptoCurrency>()) } returns CurrencyIconState.Loading
|
||||
}
|
||||
private val clickIntents = mockk<AmountScreenClickIntents>(relaxed = true)
|
||||
private val accountTitleUM = mockk<AccountTitleUM>()
|
||||
|
||||
private fun convert(isMaxButtonVisible: Boolean = true): AmountState = AmountStateConverter(
|
||||
clickIntents = clickIntents,
|
||||
appCurrency = AppCurrency.Default,
|
||||
cryptoCurrencyStatus = status,
|
||||
maxEnterAmount = EnterAmountBoundary(
|
||||
amount = BigDecimal.ONE,
|
||||
fiatAmount = BigDecimal.TEN,
|
||||
fiatRate = BigDecimal.ONE,
|
||||
),
|
||||
iconStateConverter = iconStateConverter,
|
||||
isBalanceHidden = false,
|
||||
accountTitleUM = accountTitleUM,
|
||||
isMaxButtonVisible = isMaxButtonVisible,
|
||||
).convert(AmountParameters(title = stringReference("Wallet"), value = ""))
|
||||
|
||||
@Test
|
||||
fun `GIVEN no isMaxButtonVisible param WHEN convert THEN Data isMaxButtonVisible is true`() {
|
||||
val result = convert()
|
||||
|
||||
assertThat((result as AmountState.Data).isMaxButtonVisible).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN isMaxButtonVisible false WHEN convert THEN Data isMaxButtonVisible is false`() {
|
||||
val result = convert(isMaxButtonVisible = false)
|
||||
|
||||
assertThat((result as AmountState.Data).isMaxButtonVisible).isFalse()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue