From 7cda9d6726e1f4b23b14f1de5c1d4a8ba3871138 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 4 May 2026 02:57:05 -0700 Subject: [PATCH] Updated on 2026-08-14 --- .../setup/TangemPayCardLimitSetupModel.kt | 8 ++- .../setup/TangemPayCardLimitSetupModelTest.kt | 63 +++++++++++++------ 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/features/tangempay/details/impl/src/main/kotlin/com/tangem/features/tangempay/limit/setup/TangemPayCardLimitSetupModel.kt b/features/tangempay/details/impl/src/main/kotlin/com/tangem/features/tangempay/limit/setup/TangemPayCardLimitSetupModel.kt index 7672c8911c..d832e12eea 100644 --- a/features/tangempay/details/impl/src/main/kotlin/com/tangem/features/tangempay/limit/setup/TangemPayCardLimitSetupModel.kt +++ b/features/tangempay/details/impl/src/main/kotlin/com/tangem/features/tangempay/limit/setup/TangemPayCardLimitSetupModel.kt @@ -44,6 +44,7 @@ internal class TangemPayCardLimitSetupModel @Inject constructor( ) : Model() { private val params: TangemPayDetailsContainerComponent.Params = paramsContainer.require() + private var currentAdminLimit: BigDecimal? = null val uiState: StateFlow field = MutableStateFlow( @@ -83,7 +84,7 @@ internal class TangemPayCardLimitSetupModel @Inject constructor( ?.takeIf { it.period == TangemPayCardLimitPeriod.DAY } ?.amount - val adminLimit = card.limit?.adminCardLimit + currentAdminLimit = card.limit?.adminCardLimit ?.takeIf { it.period == TangemPayCardLimitPeriod.DAY } ?.amount @@ -101,7 +102,7 @@ internal class TangemPayCardLimitSetupModel @Inject constructor( decimals = currency.defaultFractionDigits, onValueChange = ::onAmountChange, ), - subtitle = buildSubtitle(adminLimit, currency), + subtitle = buildSubtitle(currentAdminLimit, currency), currencyCode = currency.symbol, presets = buildPresets(currency), isSubmitButtonEnabled = isValid(amount), @@ -153,7 +154,8 @@ internal class TangemPayCardLimitSetupModel @Inject constructor( private fun isValid(value: String): Boolean { val amount = value.toBigDecimalOrNull() ?: return false - return amount >= MIN_LIMIT + val isLessThanMax = currentAdminLimit?.let { amount <= it } != false + return amount >= MIN_LIMIT && isLessThanMax } private fun buildSubtitle(maxLimit: BigDecimal?, currency: Currency): TextReference { diff --git a/features/tangempay/details/impl/src/test/kotlin/com/tangem/features/tangempay/limit/setup/TangemPayCardLimitSetupModelTest.kt b/features/tangempay/details/impl/src/test/kotlin/com/tangem/features/tangempay/limit/setup/TangemPayCardLimitSetupModelTest.kt index 3213e42482..b99ecc5bb7 100644 --- a/features/tangempay/details/impl/src/test/kotlin/com/tangem/features/tangempay/limit/setup/TangemPayCardLimitSetupModelTest.kt +++ b/features/tangempay/details/impl/src/test/kotlin/com/tangem/features/tangempay/limit/setup/TangemPayCardLimitSetupModelTest.kt @@ -8,6 +8,9 @@ import com.tangem.domain.models.StatusSource import com.tangem.domain.models.account.AccountStatus import com.tangem.domain.models.account.PaymentAccountStatusValue import com.tangem.domain.models.pay.TangemPayCard +import com.tangem.domain.models.pay.TangemPayCardLimit +import com.tangem.domain.models.pay.TangemPayCardLimitData +import com.tangem.domain.models.pay.TangemPayCardLimitPeriod import com.tangem.domain.models.wallet.UserWalletId import com.tangem.domain.pay.TangemPayDetailsConfig import com.tangem.domain.pay.flow.PaymentAccountStatusSupplier @@ -24,6 +27,7 @@ import org.junit.jupiter.api.TestInstance import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource +import java.math.BigDecimal @TestInstance(TestInstance.Lifecycle.PER_CLASS) internal class TangemPayCardLimitSetupModelTest { @@ -50,27 +54,35 @@ internal class TangemPayCardLimitSetupModelTest { ), ) - private val testCard = TangemPayCard( - id = cardId, - hasPinCode = false, - displayName = null, - limit = null, - isFrozen = false, - lastDigits = "1234", - ) + private fun createModel( + adminLimit: BigDecimal? = BigDecimal("1000"), + ): TangemPayCardLimitSetupModel { + val cardWithLimit = TangemPayCard( + id = cardId, + hasPinCode = false, + displayName = null, + isFrozen = false, + lastDigits = "1234", + limit = TangemPayCardLimitData( + actualCardLimit = null, + adminCardLimit = adminLimit?.let { + TangemPayCardLimit( + amount = adminLimit, + period = TangemPayCardLimitPeriod.DAY, + ) + } + ), + ) + val statusWithLimit: PaymentAccountStatusValue.Loaded = mockk(relaxed = true) { + every { source } returns StatusSource.ACTUAL + every { cards } returns listOf(cardWithLimit) + every { currencyCode } returns "USD" + } + val paymentStatusWithLimit: AccountStatus.Payment = mockk(relaxed = true) { + every { value } returns statusWithLimit + } + every { paymentAccountStatusSupplier.invoke(userWalletId) } returns flowOf(paymentStatusWithLimit) - private val loadedStatus: PaymentAccountStatusValue.Loaded = mockk(relaxed = true) { - every { source } returns StatusSource.ACTUAL - every { cards } returns listOf(testCard) - every { currencyCode } returns "USD" - } - - private val paymentStatus: AccountStatus.Payment = mockk(relaxed = true) { - every { value } returns loadedStatus - } - - private fun createModel(): TangemPayCardLimitSetupModel { - every { paymentAccountStatusSupplier.invoke(userWalletId) } returns flowOf(paymentStatus) return TangemPayCardLimitSetupModel( paramsContainer = MutableParamsContainer(params), dispatchers = TestingCoroutineDispatcherProvider(), @@ -95,6 +107,16 @@ internal class TangemPayCardLimitSetupModelTest { model.onDestroy() } + @Test + fun `GIVEN max limit null WHEN changed THEN submit button is enabled`() { + val model = createModel(adminLimit = null) + + model.uiState.value.amountFieldModel.onValueChange("100") + + assertThat(model.uiState.value.isSubmitButtonEnabled).isTrue() + model.onDestroy() + } + @Nested @TestInstance(TestInstance.Lifecycle.PER_CLASS) inner class Presets { @@ -128,5 +150,6 @@ internal class TangemPayCardLimitSetupModelTest { Arguments.of("-1", false), Arguments.of("", false), Arguments.of("abc", false), + Arguments.of("1001", false), ) } \ No newline at end of file