Updated on 2026-08-14

This commit is contained in:
Tangem 2023-05-11 13:26:54 +04:00
parent a4462d226c
commit 35566a092c
4 changed files with 19 additions and 16 deletions

View file

@ -1,6 +1,7 @@
package com.tangem.tap.features.wallet.redux
import android.graphics.Bitmap
import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.WalletManager
import com.tangem.domain.common.util.cardTypesResolver
@ -16,6 +17,7 @@ import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsState
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.store
import org.rekotlin.StateType
import java.math.BigDecimal
import kotlin.properties.ReadOnlyProperty
data class WalletState(
@ -103,6 +105,9 @@ data class WalletState(
it.derivationPath?.rawPath == currency.derivationPath
}
}
fun getBlockchainAmount(currency: Currency): BigDecimal =
getWalletManager(currency)?.wallet?.amounts?.get(AmountType.Coin)?.value ?: BigDecimal.ZERO
}
enum class ProgressState : WidgetState { Loading, Refreshing, Done, Error }
@ -114,7 +119,6 @@ enum class ErrorType {
sealed class WalletMainButton(enabled: Boolean) : Button(enabled) {
class SendButton(enabled: Boolean) : WalletMainButton(enabled)
class CreateWalletButton(enabled: Boolean) : WalletMainButton(enabled)
}
data class Artwork(

View file

@ -55,6 +55,7 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
import java.math.BigDecimal
import javax.inject.Inject
/**
@ -128,7 +129,8 @@ class WalletDetailsFragment :
(WalletState::selectedWalletData or WalletState::isExchangeServiceFeatureOn) { state ->
val selectedWallet = state.selectedWalletData
if (selectedWallet != null) {
setupButtonsRow(selectedWallet, state.isExchangeServiceFeatureOn)
val blockchainAmount: BigDecimal = state.getBlockchainAmount(selectedWallet.currency)
setupButtonsRow(selectedWallet, state.isExchangeServiceFeatureOn, blockchainAmount)
}
}
(WalletState::state or WalletState::error) { state ->
@ -281,7 +283,11 @@ class WalletDetailsFragment :
}
}
private fun setupButtonsRow(selectedWallet: WalletDataModel, isExchangeServiceFeatureOn: Boolean) {
private fun setupButtonsRow(
selectedWallet: WalletDataModel,
isExchangeServiceFeatureOn: Boolean,
blockchainAmount: BigDecimal,
) {
val exchangeManager = store.state.globalState.exchangeManager
binding.rowButtons.apply {
onBuyClick = { store.dispatch(WalletAction.TradeCryptoAction.Buy()) }
@ -310,7 +316,7 @@ class WalletDetailsFragment :
binding.rowButtons.updateButtonsVisibility(
actions = actions,
exchangeServiceFeatureOn = isExchangeServiceFeatureOn,
sendAllowed = selectedWallet.mainButton.enabled,
sendAllowed = selectedWallet.mainButton(blockchainAmount).enabled,
)
}

View file

@ -18,10 +18,9 @@ import com.tangem.tap.features.wallet.redux.utils.UNKNOWN_AMOUNT_SIGN
import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager
import java.math.BigDecimal
internal val WalletDataModel.mainButton: WalletMainButton
get() = WalletMainButton.SendButton(
enabled = !status.amount.isZero() && status.pendingTransactions.isEmpty(),
)
internal fun WalletDataModel.mainButton(blockchainAmount: BigDecimal): WalletMainButton = WalletMainButton.SendButton(
enabled = !isEmptyAmount && status.pendingTransactions.isEmpty() && !blockchainAmount.isZero(),
)
internal fun WalletDataModel.getFormattedAmount(): String {
return status.amount.toFormattedCurrencyString(

View file

@ -12,7 +12,6 @@ import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.models.PendingTransaction
import com.tangem.tap.features.wallet.models.PendingTransactionType
import com.tangem.tap.features.wallet.redux.WalletAction
import com.tangem.tap.features.wallet.redux.WalletMainButton
import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.features.wallet.ui.BalanceWidget
import com.tangem.tap.features.wallet.ui.MultipleAddressUiHelper
@ -175,15 +174,10 @@ class SingleWalletView : WalletView() {
binding?.rowButtons?.updateButtonsVisibility(
actions = actions,
exchangeServiceFeatureOn = isExchangeServiceFeatureEnabled,
sendAllowed = walletData.mainButton.enabled,
sendAllowed = walletData.mainButton(walletData.status.amount).enabled,
)
rowButtons.onSendClick = {
when (walletData.mainButton) {
is WalletMainButton.SendButton -> store.dispatch(WalletAction.Send())
is WalletMainButton.CreateWalletButton -> store.dispatch(WalletAction.CreateWallet)
}
}
rowButtons.onSendClick = { store.dispatch(WalletAction.Send()) }
}
private fun setupAddressCard(state: WalletState, binding: FragmentWalletBinding) = with(binding.lAddress) {