Updated on 2026-08-14
This commit is contained in:
parent
c7792de43b
commit
ebc4350919
9 changed files with 2218 additions and 8 deletions
|
|
@ -54,6 +54,7 @@ import com.tangem.features.send.v2.send.confirm.model.transformers.SendConfirmIn
|
|||
import com.tangem.features.send.v2.send.confirm.model.transformers.SendConfirmSendingStateTransformer
|
||||
import com.tangem.features.send.v2.send.confirm.model.transformers.SendConfirmSentStateTransformer
|
||||
import com.tangem.features.send.v2.send.confirm.model.transformers.SendConfirmationNotificationsTransformer
|
||||
import com.tangem.features.send.v2.send.confirm.model.transformers.SendConfirmationNotificationsTransformerV2
|
||||
import com.tangem.features.send.v2.send.ui.state.SendUM
|
||||
import com.tangem.features.send.v2.subcomponents.fee.SendFeeCheckReloadListener
|
||||
import com.tangem.features.send.v2.subcomponents.fee.SendFeeCheckReloadTrigger
|
||||
|
|
@ -474,14 +475,25 @@ internal class SendConfirmModel @Inject constructor(
|
|||
)
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
confirmUM = SendConfirmationNotificationsTransformer(
|
||||
feeUM = uiState.value.feeUM,
|
||||
amountUM = uiState.value.amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrencyStatus.currency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = params.analyticsCategoryName,
|
||||
).transform(uiState.value.confirmUM),
|
||||
confirmUM = if (uiState.value.isRedesignEnabled) {
|
||||
SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = uiState.value.feeSelectorUM,
|
||||
amountUM = uiState.value.amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrencyStatus.currency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = params.analyticsCategoryName,
|
||||
).transform(uiState.value.confirmUM)
|
||||
} else {
|
||||
SendConfirmationNotificationsTransformer(
|
||||
feeUM = uiState.value.feeUM,
|
||||
amountUM = uiState.value.amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrencyStatus.currency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = params.analyticsCategoryName,
|
||||
).transform(uiState.value.confirmUM)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,110 @@
|
|||
package com.tangem.features.send.v2.send.confirm.model.transformers
|
||||
|
||||
import com.tangem.blockchain.common.transaction.Fee
|
||||
import com.tangem.common.ui.amountScreen.models.AmountState
|
||||
import com.tangem.common.ui.notifications.NotificationUM
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.core.ui.extensions.wrappedList
|
||||
import com.tangem.core.ui.format.bigdecimal.fiat
|
||||
import com.tangem.core.ui.format.bigdecimal.format
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.features.send.v2.api.entity.FeeSelectorUM
|
||||
import com.tangem.features.send.v2.api.subcomponents.feeSelector.utils.FeeCalculationUtils
|
||||
import com.tangem.features.send.v2.common.analytics.CommonSendAnalyticEvents
|
||||
import com.tangem.features.send.v2.common.ui.state.ConfirmUM
|
||||
import com.tangem.features.send.v2.common.utils.formatFooterFiatFee
|
||||
import com.tangem.features.send.v2.common.utils.getTronTokenFeeSendingText
|
||||
import com.tangem.features.send.v2.impl.R
|
||||
import com.tangem.utils.transformer.Transformer
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
internal class SendConfirmationNotificationsTransformerV2(
|
||||
private val feeSelectorUM: FeeSelectorUM,
|
||||
private val amountUM: AmountState,
|
||||
private val analyticsEventHandler: AnalyticsEventHandler,
|
||||
private val cryptoCurrency: CryptoCurrency,
|
||||
private val appCurrency: AppCurrency,
|
||||
private val analyticsCategoryName: String,
|
||||
) : Transformer<ConfirmUM> {
|
||||
override fun transform(prevState: ConfirmUM): ConfirmUM {
|
||||
val state = prevState as? ConfirmUM.Content ?: return prevState
|
||||
val feeSelectorUM = feeSelectorUM as? FeeSelectorUM.Content ?: return prevState
|
||||
return state.copy(
|
||||
sendingFooter = getSendingFooterText(),
|
||||
notifications = buildList {
|
||||
addTooHighNotification(feeSelectorUM)
|
||||
addTooLowNotification(feeSelectorUM)
|
||||
}.toPersistentList(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun MutableList<NotificationUM>.addTooLowNotification(feeSelectorUM: FeeSelectorUM.Content) {
|
||||
if (FeeCalculationUtils.checkIfCustomFeeTooLow(feeSelectorUM)) {
|
||||
add(NotificationUM.Warning.FeeTooLow)
|
||||
analyticsEventHandler.send(
|
||||
CommonSendAnalyticEvents.NoticeTransactionDelays(
|
||||
categoryName = analyticsCategoryName,
|
||||
token = cryptoCurrency.symbol,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun MutableList<NotificationUM>.addTooHighNotification(feeSelectorUM: FeeSelectorUM.Content) {
|
||||
val (isFeeTooHigh, diff) = FeeCalculationUtils.checkIfCustomFeeTooHigh(feeSelectorUM)
|
||||
if (isFeeTooHigh) {
|
||||
add(NotificationUM.Warning.TooHigh(diff))
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSendingFooterText(): TextReference {
|
||||
val feeSelectorUM = feeSelectorUM as? FeeSelectorUM.Content
|
||||
val amountUM = amountUM as? AmountState.Data
|
||||
val fee = feeSelectorUM?.selectedFeeItem?.fee
|
||||
|
||||
if (fee == null || amountUM == null) return TextReference.EMPTY
|
||||
|
||||
val fiatAmountValue = amountUM.amountTextField.fiatAmount.value
|
||||
val fiatFeeValue = feeSelectorUM.feeFiatRateUM?.rate?.let { fee.amount.value?.multiply(it) }
|
||||
|
||||
val fiatSendingValue = if (feeSelectorUM.feeFiatRateUM != null) {
|
||||
fiatFeeValue?.let { fiatAmountValue?.plus(it) }
|
||||
} else {
|
||||
fiatAmountValue
|
||||
}
|
||||
|
||||
val fiatSending = fiatSendingValue.format {
|
||||
fiat(
|
||||
fiatCurrencyCode = appCurrency.code,
|
||||
fiatCurrencySymbol = appCurrency.symbol,
|
||||
)
|
||||
}
|
||||
val fiatFee = formatFooterFiatFee(
|
||||
amount = fee.amount.copy(value = fiatFeeValue),
|
||||
isFeeConvertibleToFiat = feeSelectorUM.feeFiatRateUM != null,
|
||||
isFeeApproximate = feeSelectorUM.isFeeApproximate,
|
||||
appCurrency = appCurrency,
|
||||
)
|
||||
|
||||
return if (fee is Fee.Tron) {
|
||||
getTronTokenFeeSendingText(
|
||||
fee = fee,
|
||||
fiatFee = fiatFee,
|
||||
fiatSending = stringReference(fiatSending),
|
||||
)
|
||||
} else {
|
||||
resourceReference(
|
||||
id = if (feeSelectorUM.feeFiatRateUM != null) {
|
||||
R.string.send_summary_transaction_description
|
||||
} else {
|
||||
R.string.send_summary_transaction_description_no_fiat_fee
|
||||
},
|
||||
formatArgs = wrappedList(fiatSending, fiatFee),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,439 @@
|
|||
package com.tangem.features.send.v2.send.confirm.model.transformers
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.tangem.blockchain.common.transaction.Fee
|
||||
import com.tangem.blockchain.common.transaction.TransactionFee
|
||||
import com.tangem.common.ui.amountScreen.models.AmountState
|
||||
import com.tangem.common.ui.amountScreen.models.AmountFieldModel
|
||||
import com.tangem.common.ui.notifications.NotificationUM
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.features.send.v2.common.ui.state.ConfirmUM
|
||||
import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeUM
|
||||
import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeSelectorUM
|
||||
import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeType
|
||||
import com.tangem.features.send.v2.api.entity.CustomFeeFieldUM
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import java.math.BigDecimal
|
||||
import java.math.BigInteger
|
||||
import java.util.Locale
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
|
||||
class SendConfirmationNotificationsTransformerTest {
|
||||
|
||||
private val analyticsEventHandler: AnalyticsEventHandler = mockk(relaxed = true)
|
||||
private val cryptoCurrency: CryptoCurrency = mockk(relaxed = true)
|
||||
private val appCurrency = AppCurrency(name = "US Dollar", code = "USD", symbol = "$")
|
||||
private val analyticsCategoryName = "test_category"
|
||||
|
||||
@Test
|
||||
fun `GIVEN non content state WHEN transform THEN returns original state`() = runTest {
|
||||
// GIVEN
|
||||
val feeUM: FeeUM = mockk(relaxed = true)
|
||||
val amountUM: AmountState = mockk(relaxed = true)
|
||||
val transformer = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState: ConfirmUM = ConfirmUM.Empty
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isEqualTo(initialState)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fee UM not content WHEN transform THEN returns original state`() = runTest {
|
||||
// GIVEN
|
||||
val feeUM: FeeUM = FeeUM.Empty()
|
||||
val amountUM: AmountState = mockk(relaxed = true)
|
||||
val transformer = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState: ConfirmUM.Content = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isEqualTo(initialState)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN normal fee WHEN transform THEN returns state with footer and no notifications`() = runTest {
|
||||
// GIVEN
|
||||
val feeUM = createNormalFeeUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
val transformer = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
val content = result as ConfirmUM.Content
|
||||
assertThat(content.notifications).isEmpty()
|
||||
assertThat(content.sendingFooter).isNotEqualTo(initialState.sendingFooter)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fee too high WHEN transform THEN returns state with too high notification`() = runTest {
|
||||
// GIVEN
|
||||
val feeUM = createFeeTooHighUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
val transformer = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
val content = result as ConfirmUM.Content
|
||||
assertThat(content.notifications).hasSize(1)
|
||||
assertThat(content.notifications.first()).isInstanceOf(NotificationUM.Warning.TooHigh::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fee too low WHEN transform THEN returns state with too low notification`() = runTest {
|
||||
// GIVEN
|
||||
val feeUM = createFeeTooLowUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
val transformer = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
val content = result as ConfirmUM.Content
|
||||
assertThat(content.notifications).hasSize(1)
|
||||
assertThat(content.notifications.first()).isInstanceOf(NotificationUM.Warning.FeeTooLow::class.java)
|
||||
verify { analyticsEventHandler.send(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN both fee too high and too low WHEN transform THEN returns state with both notifications`() = runTest {
|
||||
// GIVEN
|
||||
val feeUM = createFeeTooHighAndTooLowUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
val transformer = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
val content = result as ConfirmUM.Content
|
||||
assertThat(content.notifications).hasSize(2)
|
||||
assertThat(content.notifications.any { it is NotificationUM.Warning.TooHigh }).isTrue()
|
||||
assertThat(content.notifications.any { it is NotificationUM.Warning.FeeTooLow }).isTrue()
|
||||
}
|
||||
|
||||
private fun createTestConfirmUM(): ConfirmUM.Content {
|
||||
return ConfirmUM.Content(
|
||||
isPrimaryButtonEnabled = true,
|
||||
walletName = mockk(relaxed = true),
|
||||
isSending = false,
|
||||
showTapHelp = false,
|
||||
sendingFooter = mockk(relaxed = true),
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createTestAmountUM(): AmountState.Data {
|
||||
val cryptoAmount = com.tangem.domain.tokens.model.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("1.5"),
|
||||
decimals = 8,
|
||||
)
|
||||
val fiatAmount = com.tangem.domain.tokens.model.Amount(
|
||||
currencySymbol = "USD",
|
||||
value = BigDecimal("50.00"),
|
||||
decimals = 2,
|
||||
)
|
||||
|
||||
return AmountState.Data(
|
||||
isPrimaryButtonEnabled = true,
|
||||
isRedesignEnabled = false,
|
||||
title = mockk(relaxed = true),
|
||||
availableBalance = mockk(relaxed = true),
|
||||
tokenName = mockk(relaxed = true),
|
||||
tokenIconState = mockk(relaxed = true),
|
||||
segmentedButtonConfig = persistentListOf(),
|
||||
selectedButton = 0,
|
||||
isSegmentedButtonsEnabled = false,
|
||||
amountTextField = AmountFieldModel(
|
||||
value = "1.5",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
cryptoAmount = cryptoAmount,
|
||||
fiatAmount = fiatAmount,
|
||||
isFiatValue = false,
|
||||
fiatValue = "50.00",
|
||||
isFiatUnavailable = false,
|
||||
isValuePasted = false,
|
||||
onValuePastedTriggerDismiss = {},
|
||||
isError = false,
|
||||
isWarning = false,
|
||||
error = mockk(relaxed = true),
|
||||
),
|
||||
appCurrency = appCurrency,
|
||||
isEditingDisabled = false,
|
||||
reduceAmountBy = BigDecimal.ZERO,
|
||||
isIgnoreReduce = false,
|
||||
)
|
||||
}
|
||||
|
||||
private fun createNormalFeeUM(): FeeUM.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = com.tangem.blockchain.common.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Single(fee)
|
||||
return FeeUM.Content(
|
||||
feeSelectorUM = FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
selectedType = FeeType.Market,
|
||||
selectedFee = fee,
|
||||
customValues = persistentListOf(),
|
||||
nonce = BigInteger.ZERO,
|
||||
),
|
||||
rate = BigDecimal("50000"),
|
||||
isFeeConvertibleToFiat = true,
|
||||
isFeeApproximate = false,
|
||||
isTronToken = false,
|
||||
isEditingDisabled = false,
|
||||
isPrimaryButtonEnabled = true,
|
||||
appCurrency = AppCurrency.Default,
|
||||
isCustomSelected = false,
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooHighUM(): FeeUM.Content {
|
||||
val priorityFee = Fee.Common(
|
||||
amount = com.tangem.blockchain.common.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = com.tangem.blockchain.common.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val customFee = Fee.Common(
|
||||
amount = com.tangem.blockchain.common.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.01"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = minimumFee,
|
||||
priority = priorityFee,
|
||||
)
|
||||
return FeeUM.Content(
|
||||
feeSelectorUM = FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
selectedType = FeeType.Custom,
|
||||
selectedFee = customFee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.01",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "SOL",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
nonce = BigInteger.ZERO,
|
||||
),
|
||||
rate = BigDecimal("50000"),
|
||||
isFeeConvertibleToFiat = true,
|
||||
isFeeApproximate = false,
|
||||
isTronToken = false,
|
||||
isEditingDisabled = false,
|
||||
isPrimaryButtonEnabled = true,
|
||||
appCurrency = AppCurrency.Default,
|
||||
isCustomSelected = false,
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooLowUM(): FeeUM.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = com.tangem.blockchain.common.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.0001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = com.tangem.blockchain.common.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = fee,
|
||||
priority = fee,
|
||||
)
|
||||
return FeeUM.Content(
|
||||
feeSelectorUM = FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
selectedType = FeeType.Custom,
|
||||
selectedFee = fee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.0001",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "SOL",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
nonce = BigInteger.ZERO,
|
||||
),
|
||||
rate = BigDecimal("50000"),
|
||||
isFeeConvertibleToFiat = true,
|
||||
isFeeApproximate = false,
|
||||
isTronToken = false,
|
||||
isEditingDisabled = false,
|
||||
isPrimaryButtonEnabled = true,
|
||||
appCurrency = AppCurrency.Default,
|
||||
isCustomSelected = false,
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooHighAndTooLowUM(): FeeUM.Content {
|
||||
val priorityFee = Fee.Common(
|
||||
amount = com.tangem.blockchain.common.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = com.tangem.blockchain.common.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.01"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val customFee = Fee.Common(
|
||||
amount = com.tangem.blockchain.common.Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.008"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = minimumFee,
|
||||
priority = priorityFee,
|
||||
)
|
||||
return FeeUM.Content(
|
||||
feeSelectorUM = FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
selectedType = FeeType.Custom,
|
||||
selectedFee = customFee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.008",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "SOL",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
nonce = BigInteger.ZERO,
|
||||
),
|
||||
rate = BigDecimal("50000"),
|
||||
isFeeConvertibleToFiat = true,
|
||||
isFeeApproximate = false,
|
||||
isTronToken = false,
|
||||
isEditingDisabled = false,
|
||||
isPrimaryButtonEnabled = true,
|
||||
appCurrency = AppCurrency.Default,
|
||||
isCustomSelected = false,
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun setUpLocale() {
|
||||
Locale.setDefault(Locale.US)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,488 @@
|
|||
package com.tangem.features.send.v2.send.confirm.model.transformers
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.tangem.blockchain.common.Amount
|
||||
import com.tangem.blockchain.common.transaction.Fee
|
||||
import com.tangem.blockchain.common.transaction.TransactionFee
|
||||
import com.tangem.common.ui.amountScreen.models.AmountState
|
||||
import com.tangem.common.ui.amountScreen.models.AmountFieldModel
|
||||
import com.tangem.common.ui.notifications.NotificationUM
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.Amount as DomainAmount
|
||||
import com.tangem.features.send.v2.api.entity.FeeSelectorUM
|
||||
import com.tangem.features.send.v2.api.entity.FeeItem
|
||||
import com.tangem.features.send.v2.api.entity.FeeFiatRateUM
|
||||
import com.tangem.features.send.v2.api.entity.CustomFeeFieldUM
|
||||
import com.tangem.features.send.v2.common.ui.state.ConfirmUM
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import java.math.BigDecimal
|
||||
import java.math.BigInteger
|
||||
import java.util.Locale
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
|
||||
class SendConfirmationNotificationsTransformerV2Test {
|
||||
|
||||
private val analyticsEventHandler: AnalyticsEventHandler = mockk(relaxed = true)
|
||||
private val cryptoCurrency: CryptoCurrency = mockk(relaxed = true)
|
||||
private val appCurrency = AppCurrency(name = "US Dollar", code = "USD", symbol = "$")
|
||||
private val analyticsCategoryName = "test_category"
|
||||
|
||||
@Test
|
||||
fun `GIVEN non content state WHEN transform THEN returns original state`() = runTest {
|
||||
// GIVEN
|
||||
val feeSelectorUM: FeeSelectorUM = mockk(relaxed = true)
|
||||
val amountUM: AmountState = mockk(relaxed = true)
|
||||
val transformer = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState: ConfirmUM = ConfirmUM.Empty
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isEqualTo(initialState)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fee selector not content WHEN transform THEN returns original state`() = runTest {
|
||||
// GIVEN
|
||||
val feeSelectorUM: FeeSelectorUM = FeeSelectorUM.Loading
|
||||
val amountUM: AmountState = mockk(relaxed = true)
|
||||
val transformer = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isEqualTo(initialState)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN normal fee WHEN transform THEN returns state with footer and no notifications`() = runTest {
|
||||
// GIVEN
|
||||
val feeSelectorUM = createNormalFeeSelectorUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
val transformer = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
val content = result as ConfirmUM.Content
|
||||
assertThat(content.notifications).isEmpty()
|
||||
assertThat(content.sendingFooter).isNotEqualTo(initialState.sendingFooter)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fee too high WHEN transform THEN returns state with too high notification`() = runTest {
|
||||
// GIVEN
|
||||
val feeSelectorUM = createFeeTooHighUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
val transformer = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
val content = result as ConfirmUM.Content
|
||||
assertThat(content.notifications).hasSize(1)
|
||||
assertThat(content.notifications.first()).isInstanceOf(NotificationUM.Warning.TooHigh::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fee too low WHEN transform THEN returns state with too low notification`() = runTest {
|
||||
// GIVEN
|
||||
val feeSelectorUM = createFeeTooLowUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
val transformer = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
val content = result as ConfirmUM.Content
|
||||
assertThat(content.notifications).hasSize(1)
|
||||
assertThat(content.notifications.first()).isInstanceOf(NotificationUM.Warning.FeeTooLow::class.java)
|
||||
verify { analyticsEventHandler.send(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN both fee too high and too low WHEN transform THEN returns state with both notifications`() = runTest {
|
||||
// GIVEN
|
||||
val feeSelectorUM = createFeeTooHighAndTooLowUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
val transformer = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
val initialState = createTestConfirmUM()
|
||||
|
||||
// WHEN
|
||||
val result = transformer.transform(initialState)
|
||||
|
||||
// THEN
|
||||
assertThat(result).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
val content = result as ConfirmUM.Content
|
||||
assertThat(content.notifications).hasSize(2)
|
||||
assertThat(content.notifications.any { it is NotificationUM.Warning.TooHigh }).isTrue()
|
||||
assertThat(content.notifications.any { it is NotificationUM.Warning.FeeTooLow }).isTrue()
|
||||
}
|
||||
|
||||
private fun createTestConfirmUM(): ConfirmUM.Content {
|
||||
return ConfirmUM.Content(
|
||||
isPrimaryButtonEnabled = true,
|
||||
walletName = mockk(relaxed = true),
|
||||
isSending = false,
|
||||
showTapHelp = false,
|
||||
sendingFooter = mockk(relaxed = true),
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createTestAmountUM(): AmountState.Data {
|
||||
val cryptoAmount = DomainAmount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("1.5"),
|
||||
decimals = 8,
|
||||
)
|
||||
val fiatAmount = DomainAmount(
|
||||
currencySymbol = "USD",
|
||||
value = BigDecimal("50.00"),
|
||||
decimals = 2,
|
||||
)
|
||||
|
||||
return AmountState.Data(
|
||||
isPrimaryButtonEnabled = true,
|
||||
isRedesignEnabled = false,
|
||||
title = mockk(relaxed = true),
|
||||
availableBalance = mockk(relaxed = true),
|
||||
tokenName = mockk(relaxed = true),
|
||||
tokenIconState = mockk(relaxed = true),
|
||||
segmentedButtonConfig = persistentListOf(),
|
||||
selectedButton = 0,
|
||||
isSegmentedButtonsEnabled = false,
|
||||
amountTextField = AmountFieldModel(
|
||||
value = "1.5",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
cryptoAmount = cryptoAmount,
|
||||
fiatAmount = fiatAmount,
|
||||
isFiatValue = false,
|
||||
fiatValue = "50.00",
|
||||
isFiatUnavailable = false,
|
||||
isValuePasted = false,
|
||||
onValuePastedTriggerDismiss = {},
|
||||
isError = false,
|
||||
isWarning = false,
|
||||
error = mockk(relaxed = true),
|
||||
),
|
||||
appCurrency = appCurrency,
|
||||
isEditingDisabled = false,
|
||||
reduceAmountBy = BigDecimal.ZERO,
|
||||
isIgnoreReduce = false,
|
||||
)
|
||||
}
|
||||
|
||||
private fun createNormalFeeSelectorUM(): FeeSelectorUM.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Single(fee)
|
||||
return FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
feeItems = persistentListOf(FeeItem.Market(fee)),
|
||||
selectedFeeItem = FeeItem.Market(fee),
|
||||
isFeeApproximate = false,
|
||||
feeFiatRateUM = FeeFiatRateUM(
|
||||
rate = BigDecimal("50000"),
|
||||
appCurrency = appCurrency,
|
||||
),
|
||||
displayNonceInput = false,
|
||||
nonce = BigInteger.ZERO,
|
||||
onNonceChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooHighUM(): FeeSelectorUM.Content {
|
||||
val priorityFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = minimumFee,
|
||||
priority = priorityFee,
|
||||
)
|
||||
return FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
feeItems = persistentListOf(
|
||||
FeeItem.Custom(
|
||||
fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.01"),
|
||||
decimals = 8,
|
||||
),
|
||||
),
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.01",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "SOL",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
selectedFeeItem = FeeItem.Custom(
|
||||
fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.01"),
|
||||
decimals = 8,
|
||||
),
|
||||
),
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.01",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "SOL",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
isFeeApproximate = false,
|
||||
feeFiatRateUM = FeeFiatRateUM(
|
||||
rate = BigDecimal("50000"),
|
||||
appCurrency = appCurrency,
|
||||
),
|
||||
displayNonceInput = false,
|
||||
nonce = BigInteger.ZERO,
|
||||
onNonceChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooLowUM(): FeeSelectorUM.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.0001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = fee,
|
||||
priority = fee,
|
||||
)
|
||||
return FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
feeItems = persistentListOf(
|
||||
FeeItem.Custom(
|
||||
fee = fee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.0001",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "SOL",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
selectedFeeItem = FeeItem.Custom(
|
||||
fee = fee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.0001",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "SOL",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
isFeeApproximate = false,
|
||||
feeFiatRateUM = FeeFiatRateUM(
|
||||
rate = BigDecimal("50000"),
|
||||
appCurrency = appCurrency,
|
||||
),
|
||||
displayNonceInput = false,
|
||||
nonce = BigInteger.ZERO,
|
||||
onNonceChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooHighAndTooLowUM(): FeeSelectorUM.Content {
|
||||
val priorityFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.01"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = minimumFee,
|
||||
priority = priorityFee,
|
||||
)
|
||||
return FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
feeItems = persistentListOf(
|
||||
FeeItem.Custom(
|
||||
fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.008"),
|
||||
decimals = 8,
|
||||
),
|
||||
),
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.008",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "SOL",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
selectedFeeItem = FeeItem.Custom(
|
||||
fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "SOL",
|
||||
value = BigDecimal("0.008"),
|
||||
decimals = 8,
|
||||
),
|
||||
),
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.008",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "SOL",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
isFeeApproximate = false,
|
||||
feeFiatRateUM = FeeFiatRateUM(
|
||||
rate = BigDecimal("50000"),
|
||||
appCurrency = appCurrency,
|
||||
),
|
||||
displayNonceInput = false,
|
||||
nonce = BigInteger.ZERO,
|
||||
onNonceChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun setUpLocale() {
|
||||
Locale.setDefault(Locale.US)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,847 @@
|
|||
package com.tangem.features.send.v2.send.confirm.model.transformers
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.tangem.blockchain.common.Amount
|
||||
import com.tangem.blockchain.common.transaction.Fee
|
||||
import com.tangem.blockchain.common.transaction.TransactionFee
|
||||
import com.tangem.common.ui.amountScreen.models.AmountState
|
||||
import com.tangem.common.ui.amountScreen.models.AmountFieldModel
|
||||
import com.tangem.common.ui.notifications.NotificationUM
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.features.send.v2.api.entity.FeeSelectorUM as FeeSelectorUMV2
|
||||
import com.tangem.features.send.v2.common.ui.state.ConfirmUM
|
||||
import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeUM
|
||||
import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeSelectorUM
|
||||
import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeType
|
||||
import com.tangem.features.send.v2.api.entity.CustomFeeFieldUM
|
||||
import com.tangem.features.send.v2.api.entity.FeeItem
|
||||
import com.tangem.features.send.v2.api.entity.FeeFiatRateUM
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import java.math.BigDecimal
|
||||
import java.math.BigInteger
|
||||
import java.util.Locale
|
||||
import com.tangem.domain.tokens.model.Amount as DomainAmount
|
||||
|
||||
class TransformersComparisonTest {
|
||||
|
||||
private val analyticsEventHandler: AnalyticsEventHandler = mockk(relaxed = true)
|
||||
private val cryptoCurrency: CryptoCurrency = mockk(relaxed = true)
|
||||
private val appCurrency = AppCurrency(name = "US Dollar", code = "USD", symbol = "$")
|
||||
private val analyticsCategoryName = "test_category"
|
||||
|
||||
@Test
|
||||
fun `GIVEN equivalent input data WHEN both transformers transform THEN they produce equal ConfirmUM`() = runTest {
|
||||
// GIVEN
|
||||
val initialConfirmUM = createTestConfirmUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
|
||||
val feeUM = createTestFeeUM()
|
||||
val feeSelectorUMV2 = createTestFeeSelectorUMV2()
|
||||
|
||||
// WHEN
|
||||
val transformerV1 = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val transformerV2 = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUMV2,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val resultV1 = transformerV1.transform(initialConfirmUM)
|
||||
val resultV2 = transformerV2.transform(initialConfirmUM)
|
||||
|
||||
// THEN
|
||||
assertThat(resultV1).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
assertThat(resultV2).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
|
||||
val contentV1 = resultV1 as ConfirmUM.Content
|
||||
val contentV2 = resultV2 as ConfirmUM.Content
|
||||
|
||||
assertThat(contentV1.notifications.size).isEqualTo(contentV2.notifications.size)
|
||||
assertThat(contentV1.sendingFooter).isEqualTo(contentV2.sendingFooter)
|
||||
assertThat(contentV1.isPrimaryButtonEnabled).isEqualTo(contentV2.isPrimaryButtonEnabled)
|
||||
assertThat(contentV1.isSending).isEqualTo(contentV2.isSending)
|
||||
assertThat(contentV1.showTapHelp).isEqualTo(contentV2.showTapHelp)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fee too low WHEN both transformers transform THEN they produce equal notifications`() = runTest {
|
||||
// GIVEN
|
||||
val initialConfirmUM = createTestConfirmUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
|
||||
val feeUM = createFeeTooLowUM()
|
||||
val feeSelectorUMV2 = createFeeTooLowUMV2()
|
||||
|
||||
// WHEN
|
||||
val transformerV1 = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val transformerV2 = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUMV2,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val resultV1 = transformerV1.transform(initialConfirmUM)
|
||||
val resultV2 = transformerV2.transform(initialConfirmUM)
|
||||
|
||||
// THEN
|
||||
assertThat(resultV1).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
assertThat(resultV2).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
|
||||
val contentV1 = resultV1 as ConfirmUM.Content
|
||||
val contentV2 = resultV2 as ConfirmUM.Content
|
||||
|
||||
assertThat(contentV1.notifications).hasSize(1)
|
||||
assertThat(contentV2.notifications).hasSize(1)
|
||||
assertThat(contentV1.notifications.first()).isInstanceOf(NotificationUM.Warning.FeeTooLow::class.java)
|
||||
assertThat(contentV2.notifications.first()).isInstanceOf(NotificationUM.Warning.FeeTooLow::class.java)
|
||||
assertThat(contentV1.sendingFooter).isEqualTo(contentV2.sendingFooter)
|
||||
|
||||
// Verify analytics event was sent for both transformers
|
||||
verify(exactly = 2) { analyticsEventHandler.send(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fee too high WHEN both transformers transform THEN they produce equal notifications`() = runTest {
|
||||
// GIVEN
|
||||
val initialConfirmUM = createTestConfirmUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
|
||||
val feeUM = createFeeTooHighUM()
|
||||
val feeSelectorUMV2 = createFeeTooHighUMV2()
|
||||
|
||||
// WHEN
|
||||
val transformerV1 = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val transformerV2 = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUMV2,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val resultV1 = transformerV1.transform(initialConfirmUM)
|
||||
val resultV2 = transformerV2.transform(initialConfirmUM)
|
||||
|
||||
// THEN
|
||||
assertThat(resultV1).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
assertThat(resultV2).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
|
||||
val contentV1 = resultV1 as ConfirmUM.Content
|
||||
val contentV2 = resultV2 as ConfirmUM.Content
|
||||
|
||||
assertThat(contentV1.notifications).hasSize(1)
|
||||
assertThat(contentV2.notifications).hasSize(1)
|
||||
assertThat(contentV1.notifications.first()).isInstanceOf(NotificationUM.Warning.TooHigh::class.java)
|
||||
assertThat(contentV2.notifications.first()).isInstanceOf(NotificationUM.Warning.TooHigh::class.java)
|
||||
|
||||
val tooHighV1 = contentV1.notifications.first() as NotificationUM.Warning.TooHigh
|
||||
val tooHighV2 = contentV2.notifications.first() as NotificationUM.Warning.TooHigh
|
||||
assertThat(tooHighV1.value).isEqualTo(tooHighV2.value)
|
||||
assertThat(contentV1.sendingFooter).isEqualTo(contentV2.sendingFooter)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN fee both too high and too low WHEN both transformers transform THEN they produce equal notifications`() =
|
||||
runTest {
|
||||
// GIVEN
|
||||
val initialConfirmUM = createTestConfirmUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
|
||||
val feeUM = createFeeTooHighAndTooLowUM()
|
||||
val feeSelectorUMV2 = createFeeTooHighAndTooLowUMV2()
|
||||
|
||||
// WHEN
|
||||
val transformerV1 = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val transformerV2 = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUMV2,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val resultV1 = transformerV1.transform(initialConfirmUM)
|
||||
val resultV2 = transformerV2.transform(initialConfirmUM)
|
||||
|
||||
// THEN
|
||||
assertThat(resultV1).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
assertThat(resultV2).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
|
||||
val contentV1 = resultV1 as ConfirmUM.Content
|
||||
val contentV2 = resultV2 as ConfirmUM.Content
|
||||
|
||||
assertThat(contentV1.notifications).hasSize(2)
|
||||
assertThat(contentV2.notifications).hasSize(2)
|
||||
|
||||
assertThat(contentV1.notifications.any { it is NotificationUM.Warning.FeeTooLow }).isTrue()
|
||||
assertThat(contentV1.notifications.any { it is NotificationUM.Warning.TooHigh }).isTrue()
|
||||
assertThat(contentV2.notifications.any { it is NotificationUM.Warning.FeeTooLow }).isTrue()
|
||||
assertThat(contentV2.notifications.any { it is NotificationUM.Warning.TooHigh }).isTrue()
|
||||
|
||||
assertThat(contentV1.sendingFooter).isEqualTo(contentV2.sendingFooter)
|
||||
|
||||
verify(exactly = 2) { analyticsEventHandler.send(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN normal fee WHEN both transformers transform THEN they produce equal notifications`() = runTest {
|
||||
// GIVEN
|
||||
val initialConfirmUM = createTestConfirmUM()
|
||||
val amountUM = createTestAmountUM()
|
||||
|
||||
val feeUM = createNormalFeeUM()
|
||||
val feeSelectorUMV2 = createNormalFeeSelectorUMV2()
|
||||
|
||||
// WHEN
|
||||
val transformerV1 = SendConfirmationNotificationsTransformer(
|
||||
feeUM = feeUM,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val transformerV2 = SendConfirmationNotificationsTransformerV2(
|
||||
feeSelectorUM = feeSelectorUMV2,
|
||||
amountUM = amountUM,
|
||||
analyticsEventHandler = analyticsEventHandler,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
appCurrency = appCurrency,
|
||||
analyticsCategoryName = analyticsCategoryName,
|
||||
)
|
||||
|
||||
val resultV1 = transformerV1.transform(initialConfirmUM)
|
||||
val resultV2 = transformerV2.transform(initialConfirmUM)
|
||||
|
||||
// THEN
|
||||
assertThat(resultV1).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
assertThat(resultV2).isInstanceOf(ConfirmUM.Content::class.java)
|
||||
|
||||
val contentV1 = resultV1 as ConfirmUM.Content
|
||||
val contentV2 = resultV2 as ConfirmUM.Content
|
||||
|
||||
assertThat(contentV1.notifications).isEmpty()
|
||||
assertThat(contentV2.notifications).isEmpty()
|
||||
assertThat(contentV1.sendingFooter).isEqualTo(contentV2.sendingFooter)
|
||||
}
|
||||
|
||||
private fun createTestConfirmUM(): ConfirmUM.Content {
|
||||
return ConfirmUM.Content(
|
||||
isPrimaryButtonEnabled = true,
|
||||
walletName = mockk(relaxed = true),
|
||||
isSending = false,
|
||||
showTapHelp = false,
|
||||
sendingFooter = mockk(relaxed = true),
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createTestAmountUM(): AmountState.Data {
|
||||
val cryptoAmount = DomainAmount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("1.5"),
|
||||
decimals = 8,
|
||||
)
|
||||
val fiatAmount = DomainAmount(
|
||||
currencySymbol = "USD",
|
||||
value = BigDecimal("50.00"),
|
||||
decimals = 2,
|
||||
)
|
||||
|
||||
return AmountState.Data(
|
||||
isPrimaryButtonEnabled = true,
|
||||
isRedesignEnabled = false,
|
||||
title = mockk(relaxed = true),
|
||||
availableBalance = mockk(relaxed = true),
|
||||
tokenName = mockk(relaxed = true),
|
||||
tokenIconState = mockk(relaxed = true),
|
||||
segmentedButtonConfig = persistentListOf(),
|
||||
selectedButton = 0,
|
||||
isSegmentedButtonsEnabled = false,
|
||||
amountTextField = AmountFieldModel(
|
||||
value = "1.5",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
cryptoAmount = cryptoAmount,
|
||||
fiatAmount = fiatAmount,
|
||||
isFiatValue = false,
|
||||
fiatValue = "50.00",
|
||||
isFiatUnavailable = false,
|
||||
isValuePasted = false,
|
||||
onValuePastedTriggerDismiss = {},
|
||||
isError = false,
|
||||
isWarning = false,
|
||||
error = mockk(relaxed = true),
|
||||
),
|
||||
appCurrency = appCurrency,
|
||||
isEditingDisabled = false,
|
||||
reduceAmountBy = BigDecimal.ZERO,
|
||||
isIgnoreReduce = false,
|
||||
)
|
||||
}
|
||||
|
||||
private fun createTestFeeUM(): FeeUM.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Single(fee)
|
||||
return FeeUM.Content(
|
||||
feeSelectorUM = FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
selectedType = FeeType.Market,
|
||||
selectedFee = fee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.001",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
nonce = BigInteger.ZERO,
|
||||
),
|
||||
rate = BigDecimal("50000"),
|
||||
isFeeConvertibleToFiat = true,
|
||||
isFeeApproximate = false,
|
||||
isTronToken = false,
|
||||
isEditingDisabled = false,
|
||||
isPrimaryButtonEnabled = true,
|
||||
appCurrency = AppCurrency.Default,
|
||||
isCustomSelected = false,
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createTestFeeSelectorUMV2(): FeeSelectorUMV2.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Single(fee)
|
||||
return FeeSelectorUMV2.Content(
|
||||
fees = transactionFee,
|
||||
feeItems = persistentListOf(
|
||||
FeeItem.Market(fee),
|
||||
),
|
||||
selectedFeeItem = FeeItem.Market(fee),
|
||||
isFeeApproximate = false,
|
||||
feeFiatRateUM = FeeFiatRateUM(
|
||||
rate = BigDecimal("50000"),
|
||||
appCurrency = appCurrency,
|
||||
),
|
||||
displayNonceInput = false,
|
||||
nonce = BigInteger.ZERO,
|
||||
onNonceChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooLowUM(): FeeUM.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.0001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = fee,
|
||||
priority = fee,
|
||||
)
|
||||
return FeeUM.Content(
|
||||
feeSelectorUM = FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
selectedType = FeeType.Custom,
|
||||
selectedFee = fee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.0001",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
nonce = BigInteger.ZERO,
|
||||
),
|
||||
rate = BigDecimal("50000"),
|
||||
isFeeConvertibleToFiat = true,
|
||||
isFeeApproximate = false,
|
||||
isTronToken = false,
|
||||
isEditingDisabled = false,
|
||||
isPrimaryButtonEnabled = true,
|
||||
appCurrency = AppCurrency.Default,
|
||||
isCustomSelected = true,
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooLowUMV2(): FeeSelectorUMV2.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.0001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = fee,
|
||||
priority = fee,
|
||||
)
|
||||
return FeeSelectorUMV2.Content(
|
||||
fees = transactionFee,
|
||||
feeItems = persistentListOf(
|
||||
FeeItem.Custom(
|
||||
fee = fee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.0001",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
selectedFeeItem = FeeItem.Custom(
|
||||
fee = fee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.0001",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
isFeeApproximate = false,
|
||||
feeFiatRateUM = FeeFiatRateUM(
|
||||
rate = BigDecimal("50000"),
|
||||
appCurrency = appCurrency,
|
||||
),
|
||||
displayNonceInput = false,
|
||||
nonce = BigInteger.ZERO,
|
||||
onNonceChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooHighUM(): FeeUM.Content {
|
||||
val priorityFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val customFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.01"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = minimumFee,
|
||||
priority = priorityFee,
|
||||
)
|
||||
return FeeUM.Content(
|
||||
feeSelectorUM = FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
selectedType = FeeType.Custom,
|
||||
selectedFee = customFee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.01",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
nonce = BigInteger.ZERO,
|
||||
),
|
||||
rate = BigDecimal("50000"),
|
||||
isFeeConvertibleToFiat = true,
|
||||
isFeeApproximate = false,
|
||||
isTronToken = false,
|
||||
isEditingDisabled = false,
|
||||
isPrimaryButtonEnabled = true,
|
||||
appCurrency = AppCurrency.Default,
|
||||
isCustomSelected = true,
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooHighUMV2(): FeeSelectorUMV2.Content {
|
||||
val priorityFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val customFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.01"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = minimumFee,
|
||||
priority = priorityFee,
|
||||
)
|
||||
return FeeSelectorUMV2.Content(
|
||||
fees = transactionFee,
|
||||
feeItems = persistentListOf(
|
||||
FeeItem.Custom(
|
||||
fee = customFee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.01",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
selectedFeeItem = FeeItem.Custom(
|
||||
fee = customFee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.01",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
isFeeApproximate = false,
|
||||
feeFiatRateUM = FeeFiatRateUM(
|
||||
rate = BigDecimal("50000"),
|
||||
appCurrency = appCurrency,
|
||||
),
|
||||
displayNonceInput = false,
|
||||
nonce = BigInteger.ZERO,
|
||||
onNonceChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooHighAndTooLowUM(): FeeUM.Content {
|
||||
val priorityFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.01"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val customFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.008"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = minimumFee,
|
||||
priority = priorityFee,
|
||||
)
|
||||
return FeeUM.Content(
|
||||
feeSelectorUM = FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
selectedType = FeeType.Custom,
|
||||
selectedFee = customFee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.008",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
nonce = BigInteger.ZERO,
|
||||
),
|
||||
rate = BigDecimal("50000"),
|
||||
isFeeConvertibleToFiat = true,
|
||||
isFeeApproximate = false,
|
||||
isTronToken = false,
|
||||
isEditingDisabled = false,
|
||||
isPrimaryButtonEnabled = true,
|
||||
appCurrency = AppCurrency.Default,
|
||||
isCustomSelected = true,
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFeeTooHighAndTooLowUMV2(): FeeSelectorUMV2.Content {
|
||||
val priorityFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val minimumFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.01"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val customFee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.008"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Choosable(
|
||||
minimum = minimumFee,
|
||||
normal = minimumFee,
|
||||
priority = priorityFee,
|
||||
)
|
||||
return FeeSelectorUMV2.Content(
|
||||
fees = transactionFee,
|
||||
feeItems = persistentListOf(
|
||||
FeeItem.Custom(
|
||||
fee = customFee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.008",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
selectedFeeItem = FeeItem.Custom(
|
||||
fee = customFee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.008",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
),
|
||||
isFeeApproximate = false,
|
||||
feeFiatRateUM = FeeFiatRateUM(
|
||||
rate = BigDecimal("50000"),
|
||||
appCurrency = appCurrency,
|
||||
),
|
||||
displayNonceInput = false,
|
||||
nonce = BigInteger.ZERO,
|
||||
onNonceChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
private fun createNormalFeeUM(): FeeUM.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Single(fee)
|
||||
return FeeUM.Content(
|
||||
feeSelectorUM = FeeSelectorUM.Content(
|
||||
fees = transactionFee,
|
||||
selectedType = FeeType.Market,
|
||||
selectedFee = fee,
|
||||
customValues = persistentListOf(
|
||||
CustomFeeFieldUM(
|
||||
value = "0.001",
|
||||
onValueChange = {},
|
||||
keyboardOptions = mockk(relaxed = true),
|
||||
keyboardActions = mockk(relaxed = true),
|
||||
symbol = "TST",
|
||||
decimals = 8,
|
||||
title = mockk(relaxed = true),
|
||||
footer = mockk(relaxed = true),
|
||||
),
|
||||
),
|
||||
nonce = BigInteger.ZERO,
|
||||
),
|
||||
rate = BigDecimal("50000"),
|
||||
isFeeConvertibleToFiat = true,
|
||||
isFeeApproximate = false,
|
||||
isTronToken = false,
|
||||
isEditingDisabled = false,
|
||||
isPrimaryButtonEnabled = true,
|
||||
appCurrency = AppCurrency.Default,
|
||||
isCustomSelected = false,
|
||||
notifications = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createNormalFeeSelectorUMV2(): FeeSelectorUMV2.Content {
|
||||
val fee = Fee.Common(
|
||||
amount = Amount(
|
||||
currencySymbol = "TST",
|
||||
value = BigDecimal("0.001"),
|
||||
decimals = 8,
|
||||
),
|
||||
)
|
||||
val transactionFee = TransactionFee.Single(fee)
|
||||
return FeeSelectorUMV2.Content(
|
||||
fees = transactionFee,
|
||||
feeItems = persistentListOf(
|
||||
FeeItem.Market(fee),
|
||||
),
|
||||
selectedFeeItem = FeeItem.Market(fee),
|
||||
isFeeApproximate = false,
|
||||
feeFiatRateUM = FeeFiatRateUM(
|
||||
rate = BigDecimal("50000"),
|
||||
appCurrency = appCurrency,
|
||||
),
|
||||
displayNonceInput = false,
|
||||
nonce = BigInteger.ZERO,
|
||||
onNonceChange = {},
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun setUpLocale() {
|
||||
Locale.setDefault(Locale.US)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue