From 20755c42bbbc9990d5af92db755f2bb35fededde Mon Sep 17 00:00:00 2001 From: Tangem Date: Sat, 28 May 2022 16:12:25 +0300 Subject: [PATCH 1/6] Updated on 2026-08-14 --- .../tangem/tap/domain/extensions/Amount.kt | 11 ----- .../features/details/redux/DetailsReducer.kt | 7 +--- .../wallet/models/PendingTransaction.kt | 42 ++++++++++++++----- .../tap/features/wallet/redux/WalletState.kt | 36 +++++----------- .../redux/middlewares/WalletMiddleware.kt | 20 +++------ .../redux/reducers/MultiWalletReducer.kt | 5 +-- .../redux/reducers/OnWalletLoadedReducer.kt | 5 +-- 7 files changed, 52 insertions(+), 74 deletions(-) delete mode 100644 app/src/main/java/com/tangem/tap/domain/extensions/Amount.kt diff --git a/app/src/main/java/com/tangem/tap/domain/extensions/Amount.kt b/app/src/main/java/com/tangem/tap/domain/extensions/Amount.kt deleted file mode 100644 index 08703ba05c..0000000000 --- a/app/src/main/java/com/tangem/tap/domain/extensions/Amount.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.tangem.tap.domain.extensions - -import com.tangem.blockchain.common.Amount -import com.tangem.blockchain.common.AmountType -import com.tangem.blockchain.extensions.isAboveZero - -fun Map.toSendableAmounts(): List { - return this.toList().unzip().second - .filter { it.type != AmountType.Reserve } - .filter { it.isAboveZero() } -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt index 5b6eaa198f..45910f64c4 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt @@ -7,8 +7,7 @@ import com.tangem.domain.common.isTangemTwin import com.tangem.tap.common.redux.AppState import com.tangem.tap.domain.extensions.isWalletDataSupported import com.tangem.tap.domain.extensions.signedHashesCount -import com.tangem.tap.domain.extensions.toSendableAmounts -import com.tangem.tap.features.wallet.models.hasPendingTransactions +import com.tangem.tap.features.wallet.models.hasSendableAmountsOrPendingTransactions import org.rekotlin.Action import java.util.* @@ -62,9 +61,7 @@ private fun handleEraseWallet( (card?.isWalletDataSupported == true && (!state.scanResponse.isTangemNote() && !state.scanResponse.supportsBackup())) - val notEmpty = state.wallets.any { - it.hasPendingTransactions() || it.amounts.toSendableAmounts().isNotEmpty() - } + val notEmpty = state.wallets.any { it.hasSendableAmountsOrPendingTransactions() } val eraseWalletState = when { notAllowedByCard -> EraseWalletState.NotAllowedByCard notEmpty -> EraseWalletState.NotEmpty diff --git a/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt index 722b2c7d03..f2ded85944 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt @@ -1,11 +1,8 @@ package com.tangem.tap.features.wallet.models -import com.tangem.blockchain.common.Token -import com.tangem.blockchain.common.TransactionData -import com.tangem.blockchain.common.TransactionStatus -import com.tangem.blockchain.common.Wallet +import com.tangem.blockchain.common.* +import com.tangem.blockchain.extensions.isAboveZero import com.tangem.tap.common.extensions.toFormattedString -import com.tangem.tap.domain.extensions.toSendableAmounts import java.math.BigDecimal data class PendingTransaction( @@ -60,22 +57,45 @@ fun TransactionData.toPendingTransactionForToken(token: Token, walletAddress: St return this.toPendingTransaction(walletAddress) } -fun List.toPendingTransactionsForToken(token: Token, walletAddress: String): List { - return this.mapNotNull { it.toPendingTransactionForToken(token, walletAddress) } -} - fun Wallet.getPendingTransactions(type: PendingTransactionType? = null): List { val txs = recentTransactions.toPendingTransactions(address) - return when(type) { + return when (type) { null -> txs else -> txs.filter { it.type == type } } } +fun Wallet.getPendingTransactions(token: Token): List { + return recentTransactions.mapNotNull { it.toPendingTransactionForToken(token, address) } +} + fun Wallet.hasPendingTransactions(): Boolean { return getPendingTransactions().isNotEmpty() } +fun Wallet.hasPendingTransactions(token: Token): Boolean { + return getPendingTransactions(token).isNotEmpty() +} + +fun Wallet.getSendableAmounts(): List { + return amounts.values + .filter { it.type != AmountType.Reserve } + .filter { it.isAboveZero() } +} + +fun Wallet.hasSendableAmounts(): Boolean { + return getSendableAmounts().isNotEmpty() +} + fun Wallet.hasSendableAmountsOrPendingTransactions(): Boolean { - return hasPendingTransactions() || amounts.toSendableAmounts().isNotEmpty() + return hasPendingTransactions() || hasSendableAmounts() +} + +fun Wallet.isSendableAmount(type: AmountType): Boolean { + return amounts[type]?.isAboveZero() == true + +} + +fun Wallet.isSendableAmount(token: Token): Boolean { + return isSendableAmount(AmountType.Token(token)) } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt index c815b4b404..9d0e40811a 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt @@ -1,15 +1,8 @@ package com.tangem.tap.features.wallet.redux import android.graphics.Bitmap -import com.tangem.blockchain.common.Amount -import com.tangem.blockchain.common.AmountType -import com.tangem.blockchain.common.Blockchain -import com.tangem.blockchain.common.DerivationStyle -import com.tangem.blockchain.common.Token -import com.tangem.blockchain.common.Wallet -import com.tangem.blockchain.common.WalletManager +import com.tangem.blockchain.common.* import com.tangem.blockchain.common.address.AddressType -import com.tangem.blockchain.extensions.isAboveZero import com.tangem.common.extensions.isZero import com.tangem.domain.common.extensions.canHandleToken import com.tangem.domain.common.extensions.toCoinId @@ -22,22 +15,16 @@ import com.tangem.tap.common.toggleWidget.WidgetState import com.tangem.tap.domain.configurable.warningMessage.WarningMessage import com.tangem.tap.domain.extensions.buyIsAllowed import com.tangem.tap.domain.extensions.sellIsAllowed -import com.tangem.tap.domain.extensions.toSendableAmounts import com.tangem.tap.domain.tokens.BlockchainNetwork import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsState import com.tangem.tap.features.tokens.redux.TokenWithBlockchain -import com.tangem.tap.features.wallet.models.PendingTransaction -import com.tangem.tap.features.wallet.models.TotalBalance -import com.tangem.tap.features.wallet.models.WalletRent -import com.tangem.tap.features.wallet.models.WalletWarning -import com.tangem.tap.features.wallet.models.toPendingTransactions -import com.tangem.tap.features.wallet.models.toPendingTransactionsForToken +import com.tangem.tap.features.wallet.models.* import com.tangem.tap.features.wallet.ui.BalanceStatus import com.tangem.tap.features.wallet.ui.BalanceWidgetData import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager import com.tangem.tap.store -import java.math.BigDecimal import org.rekotlin.StateType +import java.math.BigDecimal import kotlin.properties.ReadOnlyProperty data class WalletState( @@ -151,16 +138,13 @@ data class WalletState( val wallet = walletManager.wallet - if (walletData.currency is Currency.Blockchain) { - return wallet.recentTransactions.toPendingTransactions(wallet.address).isEmpty() && - wallet.amounts.toSendableAmounts().isEmpty() - } else if (walletData.currency is Currency.Token) ( - return wallet.recentTransactions.toPendingTransactionsForToken( - walletData.currency.token, wallet.address - ).isEmpty() - && wallet.amounts[AmountType.Token(token = walletData.currency.token)] - ?.isAboveZero() != true - ) + return when (walletData.currency) { + is Currency.Blockchain -> !wallet.hasPendingTransactions() && !wallet.hasSendableAmounts() + is Currency.Token -> { + val token = walletData.currency.token + !wallet.hasPendingTransactions(token) && !wallet.isSendableAmount(token) + } + } } return false } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt index e2d7c6d4b5..6f0cf6b5cc 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt @@ -15,19 +15,12 @@ import com.tangem.domain.common.extensions.withMainContext import com.tangem.operations.attestation.Attestation import com.tangem.operations.attestation.OnlineCardVerifier import com.tangem.tap.common.analytics.Analytics -import com.tangem.tap.common.extensions.copyToClipboard -import com.tangem.tap.common.extensions.dispatchDebugErrorNotification -import com.tangem.tap.common.extensions.dispatchDialogShow -import com.tangem.tap.common.extensions.dispatchOnMain -import com.tangem.tap.common.extensions.onCardScanned -import com.tangem.tap.common.extensions.shareText -import com.tangem.tap.common.extensions.stripZeroPlainString +import com.tangem.tap.common.extensions.* import com.tangem.tap.common.redux.AppDialog import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.common.redux.navigation.AppScreen import com.tangem.tap.common.redux.navigation.NavigationAction -import com.tangem.tap.domain.extensions.toSendableAmounts import com.tangem.tap.domain.failedRates import com.tangem.tap.domain.loadedRates import com.tangem.tap.features.demo.DemoHelper @@ -35,17 +28,13 @@ import com.tangem.tap.features.home.redux.HomeAction import com.tangem.tap.features.send.redux.PrepareSendScreen import com.tangem.tap.features.wallet.models.PendingTransactionType import com.tangem.tap.features.wallet.models.getPendingTransactions -import com.tangem.tap.features.wallet.redux.Currency -import com.tangem.tap.features.wallet.redux.WalletAction -import com.tangem.tap.features.wallet.redux.WalletData -import com.tangem.tap.features.wallet.redux.WalletState -import com.tangem.tap.features.wallet.redux.WalletStore +import com.tangem.tap.features.wallet.models.getSendableAmounts +import com.tangem.tap.features.wallet.redux.* import com.tangem.tap.network.NetworkStateChanged import com.tangem.tap.preferencesStorage import com.tangem.tap.scope import com.tangem.tap.store import com.tangem.tap.tangemSdkManager -import java.math.BigDecimal import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.launch @@ -53,6 +42,7 @@ import org.rekotlin.Action import org.rekotlin.DispatchFunction import org.rekotlin.Middleware import timber.log.Timber +import java.math.BigDecimal class WalletMiddleware { private val tradeCryptoMiddleware = TradeCryptoMiddleware() @@ -266,7 +256,7 @@ class WalletMiddleware { PrepareSendScreen(amount, selectedWalletData?.fiatRate, walletStore?.walletManager) } } else { - val amounts = walletStore?.walletManager?.wallet?.amounts?.toSendableAmounts() + val amounts = walletStore?.walletManager?.wallet?.getSendableAmounts() if (currency != null && state.isMultiwalletAllowed) { when (currency) { is Currency.Blockchain -> { diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt index a7437c94eb..643fbe7f71 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt @@ -107,8 +107,7 @@ class MultiWalletReducer { } val pendingTransactions = wallet.recentTransactions.toPendingTransactions(wallet.address) - val sendButtonEnabled = - action.amount.value?.isZero() == false && pendingTransactions.isEmpty() + val tokenSendButton = action.amount.value?.isZero() == false && pendingTransactions.isEmpty() val tokenPendingTransactions = pendingTransactions .filter { it.currency == action.amount.currencySymbol } val tokenBalanceStatus = when { @@ -131,7 +130,7 @@ class MultiWalletReducer { blockchainAmount = wallet.amounts[AmountType.Coin]?.value ?: BigDecimal.ZERO ), pendingTransactions = pendingTransactions.removeUnknownTransactions(), - mainButton = WalletMainButton.SendButton(sendButtonEnabled), + mainButton = WalletMainButton.SendButton(tokenSendButton), currency = Currency.Token( token = action.token, blockchain = action.blockchain.blockchain, diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt index ce9b5cf80a..2d3c053dab 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt @@ -9,6 +9,7 @@ import com.tangem.tap.common.extensions.toFormattedCurrencyString import com.tangem.tap.common.extensions.toFormattedFiatValue import com.tangem.tap.domain.getFirstToken import com.tangem.tap.domain.tokens.BlockchainNetwork +import com.tangem.tap.features.wallet.models.getPendingTransactions import com.tangem.tap.features.wallet.models.removeUnknownTransactions import com.tangem.tap.features.wallet.models.toPendingTransactions import com.tangem.tap.features.wallet.redux.* @@ -44,9 +45,7 @@ class OnWalletLoadedReducer { wallet.blockchain.currency ) - val pendingTransactions = wallet.recentTransactions - .toPendingTransactions(wallet.address) - + val pendingTransactions = wallet.getPendingTransactions() val coinSendButton = coinAmountValue?.isZero() == false && pendingTransactions.isEmpty() val balanceStatus = if (pendingTransactions.isNotEmpty()) { BalanceStatus.TransactionInProgress From 162b2b9791988f7e2f336dee8db5c2b9e8cd56a3 Mon Sep 17 00:00:00 2001 From: Tangem Date: Sat, 28 May 2022 18:12:59 +0300 Subject: [PATCH 2/6] Updated on 2026-08-14 --- .../wallet/models/PendingTransaction.kt | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt index f2ded85944..62f4f714b1 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt @@ -6,12 +6,21 @@ import com.tangem.tap.common.extensions.toFormattedString import java.math.BigDecimal data class PendingTransaction( - val address: String?, - val amount: BigDecimal?, - val amountUi: String?, - val currency: String, - val type: PendingTransactionType -) + val transactionData: TransactionData, + val type: PendingTransactionType, +) { + val address: String? = when (type) { + PendingTransactionType.Incoming -> transactionData.destinationAddress + PendingTransactionType.Outgoing -> transactionData.sourceAddress + PendingTransactionType.Unknown -> null + } + + val amountValue: BigDecimal? = transactionData.amount.value + + val amountValueUi: String? = amountValue?.toFormattedString(transactionData.amount.decimals) + + val currency: String = transactionData.amount.currencySymbol +} enum class PendingTransactionType { Incoming, Outgoing, Unknown } @@ -19,29 +28,11 @@ fun TransactionData.toPendingTransaction(walletAddress: String): PendingTransact if (this.status == TransactionStatus.Confirmed) return null val type: PendingTransactionType = when { - this.sourceAddress == walletAddress -> { - PendingTransactionType.Outgoing - } - this.destinationAddress == walletAddress -> { - PendingTransactionType.Incoming - } - else -> { - PendingTransactionType.Unknown - } + this.sourceAddress == walletAddress -> PendingTransactionType.Outgoing + this.destinationAddress == walletAddress -> PendingTransactionType.Incoming + else -> PendingTransactionType.Unknown } - val address = if (this.sourceAddress == walletAddress) { - this.destinationAddress - } else { - this.sourceAddress - } - - return PendingTransaction( - if (address == "unknown") null else address, - this.amount.value, - this.amount.value?.toFormattedString(amount.decimals), - this.amount.currencySymbol, - type - ) + return PendingTransaction(this, type) } fun List.toPendingTransactions(walletAddress: String): List { From 5ba4effe5f4a76bdc8551042672499906fbf1cd0 Mon Sep 17 00:00:00 2001 From: Tangem Date: Sat, 28 May 2022 18:18:57 +0300 Subject: [PATCH 3/6] Updated on 2026-08-14 --- .../tap/features/wallet/redux/middlewares/WalletMiddleware.kt | 2 +- .../features/wallet/ui/adapters/PendingTransactionsAdapter.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt index 6f0cf6b5cc..a64e4a5368 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt @@ -335,7 +335,7 @@ class WalletMiddleware { val show = if (outgoingTxs.isEmpty()) { isNeedToShowWarning(balance, rentExempt) } else { - val outgoingAmount = outgoingTxs.sumOf { it.amount ?: BigDecimal.ZERO } + val outgoingAmount = outgoingTxs.sumOf { it.amountValue ?: BigDecimal.ZERO } val rest = balance.minus(outgoingAmount) isNeedToShowWarning(rest, rentExempt) } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/PendingTransactionsAdapter.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/PendingTransactionsAdapter.kt index 6fc4e509b1..86ce19dc89 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/PendingTransactionsAdapter.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/PendingTransactionsAdapter.kt @@ -63,7 +63,7 @@ class PendingTransactionsAdapter } binding.tvPendingTransaction.text = binding.root.getString(transactionDescriptionRes) - transaction.amountUi?.let { binding.tvPendingTransactionAmount.text = "$it " } + transaction.amountValueUi?.let { binding.tvPendingTransactionAmount.text = "$it " } binding.tvPendingTransactionCurrency.text = "${transaction.currency}" if (transaction.address != null) { From 90d157ff37c7796382a984bf19ed472d5e1b1585 Mon Sep 17 00:00:00 2001 From: Tangem Date: Sat, 28 May 2022 18:52:40 +0300 Subject: [PATCH 4/6] Updated on 2026-08-14 --- .../wallet/redux/middlewares/TradeCryptoMiddleware.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/TradeCryptoMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/TradeCryptoMiddleware.kt index 45e34c15f9..3e4210fe42 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/TradeCryptoMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/TradeCryptoMiddleware.kt @@ -2,6 +2,7 @@ package com.tangem.tap.features.wallet.redux.middlewares import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager import com.tangem.blockchain.common.AmountType +import com.tangem.tap.common.extensions.dispatchDebugErrorNotification import com.tangem.tap.common.extensions.dispatchOnMain import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.navigation.AppScreen @@ -51,7 +52,10 @@ class TradeCryptoMiddleware { currency is Currency.Token && currency.blockchain.isTestnet() ) { val walletManager = store.state.walletState.getWalletManager(currency) - if (walletManager !is EthereumWalletManager) return + if (walletManager !is EthereumWalletManager) { + store.dispatchDebugErrorNotification("Testnet tokens available only for the ETH") + return + } scope.launch { exchangeManager.buyErc20Tokens(walletManager, currency.token) } return From ac25a445c6ad004c3d2b9f89516dff3e6e9ea47f Mon Sep 17 00:00:00 2001 From: Tangem Date: Sat, 28 May 2022 19:13:46 +0300 Subject: [PATCH 5/6] Updated on 2026-08-14 --- .../tap/features/wallet/models/PendingTransaction.kt | 8 ++++++++ .../com/tangem/tap/features/wallet/redux/WalletState.kt | 9 +++++++-- .../features/wallet/redux/reducers/MultiWalletReducer.kt | 8 ++++---- .../wallet/redux/reducers/OnWalletLoadedReducer.kt | 9 ++++----- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt index 62f4f714b1..d24a3ea480 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt @@ -43,6 +43,14 @@ fun List.removeUnknownTransactions(): List.filterByCoin(): List { + return this.filter { it.transactionData.amount.type == AmountType.Coin } +} + +fun List.filterByToken(token: Token): List { + return this.filter { it.currency == token.symbol } +} + fun TransactionData.toPendingTransactionForToken(token: Token, walletAddress: String): PendingTransaction? { if (this.amount.currencySymbol != token.symbol) return null return this.toPendingTransaction(walletAddress) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt index 9d0e40811a..0e4e83be59 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletState.kt @@ -357,7 +357,11 @@ data class WalletData( return listOfAddresses.size > 1 } - fun shouldEnableTokenSendButton(): Boolean = !blockchainAmountIsEmpty() || !tokenAmountIsEmpty() + fun shouldEnableTokenSendButton(): Boolean = if (blockchainAmountIsEmpty()) { + false + } else { + !tokenAmountIsEmpty() + } fun assembleWarnings(): List { val blockchain = currency.blockchain @@ -380,10 +384,11 @@ data class WalletData( val fullName = currency.blockchain.fullName walletWarnings.add(WalletWarning.BalanceNotEnoughForFee(fullName)) } + return walletWarnings.sortedBy { it.showingPosition } } - private fun blockchainAmountIsEmpty(): Boolean = currencyData.blockchainAmount?.isZero() ?: false + private fun blockchainAmountIsEmpty(): Boolean = currencyData.blockchainAmount?.isZero() == true private fun tokenAmountIsEmpty(): Boolean = currencyData.amount?.isZero() == true } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt index 643fbe7f71..cf8ca6cf56 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt @@ -8,8 +8,9 @@ import com.tangem.tap.common.extensions.toFiatString import com.tangem.tap.common.extensions.toFormattedCurrencyString import com.tangem.tap.domain.getFirstToken import com.tangem.tap.domain.tokens.BlockchainNetwork +import com.tangem.tap.features.wallet.models.filterByToken +import com.tangem.tap.features.wallet.models.getPendingTransactions import com.tangem.tap.features.wallet.models.removeUnknownTransactions -import com.tangem.tap.features.wallet.models.toPendingTransactions import com.tangem.tap.features.wallet.redux.* import com.tangem.tap.features.wallet.ui.BalanceStatus import com.tangem.tap.features.wallet.ui.BalanceWidgetData @@ -106,10 +107,9 @@ class MultiWalletReducer { throw NullPointerException("MultiWallet.TokenLoaded: WalletManager must be no NULL") } - val pendingTransactions = wallet.recentTransactions.toPendingTransactions(wallet.address) + val pendingTransactions = wallet.getPendingTransactions() val tokenSendButton = action.amount.value?.isZero() == false && pendingTransactions.isEmpty() - val tokenPendingTransactions = pendingTransactions - .filter { it.currency == action.amount.currencySymbol } + val tokenPendingTransactions = pendingTransactions.filterByToken(action.token) val tokenBalanceStatus = when { tokenPendingTransactions.isNotEmpty() -> BalanceStatus.TransactionInProgress pendingTransactions.isNotEmpty() -> BalanceStatus.SameCurrencyTransactionInProgress diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt index 2d3c053dab..79a0545616 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt @@ -9,9 +9,9 @@ import com.tangem.tap.common.extensions.toFormattedCurrencyString import com.tangem.tap.common.extensions.toFormattedFiatValue import com.tangem.tap.domain.getFirstToken import com.tangem.tap.domain.tokens.BlockchainNetwork +import com.tangem.tap.features.wallet.models.filterByToken import com.tangem.tap.features.wallet.models.getPendingTransactions import com.tangem.tap.features.wallet.models.removeUnknownTransactions -import com.tangem.tap.features.wallet.models.toPendingTransactions import com.tangem.tap.features.wallet.redux.* import com.tangem.tap.features.wallet.ui.BalanceStatus import com.tangem.tap.features.wallet.ui.BalanceWidgetData @@ -73,8 +73,7 @@ class OnWalletLoadedReducer { val tokens = wallet.getTokens().mapNotNull { token -> val currency = Currency.fromBlockchainNetwork(blockchainNetwork, token) val tokenWalletData = walletState.getWalletData(currency) - val tokenPendingTransactions = - pendingTransactions.filter { it.currency == token.symbol } + val tokenPendingTransactions = pendingTransactions.filterByToken(token) val tokenBalanceStatus = when { tokenPendingTransactions.isNotEmpty() -> BalanceStatus.TransactionInProgress pendingTransactions.isNotEmpty() -> BalanceStatus.SameCurrencyTransactionInProgress @@ -85,7 +84,7 @@ class OnWalletLoadedReducer { tokenWalletData?.fiatRate?.let { rate -> tokenAmountValue?.toFiatValue(rate) } val tokenSendButton = newWalletData.shouldEnableTokenSendButton() - && tokenPendingTransactions.isEmpty() + && tokenPendingTransactions.isEmpty() tokenWalletData?.copy( currencyData = tokenWalletData.currencyData.copy( status = tokenBalanceStatus, @@ -156,7 +155,7 @@ class OnWalletLoadedReducer { val fiatAmountRaw = fiatRate?.multiply(amount)?.setScale(2, RoundingMode.DOWN) val fiatAmount = fiatRate?.let { amount?.toFiatString(it, fiatCurrencyName) } - val pendingTransactions = wallet.recentTransactions.toPendingTransactions(wallet.address) + val pendingTransactions = wallet.getPendingTransactions() val sendButtonEnabled = amount?.isZero() == false && pendingTransactions.isEmpty() val balanceStatus = if (pendingTransactions.isNotEmpty()) { BalanceStatus.TransactionInProgress From b2cb46f21a3605de78fdc29b786f9cd1fc3e9fc5 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 30 May 2022 15:32:04 +0300 Subject: [PATCH 6/6] Updated on 2026-08-14 --- .../features/wallet/redux/reducers/MultiWalletReducer.kt | 7 ++++--- .../wallet/redux/reducers/OnWalletLoadedReducer.kt | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt index cf8ca6cf56..054a46cf8a 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/MultiWalletReducer.kt @@ -2,8 +2,8 @@ package com.tangem.tap.features.wallet.redux.reducers import com.tangem.blockchain.common.AmountType import com.tangem.blockchain.common.Token +import com.tangem.blockchain.extensions.isAboveZero import com.tangem.common.extensions.guard -import com.tangem.common.extensions.isZero import com.tangem.tap.common.extensions.toFiatString import com.tangem.tap.common.extensions.toFormattedCurrencyString import com.tangem.tap.domain.getFirstToken @@ -108,7 +108,6 @@ class MultiWalletReducer { } val pendingTransactions = wallet.getPendingTransactions() - val tokenSendButton = action.amount.value?.isZero() == false && pendingTransactions.isEmpty() val tokenPendingTransactions = pendingTransactions.filterByToken(action.token) val tokenBalanceStatus = when { tokenPendingTransactions.isNotEmpty() -> BalanceStatus.TransactionInProgress @@ -116,6 +115,8 @@ class MultiWalletReducer { else -> BalanceStatus.VerifiedOnline } val tokenWalletData = state.getWalletData(currency) + val isTokenSendButtonEnabled = action.amount.isAboveZero() && pendingTransactions.isEmpty() + val newTokenWalletData = tokenWalletData?.copy( currencyData = tokenWalletData.currencyData.copy( status = tokenBalanceStatus, @@ -130,7 +131,7 @@ class MultiWalletReducer { blockchainAmount = wallet.amounts[AmountType.Coin]?.value ?: BigDecimal.ZERO ), pendingTransactions = pendingTransactions.removeUnknownTransactions(), - mainButton = WalletMainButton.SendButton(tokenSendButton), + mainButton = WalletMainButton.SendButton(isTokenSendButtonEnabled), currency = Currency.Token( token = action.token, blockchain = action.blockchain.blockchain, diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt index 79a0545616..34b6277cb6 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt @@ -46,7 +46,7 @@ class OnWalletLoadedReducer { ) val pendingTransactions = wallet.getPendingTransactions() - val coinSendButton = coinAmountValue?.isZero() == false && pendingTransactions.isEmpty() + val isCoinSendButtonEnabled = coinAmountValue?.isZero() == false && pendingTransactions.isEmpty() val balanceStatus = if (pendingTransactions.isNotEmpty()) { BalanceStatus.TransactionInProgress } else { @@ -65,7 +65,7 @@ class OnWalletLoadedReducer { fiatAmountFormatted = fiatAmount?.toFormattedFiatValue(fiatCurrency.symbol) ), pendingTransactions = pendingTransactions.removeUnknownTransactions(), - mainButton = WalletMainButton.SendButton(coinSendButton), + mainButton = WalletMainButton.SendButton(isCoinSendButtonEnabled), currency = Currency.fromBlockchainNetwork(blockchainNetwork), tradeCryptoState = TradeCryptoState.from(exchangeManager, walletData), ) @@ -83,7 +83,7 @@ class OnWalletLoadedReducer { val tokenFiatAmount = tokenWalletData?.fiatRate?.let { rate -> tokenAmountValue?.toFiatValue(rate) } - val tokenSendButton = newWalletData.shouldEnableTokenSendButton() + val isTokenSendButtonEnabled = newWalletData.shouldEnableTokenSendButton() && tokenPendingTransactions.isEmpty() tokenWalletData?.copy( currencyData = tokenWalletData.currencyData.copy( @@ -98,7 +98,7 @@ class OnWalletLoadedReducer { fiatAmountFormatted = tokenFiatAmount?.toFormattedFiatValue(fiatCurrency.code) ), pendingTransactions = tokenPendingTransactions.removeUnknownTransactions(), - mainButton = WalletMainButton.SendButton(tokenSendButton), + mainButton = WalletMainButton.SendButton(isTokenSendButtonEnabled), tradeCryptoState = TradeCryptoState.from(exchangeManager, tokenWalletData), ) }