Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-10 15:40:23 +03:00
parent 36fabffe3a
commit c8da4e40e1
3 changed files with 10 additions and 3 deletions

View file

@ -1,9 +1,15 @@
package com.tangem.utils
import java.math.BigDecimal
inline fun <reified T : Enum<T>> 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
}

View file

@ -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))

View file

@ -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
}