diff --git a/core/utils/src/main/java/com/tangem/utils/Extensions.kt b/core/utils/src/main/java/com/tangem/utils/Extensions.kt index de72e53d54..efeb15cdb9 100644 --- a/core/utils/src/main/java/com/tangem/utils/Extensions.kt +++ b/core/utils/src/main/java/com/tangem/utils/Extensions.kt @@ -1,9 +1,15 @@ package com.tangem.utils +import java.math.BigDecimal + inline fun > safeValueOf(type: String, default: T): T { return try { java.lang.Enum.valueOf(T::class.java, type) } catch (e: IllegalArgumentException) { default } +} + +fun BigDecimal?.isNullOrZero(): Boolean { + return this == null || this.compareTo(BigDecimal.ZERO) == 0 } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt index cd63eb702a..c9452c4411 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt @@ -7,6 +7,7 @@ import com.tangem.domain.tokens.model.TokenActionsState import com.tangem.domain.tokens.repository.MarketCryptoCurrencyRepository import com.tangem.domain.wallets.models.UserWalletId import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import com.tangem.utils.isNullOrZero import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOn @@ -70,7 +71,7 @@ class GetCryptoCurrencyActionsUseCase( } // send - if (cryptoCurrencyStatus.value.amount?.signum() == 0) { + if (cryptoCurrencyStatus.value.amount.isNullOrZero()) { disabledList.add(TokenActionsState.ActionState.Send(false)) } else { activeList.add(TokenActionsState.ActionState.Send(true)) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt index 7f86a56e66..9c671a6549 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt @@ -1,6 +1,5 @@ package com.tangem.feature.wallet.presentation.wallet.state.factory -import com.tangem.common.extensions.isZero import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resourceReference import com.tangem.domain.tokens.model.CryptoCurrencyStatus @@ -9,6 +8,7 @@ import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.state.TokenItemState import com.tangem.feature.wallet.presentation.wallet.state.TokenActionButtonConfig import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents +import com.tangem.utils.isNullOrZero import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList @@ -34,7 +34,7 @@ internal class TokenActionsProvider(private val clickIntents: WalletClickIntents cryptoCurrencyStatus: CryptoCurrencyStatus, ): TokenActionButtonConfig? { if (actionsState is TokenActionsState.ActionState.Send && - cryptoCurrencyStatus.value.amount?.isZero() == true + cryptoCurrencyStatus.value.amount.isNullOrZero() ) { return null }