From 20755c42bbbc9990d5af92db755f2bb35fededde Mon Sep 17 00:00:00 2001 From: Tangem Date: Sat, 28 May 2022 16:12:25 +0300 Subject: [PATCH 1/8] 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/8] 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/8] 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/8] 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/8] 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 0c57e22fb3e4780f230b9cef846aa5d772fa25a5 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 27 May 2022 17:35:14 +0300 Subject: [PATCH 6/8] Updated on 2026-08-14 --- .../wallet/ui/WalletDetailsFragment.kt | 29 +++--- .../wallet/ui/view/WalletDetailsButtonsRow.kt | 45 ++++++++++ .../res/layout/fragment_wallet_details.xml | 89 ++++--------------- .../view_wallet_details_buttons_row.xml | 50 +++++++++++ 4 files changed, 132 insertions(+), 81 deletions(-) create mode 100644 app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt create mode 100644 app/src/main/res/layout/view_wallet_details_buttons_row.xml diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt index f267c25f89..1613621c1c 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt @@ -92,14 +92,18 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), } private fun setupButtons() = with(binding) { - btnConfirm.text = getString(R.string.wallet_button_send) - btnConfirm.setOnClickListener { store.dispatch(WalletAction.Send()) } - - binding.lWalletDetails.btnShare.setOnClickListener { store.dispatch(WalletAction.ShowDialog.QrCode) } - - btnTrade.setOnClickListener { store.dispatch(WalletAction.TradeCryptoAction.Buy) } - - btnSell.setOnClickListener { store.dispatch(WalletAction.TradeCryptoAction.Sell) } + rowButtons.onBuyClick = { + store.dispatch(WalletAction.TradeCryptoAction.Buy) + } + rowButtons.onSellClick = { + store.dispatch(WalletAction.TradeCryptoAction.Sell) + } + rowButtons.onTradeClick = { + store.dispatch(WalletAction.DialogAction.ChooseTradeActionDialog) + } + rowButtons.onSendClick = { + store.dispatch(WalletAction.Send()) + } } private fun setupTestActionButton() { @@ -156,7 +160,6 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), } private fun setupButtons(selectedWallet: WalletData) = with(binding) { - btnConfirm.isEnabled = selectedWallet.mainButton.enabled lWalletDetails.btnCopy.setOnClickListener { selectedWallet.walletAddresses?.selectedAddress?.address?.let { addressString -> store.dispatch(WalletAction.CopyAddress(addressString, requireContext())) @@ -167,8 +170,12 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), store.dispatch(WalletAction.ShareAddress(addressString, requireContext())) } } - btnTrade.isEnabled = selectedWallet.tradeCryptoState.buyingAllowed - btnSell.show(selectedWallet.tradeCryptoState.sellingAllowed) + + rowButtons.updateButtonsVisibility( + buyAllowed = selectedWallet.tradeCryptoState.buyingAllowed, + sellAllowed = selectedWallet.tradeCryptoState.sellingAllowed, + sendAllowed = selectedWallet.mainButton.enabled + ) } private fun handleWarnings(selectedWallet: WalletData) = with(binding) { diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt new file mode 100644 index 0000000000..f4da3e86ce --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt @@ -0,0 +1,45 @@ +package com.tangem.tap.features.wallet.ui.view + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.widget.LinearLayout +import androidx.core.view.isVisible +import com.tangem.wallet.databinding.ViewWalletDetailsButtonsRowBinding + +internal class WalletDetailsButtonsRow @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0, +) : LinearLayout(context, attrs, defStyleAttr) { + private val binding = ViewWalletDetailsButtonsRowBinding.inflate( + LayoutInflater.from(context), + this + ) + + var onBuyClick: (() -> Unit)? = null + var onSellClick: (() -> Unit)? = null + var onTradeClick: (() -> Unit)? = null + var onSendClick: (() -> Unit)? = null + + init { + orientation = HORIZONTAL + + with(binding) { + btnBuy.setOnClickListener { onBuyClick?.invoke() } + btnSell.setOnClickListener { onSellClick?.invoke() } + btnTrade.setOnClickListener { onTradeClick?.invoke() } + btnSend.setOnClickListener { onSendClick?.invoke() } + } + } + + fun renderButtons( + buyAllowed: Boolean, + sellAllowed: Boolean, + ) = with(binding) { + btnBuy.isVisible = (buyAllowed && !sellAllowed) || (!buyAllowed && !sellAllowed) + btnBuy.isEnabled = buyAllowed + btnSell.isVisible = !buyAllowed && sellAllowed + btnTrade.isVisible = buyAllowed && sellAllowed + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_wallet_details.xml b/app/src/main/res/layout/fragment_wallet_details.xml index cd51f4c2fa..04649efe6b 100644 --- a/app/src/main/res/layout/fragment_wallet_details.xml +++ b/app/src/main/res/layout/fragment_wallet_details.xml @@ -105,78 +105,27 @@ android:layout_marginStart="16dp" android:layout_marginEnd="16dp" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/l_wallet_details" /> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/l_wallet_details" /> + android:id="@+id/barrier" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:barrierDirection="bottom" + app:constraint_referenced_ids="l_wallet_details" /> - - - - - - - - - + @@ -184,4 +133,4 @@ - \ No newline at end of file + diff --git a/app/src/main/res/layout/view_wallet_details_buttons_row.xml b/app/src/main/res/layout/view_wallet_details_buttons_row.xml new file mode 100644 index 0000000000..bb5bd190b0 --- /dev/null +++ b/app/src/main/res/layout/view_wallet_details_buttons_row.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + From 2571bc8e560ed42829195177290d8c07e4068f33 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 27 May 2022 17:36:03 +0300 Subject: [PATCH 7/8] Updated on 2026-08-14 --- .../com/tangem/tap/common/DialogManager.kt | 14 +++++- .../tangem/tap/common/redux/StateDialog.kt | 6 --- .../home/compose/FirstStoriesContent.kt | 6 ++- .../tap/features/wallet/redux/WalletAction.kt | 19 ++++---- .../tap/features/wallet/redux/WalletState.kt | 14 +++--- .../middlewares/AppCurrencyMiddleware.kt | 6 +-- .../middlewares/WalletDialogsMiddleware.kt | 39 ++++++++++++++++ .../redux/middlewares/WalletMiddleware.kt | 17 ++----- .../wallet/redux/reducers/WalletReducer.kt | 15 ------- .../wallet/ui/WalletDetailsFragment.kt | 45 +++++++++---------- .../ui/adapters/WarningMessagesAdapter.kt | 9 +++- ...og.kt => AmountToSendBottomSheetDialog.kt} | 20 ++++++--- ... => ChooseTradeActionBottomSheetDialog.kt} | 4 +- .../ui/dialogs/SignedHashesWarningDialog.kt | 2 +- .../wallet/ui/view/WalletDetailsButtonsRow.kt | 4 +- .../ui/wallet/CurrencySelectionDialog.kt | 4 +- .../wallet/ui/wallet/MultiWalletView.kt | 22 --------- .../wallet/ui/wallet/SingleWalletView.kt | 43 ++++-------------- 18 files changed, 142 insertions(+), 147 deletions(-) create mode 100644 app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletDialogsMiddleware.kt rename app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/{AmountToSendDialog.kt => AmountToSendBottomSheetDialog.kt} (80%) rename app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/{ChooseTradeActionDialog.kt => ChooseTradeActionBottomSheetDialog.kt} (87%) diff --git a/app/src/main/java/com/tangem/tap/common/DialogManager.kt b/app/src/main/java/com/tangem/tap/common/DialogManager.kt index 19dd6168cb..8af2818c0a 100644 --- a/app/src/main/java/com/tangem/tap/common/DialogManager.kt +++ b/app/src/main/java/com/tangem/tap/common/DialogManager.kt @@ -19,7 +19,11 @@ import com.tangem.tap.features.onboarding.products.wallet.ui.dialogs.AddMoreBack import com.tangem.tap.features.onboarding.products.wallet.ui.dialogs.BackupInProgressDialog import com.tangem.tap.features.onboarding.products.wallet.ui.dialogs.ConfirmDiscardingBackupDialog import com.tangem.tap.features.onboarding.products.wallet.ui.dialogs.UnfinishedBackupFoundDialog +import com.tangem.tap.features.wallet.redux.WalletDialog +import com.tangem.tap.features.wallet.ui.dialogs.AmountToSendBottomSheetDialog +import com.tangem.tap.features.wallet.ui.dialogs.ChooseTradeActionBottomSheetDialog import com.tangem.tap.features.wallet.ui.dialogs.ScanFailsDialog +import com.tangem.tap.features.wallet.ui.dialogs.SignedHashesWarningDialog import com.tangem.tap.features.wallet.ui.dialogs.SimpleOkDialog import com.tangem.tap.features.wallet.ui.wallet.CurrencySelectionDialog import com.tangem.tap.store @@ -60,8 +64,6 @@ class DialogManager : StoreSubscriber { is AppDialog.ScanFailsDialog -> ScanFailsDialog.create(context) is AppDialog.AddressInfoDialog -> AddressInfoBottomSheetDialog(state.dialog, context) is AppDialog.TestActionsDialog -> TestActionsBottomSheetDialog(state.dialog, context) - is AppDialog.CurrencySelectionDialog -> - CurrencySelectionDialog.create(state.dialog, context) is TwinCardsAction.Wallet.ShowInterruptDialog -> CreateWalletInterruptDialog.create(state.dialog, context) is WalletConnectDialog.UnsupportedCard -> @@ -105,6 +107,14 @@ class DialogManager : StoreSubscriber { is BackupDialog.BackupInProgress -> BackupInProgressDialog.create(context) is BackupDialog.UnfinishedBackupFound -> UnfinishedBackupFoundDialog.create(context) is BackupDialog.ConfirmDiscardingBackup -> ConfirmDiscardingBackupDialog.create(context) + is WalletDialog.CurrencySelectionDialog -> + CurrencySelectionDialog.create(state.dialog, context) + is WalletDialog.ChooseTradeActionDialog -> + ChooseTradeActionBottomSheetDialog(context) + is WalletDialog.SelectAmountToSendDialog -> + AmountToSendBottomSheetDialog(context, state.dialog) + is WalletDialog.SignedHashesMultiWalletDialog -> + SignedHashesWarningDialog.create(context) else -> null } dialog?.show() diff --git a/app/src/main/java/com/tangem/tap/common/redux/StateDialog.kt b/app/src/main/java/com/tangem/tap/common/redux/StateDialog.kt index 6181bbbc44..591a20e896 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/StateDialog.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/StateDialog.kt @@ -2,7 +2,6 @@ package com.tangem.tap.common.redux import com.tangem.common.extensions.VoidCallback import com.tangem.tap.common.TestAction -import com.tangem.tap.common.entities.FiatCurrency import com.tangem.tap.features.wallet.redux.AddressData import com.tangem.tap.features.wallet.redux.Currency @@ -28,9 +27,4 @@ sealed class AppDialog : StateDialog { data class TestActionsDialog( val actionsList: List ) : AppDialog() - - data class CurrencySelectionDialog( - val currenciesList: List, - val currentAppCurrency: FiatCurrency, - ) : AppDialog() } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/home/compose/FirstStoriesContent.kt b/app/src/main/java/com/tangem/tap/features/home/compose/FirstStoriesContent.kt index 6bb3d25b87..30e72ec626 100644 --- a/app/src/main/java/com/tangem/tap/features/home/compose/FirstStoriesContent.kt +++ b/app/src/main/java/com/tangem/tap/features/home/compose/FirstStoriesContent.kt @@ -8,7 +8,11 @@ import androidx.compose.animation.core.tween import androidx.compose.animation.scaleIn import androidx.compose.animation.slideInVertically import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.mutableStateOf diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletAction.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletAction.kt index ce2ce4b63d..48712bb6d7 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletAction.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletAction.kt @@ -121,10 +121,8 @@ sealed class WalletAction : Action { data class Send(val amount: Amount? = null) : WalletAction() { data class ChooseCurrency(val amounts: List?) : WalletAction() - object Cancel : WalletAction() } - object EmptyField : WalletAction(), ErrorAction { override val error = TapError.PayIdEmptyField } @@ -137,13 +135,18 @@ sealed class WalletAction : Action { data class ShareAddress(val address: String, val context: Context) : WalletAction() - object ShowDialog : WalletAction() { - object QrCode : WalletAction() - object SignedHashesMultiWalletDialog : WalletAction() - object ChooseTradeActionDialog : WalletAction() - } + sealed class DialogAction : WalletAction() { + data class QrCode( + val currency: Currency, + val selectedAddress: AddressData, + ) : DialogAction() - object HideDialog : WalletAction() + object SignedHashesMultiWalletDialog : DialogAction() + object ChooseTradeActionDialog : DialogAction() + data class ChooseCurrency(val amounts: List?) : DialogAction() + + object Hide : DialogAction() + } data class ExploreAddress(val exploreUrl: String, val context: Context) : WalletAction() 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 f5b14fe589..df341d3e17 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 @@ -15,6 +15,7 @@ import com.tangem.domain.common.extensions.canHandleToken import com.tangem.domain.common.extensions.toCoinId import com.tangem.domain.features.addCustomToken.CustomCurrency import com.tangem.tap.common.entities.Button +import com.tangem.tap.common.entities.FiatCurrency import com.tangem.tap.common.extensions.toQrCode import com.tangem.tap.common.redux.StateDialog import com.tangem.tap.common.redux.global.CryptoCurrencyName @@ -47,7 +48,6 @@ data class WalletState( val error: ErrorType? = null, val cardImage: Artwork? = null, val hashesCountVerified: Boolean? = null, - val walletDialog: StateDialog? = null, val mainWarningsList: List = mutableListOf(), val wallets: List = listOf(), val isMultiwalletAllowed: Boolean = false, @@ -301,10 +301,14 @@ data class WalletState( } } -sealed class WalletDialog : StateDialog { - data class SelectAmountToSendDialog(val amounts: List?) : WalletDialog() - object SignedHashesMultiWalletDialog : WalletDialog() - object ChooseTradeActionDialog : WalletDialog() +sealed interface WalletDialog : StateDialog { + data class SelectAmountToSendDialog(val amounts: List?) : WalletDialog + object SignedHashesMultiWalletDialog : WalletDialog + object ChooseTradeActionDialog : WalletDialog + data class CurrencySelectionDialog( + val currenciesList: List, + val currentAppCurrency: FiatCurrency, + ) : WalletDialog } enum class ProgressState : WidgetState { Loading, Done, Error } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/AppCurrencyMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/AppCurrencyMiddleware.kt index 3c9c87e9f8..904aecab65 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/AppCurrencyMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/AppCurrencyMiddleware.kt @@ -5,10 +5,10 @@ import com.tangem.network.api.tangemTech.CurrenciesResponse import com.tangem.network.api.tangemTech.TangemTechService import com.tangem.tap.common.entities.FiatCurrency import com.tangem.tap.common.extensions.dispatchDialogShow -import com.tangem.tap.common.redux.AppDialog import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.domain.TapWalletManager import com.tangem.tap.features.wallet.redux.WalletAction +import com.tangem.tap.features.wallet.redux.WalletDialog import com.tangem.tap.persistence.FiatCurrenciesPrefStorage import com.tangem.tap.scope import com.tangem.tap.store @@ -31,7 +31,7 @@ class AppCurrencyMiddleware( val storedFiatCurrencies = fiatCurrenciesPrefStorage.restore() if (storedFiatCurrencies.isNotEmpty()) { store.dispatchDialogShow( - AppDialog.CurrencySelectionDialog( + WalletDialog.CurrencySelectionDialog( currenciesList = storedFiatCurrencies.mapToUiModel(), currentAppCurrency = appCurrencyProvider.invoke() ) @@ -47,7 +47,7 @@ class AppCurrencyMiddleware( ) { fiatCurrenciesPrefStorage.save(currenciesList) store.dispatchDialogShow( - AppDialog.CurrencySelectionDialog( + WalletDialog.CurrencySelectionDialog( currenciesList = currenciesList.mapToUiModel(), currentAppCurrency = appCurrencyProvider.invoke() ) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletDialogsMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletDialogsMiddleware.kt new file mode 100644 index 0000000000..e495c55c94 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletDialogsMiddleware.kt @@ -0,0 +1,39 @@ +package com.tangem.tap.features.wallet.redux.middlewares + +import com.tangem.tap.common.extensions.dispatchDialogHide +import com.tangem.tap.common.extensions.dispatchDialogShow +import com.tangem.tap.common.redux.AppDialog +import com.tangem.tap.features.wallet.redux.WalletAction +import com.tangem.tap.features.wallet.redux.WalletDialog +import com.tangem.tap.store + +class WalletDialogsMiddleware { + fun handle(action: WalletAction.DialogAction) { + when (action) { + is WalletAction.DialogAction.SignedHashesMultiWalletDialog -> { + store.dispatchDialogShow(WalletDialog.SignedHashesMultiWalletDialog) + } + is WalletAction.DialogAction.ChooseTradeActionDialog -> { + store.dispatchDialogShow(WalletDialog.ChooseTradeActionDialog) + } + is WalletAction.DialogAction.QrCode -> { + store.dispatchDialogShow( + AppDialog.AddressInfoDialog( + currency = action.currency, + addressData = action.selectedAddress, + ) + ) + } + is WalletAction.DialogAction.ChooseCurrency -> { + store.dispatchDialogShow( + WalletDialog.SelectAmountToSendDialog( + amounts = action.amounts + ) + ) + } + is WalletAction.DialogAction.Hide -> { + store.dispatchDialogHide() + } + } + } +} \ No newline at end of file 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..369a3955e0 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 @@ -17,12 +17,10 @@ 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.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 @@ -58,6 +56,7 @@ class WalletMiddleware { private val tradeCryptoMiddleware = TradeCryptoMiddleware() private val warningsMiddleware = WarningsMiddleware() private val multiWalletMiddleware = MultiWalletMiddleware() + private val walletDialogMiddleware = WalletDialogsMiddleware() private val appCurrencyMiddleware by lazy(mode = LazyThreadSafetyMode.NONE) { AppCurrencyMiddleware( tangemTechService = store.state.domainNetworks.tangemTechService, @@ -91,6 +90,7 @@ class WalletMiddleware { globalState ) is WalletAction.AppCurrencyAction -> appCurrencyMiddleware.handle(action) + is WalletAction.DialogAction -> walletDialogMiddleware.handle(action) is WalletAction.LoadWallet -> { scope.launch { if (action.blockchain == null) { @@ -242,15 +242,6 @@ class WalletMiddleware { store.dispatch(NavigationAction.NavigateTo(AppScreen.Send)) } } - is WalletAction.ShowDialog.QrCode -> { - val selectedWalletData = - walletState.getWalletData(walletState.selectedCurrency) ?: return - val selectedAddressData = - selectedWalletData.walletAddresses?.selectedAddress ?: return - - val currency = selectedWalletData.currency - store.dispatchDialogShow(AppDialog.AddressInfoDialog(currency, selectedAddressData)) - } } } @@ -272,7 +263,7 @@ class WalletMiddleware { is Currency.Blockchain -> { val amountToSend = amounts?.find { it.currencySymbol == currency.blockchain.currency } - ?: return WalletAction.Send.ChooseCurrency(amounts) + ?: return WalletAction.DialogAction.ChooseCurrency(amounts) PrepareSendScreen( coinAmount = amountToSend, coinRate = selectedWalletData.fiatRate, @@ -282,7 +273,7 @@ class WalletMiddleware { is Currency.Token -> { val amountToSend = amounts?.find { it.currencySymbol == currency.token.symbol } - ?: return WalletAction.Send.ChooseCurrency(amounts) + ?: return WalletAction.DialogAction.ChooseCurrency(amounts) prepareSendActionForToken( amount = amountToSend, state = state, diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt index 65e89b0d83..7cf3776bd9 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt @@ -284,21 +284,6 @@ private fun internalReduce(action: Action, state: AppState): WalletState { } newState = newState.copy(cardImage = Artwork(artworkId = artworkUrl)) } - is WalletAction.ShowDialog.SignedHashesMultiWalletDialog -> { - newState = newState.copy(walletDialog = WalletDialog.SignedHashesMultiWalletDialog) - } - is WalletAction.ShowDialog.ChooseTradeActionDialog -> { - newState = newState.copy(walletDialog = WalletDialog.ChooseTradeActionDialog) - } - is WalletAction.HideDialog -> { - newState = newState.copy(walletDialog = null) - } - is WalletAction.Send.ChooseCurrency -> { - newState = newState.copy( - walletDialog = WalletDialog.SelectAmountToSendDialog(action.amounts) - ) - } - is WalletAction.Send.Cancel -> newState = newState.copy(walletDialog = null) is WalletAction.TradeCryptoAction -> return newState is WalletAction.ChangeSelectedAddress -> { val selectedWalletData = newState.getWalletData(newState.selectedCurrency) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt index 1613621c1c..6c652d40c8 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt @@ -1,8 +1,11 @@ package com.tangem.tap.features.wallet.ui -import android.app.Dialog import android.os.Bundle -import android.view.* +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem +import android.view.View +import android.view.ViewGroup import android.widget.TextView import androidx.activity.OnBackPressedCallback import androidx.annotation.ColorRes @@ -15,17 +18,28 @@ import by.kirich1409.viewbindingdelegate.viewBinding import com.squareup.picasso.Picasso import com.tangem.tap.common.SnackbarHandler import com.tangem.tap.common.TestActions -import com.tangem.tap.common.extensions.* +import com.tangem.tap.common.extensions.appendIfNotNull +import com.tangem.tap.common.extensions.beginDelayedTransition +import com.tangem.tap.common.extensions.fitChipsByGroupWidth +import com.tangem.tap.common.extensions.getColor +import com.tangem.tap.common.extensions.getString +import com.tangem.tap.common.extensions.hide +import com.tangem.tap.common.extensions.loadCurrenciesIcon +import com.tangem.tap.common.extensions.show +import com.tangem.tap.common.extensions.toQrCode import com.tangem.tap.common.recyclerView.SpaceItemDecoration -import com.tangem.tap.common.redux.StateDialog import com.tangem.tap.common.redux.navigation.NavigationAction import com.tangem.tap.domain.tokens.BlockchainNetwork import com.tangem.tap.features.onboarding.getQRReceiveMessage import com.tangem.tap.features.wallet.models.PendingTransaction -import com.tangem.tap.features.wallet.redux.* +import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.redux.ErrorType +import com.tangem.tap.features.wallet.redux.ProgressState +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.ui.adapters.PendingTransactionsAdapter import com.tangem.tap.features.wallet.ui.adapters.WalletDetailWarningMessagesAdapter -import com.tangem.tap.features.wallet.ui.dialogs.AmountToSendDialog import com.tangem.tap.features.wallet.ui.test.TestWalletDetails import com.tangem.tap.store import com.tangem.wallet.R @@ -37,7 +51,6 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), private lateinit var pendingTransactionAdapter: PendingTransactionsAdapter private lateinit var warningMessagesAdapter: WalletDetailWarningMessagesAdapter - private var dialog: Dialog? = null private val binding: FragmentWalletDetailsBinding by viewBinding(FragmentWalletDetailsBinding::bind) @@ -128,7 +141,6 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), setupBalanceData(selectedWallet.currencyData) setupButtons(selectedWallet) - handleDialogs(state.walletDialog) handleCurrencyIcon(selectedWallet) handleWarnings(selectedWallet) @@ -174,7 +186,7 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), rowButtons.updateButtonsVisibility( buyAllowed = selectedWallet.tradeCryptoState.buyingAllowed, sellAllowed = selectedWallet.tradeCryptoState.sellingAllowed, - sendAllowed = selectedWallet.mainButton.enabled + sendAllowed = selectedWallet.mainButton.enabled, ) } @@ -298,21 +310,6 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), } } - private fun handleDialogs(walletDialog: StateDialog?) { - when (walletDialog) { - is WalletDialog.SelectAmountToSendDialog -> { - if (dialog == null) dialog = AmountToSendDialog(requireContext()).apply { - this.show(walletDialog.amounts) - } - } - null -> { - dialog?.dismiss() - dialog = null - } - } - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { R.id.menu_remove -> { diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WarningMessagesAdapter.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WarningMessagesAdapter.kt index 946e347a65..9014d5d4ff 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WarningMessagesAdapter.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WarningMessagesAdapter.kt @@ -10,7 +10,12 @@ import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.google.android.play.core.review.ReviewManagerFactory import com.tangem.tap.common.analytics.AnalyticsEvent -import com.tangem.tap.common.extensions.* +import com.tangem.tap.common.extensions.dispatchOpenUrl +import com.tangem.tap.common.extensions.getActivity +import com.tangem.tap.common.extensions.getColor +import com.tangem.tap.common.extensions.getString +import com.tangem.tap.common.extensions.hide +import com.tangem.tap.common.extensions.show import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.domain.configurable.warningMessage.WarningMessage import com.tangem.tap.domain.configurable.warningMessage.WarningMessagesManager @@ -87,7 +92,7 @@ class WarningMessageVH(val binding: LayoutWarningCardActionBinding) : RecyclerVi when { warning.titleResId == R.string.warning_important_security_info -> { View.OnClickListener { - store.dispatch(WalletAction.ShowDialog.SignedHashesMultiWalletDialog) + store.dispatch(WalletAction.DialogAction.SignedHashesMultiWalletDialog) } } warning.messageResId == R.string.alert_funds_restoration_message -> { diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendDialog.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendBottomSheetDialog.kt similarity index 80% rename from app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendDialog.kt rename to app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendBottomSheetDialog.kt index 69219eff90..2f9e597096 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendBottomSheetDialog.kt @@ -5,17 +5,25 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.view.ContextThemeWrapper -import androidx.recyclerview.widget.* +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView import com.google.android.material.bottomsheet.BottomSheetDialog import com.tangem.blockchain.common.Amount import com.tangem.tap.common.extensions.toFormattedString import com.tangem.tap.features.wallet.redux.WalletAction +import com.tangem.tap.features.wallet.redux.WalletDialog import com.tangem.tap.store import com.tangem.wallet.R import com.tangem.wallet.databinding.DialogWalletSendBinding import com.tangem.wallet.databinding.ItemWalletAmountToSendBinding -class AmountToSendDialog(context: Context) : BottomSheetDialog(context) { +class AmountToSendBottomSheetDialog( + context: Context, + private val dialog: WalletDialog.SelectAmountToSendDialog, +) : BottomSheetDialog(context) { var binding: DialogWalletSendBinding? = null @@ -25,12 +33,12 @@ class AmountToSendDialog(context: Context) : BottomSheetDialog(context) { setContentView(binding!!.root) } - fun show(amounts: List?) { + override fun show() { super.show() setOnDismissListener { binding = null - store.dispatch(WalletAction.Send.Cancel) + store.dispatch(WalletAction.DialogAction.Hide) } binding!!.rvAmountsToSend.layoutManager = LinearLayoutManager(context) @@ -43,7 +51,7 @@ class AmountToSendDialog(context: Context) : BottomSheetDialog(context) { val viewAdapter = ChooseAmountAdapter() binding!!.rvAmountsToSend.adapter = viewAdapter - viewAdapter.submitList(amounts) + viewAdapter.submitList(dialog.amounts) } } @@ -79,7 +87,7 @@ class ChooseAmountAdapter tvCurrencySymbol.text = amount.currencySymbol tvAmount.text = amount.value?.toFormattedString(amount.decimals) root.setOnClickListener { - store.dispatch(WalletAction.Send.Cancel) + store.dispatch(WalletAction.DialogAction.Hide) store.dispatch(WalletAction.Send(amount)) } } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/ChooseTradeActionDialog.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/ChooseTradeActionBottomSheetDialog.kt similarity index 87% rename from app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/ChooseTradeActionDialog.kt rename to app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/ChooseTradeActionBottomSheetDialog.kt index 93baaf29a3..1c65315d3a 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/ChooseTradeActionDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/ChooseTradeActionBottomSheetDialog.kt @@ -8,7 +8,7 @@ import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.store import com.tangem.wallet.databinding.DialogWalletTradeBinding -class ChooseTradeActionDialog(context: Context) : BottomSheetDialog(context) { +class ChooseTradeActionBottomSheetDialog(context: Context) : BottomSheetDialog(context) { var binding: DialogWalletTradeBinding? = null @@ -23,7 +23,7 @@ class ChooseTradeActionDialog(context: Context) : BottomSheetDialog(context) { this.setOnDismissListener { binding = null - store.dispatch(WalletAction.HideDialog) + store.dispatch(WalletAction.DialogAction.Hide) } binding!!.dialogBtnBuy.setOnClickListener { diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/SignedHashesWarningDialog.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/SignedHashesWarningDialog.kt index 9aaf4b88d6..609537bbaf 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/SignedHashesWarningDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/SignedHashesWarningDialog.kt @@ -24,7 +24,7 @@ class SignedHashesWarningDialog { } setNegativeButton(R.string.common_cancel) { _, _ -> } setOnDismissListener { - store.dispatch(WalletAction.HideDialog) + store.dispatch(WalletAction.DialogAction.Hide) } }.create() } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt index f4da3e86ce..12efe010c8 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/view/WalletDetailsButtonsRow.kt @@ -33,13 +33,15 @@ internal class WalletDetailsButtonsRow @JvmOverloads constructor( } } - fun renderButtons( + fun updateButtonsVisibility( buyAllowed: Boolean, sellAllowed: Boolean, + sendAllowed: Boolean ) = with(binding) { btnBuy.isVisible = (buyAllowed && !sellAllowed) || (!buyAllowed && !sellAllowed) btnBuy.isEnabled = buyAllowed btnSell.isVisible = !buyAllowed && sellAllowed btnTrade.isVisible = buyAllowed && sellAllowed + btnSend.isEnabled = sendAllowed } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/CurrencySelectionDialog.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/CurrencySelectionDialog.kt index deab5c4759..78b665cde6 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/CurrencySelectionDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/CurrencySelectionDialog.kt @@ -3,14 +3,14 @@ package com.tangem.tap.features.wallet.ui.wallet import android.content.Context import androidx.appcompat.app.AlertDialog import com.tangem.tap.common.extensions.dispatchDialogHide -import com.tangem.tap.common.redux.AppDialog import com.tangem.tap.features.wallet.redux.WalletAction +import com.tangem.tap.features.wallet.redux.WalletDialog import com.tangem.tap.store import com.tangem.wallet.R object CurrencySelectionDialog { fun create( - dialog: AppDialog.CurrencySelectionDialog, + dialog: WalletDialog.CurrencySelectionDialog, context: Context ): AlertDialog { val currenciesToShow = dialog.currenciesList diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/MultiWalletView.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/MultiWalletView.kt index 623f19e85d..b777d3ef00 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/MultiWalletView.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/MultiWalletView.kt @@ -1,6 +1,5 @@ package com.tangem.tap.features.wallet.ui.wallet -import android.app.Dialog import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager import com.tangem.common.card.Card @@ -10,19 +9,16 @@ import com.tangem.tap.common.extensions.animateVisibility import com.tangem.tap.common.extensions.formatAmountAsSpannedString import com.tangem.tap.common.extensions.hide import com.tangem.tap.common.extensions.show -import com.tangem.tap.common.redux.StateDialog import com.tangem.tap.common.redux.navigation.AppScreen import com.tangem.tap.common.redux.navigation.NavigationAction import com.tangem.tap.currenciesRepository import com.tangem.tap.features.tokens.redux.TokensAction import com.tangem.tap.features.wallet.models.TotalBalance import com.tangem.tap.features.wallet.redux.WalletAction -import com.tangem.tap.features.wallet.redux.WalletDialog import com.tangem.tap.features.wallet.redux.WalletState import com.tangem.tap.features.wallet.ui.BalanceStatus import com.tangem.tap.features.wallet.ui.WalletFragment import com.tangem.tap.features.wallet.ui.adapters.WalletAdapter -import com.tangem.tap.features.wallet.ui.dialogs.SignedHashesWarningDialog import com.tangem.tap.store import com.tangem.wallet.R import com.tangem.wallet.databinding.FragmentWalletBinding @@ -32,7 +28,6 @@ class MultiWalletView : WalletView { private var fragment: WalletFragment? = null private var binding: FragmentWalletBinding? = null - private var dialog: Dialog? = null private lateinit var walletsAdapter: WalletAdapter @@ -122,7 +117,6 @@ class MultiWalletView : WalletView { store.dispatch(NavigationAction.NavigateTo(AppScreen.AddTokens)) } handleErrorStates(state = state, binding = binding, fragment = fragment) - handleDialogs(state.walletDialog) } private fun handleTotalBalance( @@ -200,20 +194,4 @@ class MultiWalletView : WalletView { lButtonsLong.btnConfirmLong.text = fragment?.getText(R.string.wallet_button_create_wallet) } - - private fun handleDialogs(walletDialog: StateDialog?) { - val fragment = fragment ?: return - val context = fragment.context ?: return - when (walletDialog) { - is WalletDialog.SignedHashesMultiWalletDialog -> { - if (dialog == null) { - dialog = SignedHashesWarningDialog.create(context).apply { show() } - } - } - else -> { - dialog?.dismiss() - dialog = null - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt index d89a51f8c5..4fb9b0ca0b 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SingleWalletView.kt @@ -1,6 +1,5 @@ package com.tangem.tap.features.wallet.ui.wallet -import android.app.Dialog import android.view.View import android.view.ViewGroup import android.widget.Button @@ -10,23 +9,18 @@ import com.tangem.tap.common.extensions.beginDelayedTransition import com.tangem.tap.common.extensions.fitChipsByGroupWidth import com.tangem.tap.common.extensions.hide import com.tangem.tap.common.extensions.show -import com.tangem.tap.common.redux.StateDialog import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsState import com.tangem.tap.features.wallet.models.PendingTransaction import com.tangem.tap.features.wallet.redux.Currency import com.tangem.tap.features.wallet.redux.TradeCryptoState import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.features.wallet.redux.WalletData -import com.tangem.tap.features.wallet.redux.WalletDialog 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 import com.tangem.tap.features.wallet.ui.WalletFragment import com.tangem.tap.features.wallet.ui.adapters.PendingTransactionsAdapter -import com.tangem.tap.features.wallet.ui.dialogs.AmountToSendDialog -import com.tangem.tap.features.wallet.ui.dialogs.ChooseTradeActionDialog -import com.tangem.tap.features.wallet.ui.dialogs.SignedHashesWarningDialog import com.tangem.tap.store import com.tangem.wallet.R import com.tangem.wallet.databinding.FragmentWalletBinding @@ -36,7 +30,6 @@ class SingleWalletView : WalletView { private lateinit var pendingTransactionAdapter: PendingTransactionsAdapter private var fragment: WalletFragment? = null private var binding: FragmentWalletBinding? = null - private var dialog: Dialog? = null override fun setFragment(fragment: WalletFragment, binding: FragmentWalletBinding) { this.fragment = fragment @@ -85,7 +78,6 @@ class SingleWalletView : WalletView { setupAddressCard(state.primaryWallet, binding) showPendingTransactionsIfPresent(state.primaryWallet.pendingTransactions) setupBalance(state, state.primaryWallet) - handleDialogs(state.walletDialog, fragment) } private fun showPendingTransactionsIfPresent(pendingTransactions: List) { @@ -158,7 +150,14 @@ class SingleWalletView : WalletView { } } lAddress.btnShowQr.setOnClickListener { - store.dispatch(WalletAction.ShowDialog.QrCode) + state.walletAddresses?.selectedAddress?.let { selectedAddress -> + store.dispatch( + WalletAction.DialogAction.QrCode( + currency = state.currency, + selectedAddress = selectedAddress + ) + ) + } } setupTradeButton(binding, state.tradeCryptoState) @@ -170,7 +169,7 @@ class SingleWalletView : WalletView { val action = when { allowedToBuy && !allowedToSell -> WalletAction.TradeCryptoAction.Buy !allowedToBuy && allowedToSell -> WalletAction.TradeCryptoAction.Sell - allowedToBuy && allowedToSell -> WalletAction.ShowDialog.ChooseTradeActionDialog + allowedToBuy && allowedToSell -> WalletAction.DialogAction.ChooseTradeActionDialog else -> null } val text = when { @@ -262,28 +261,4 @@ class SingleWalletView : WalletView { binding.lAddress.root.hide() } } - - private fun handleDialogs(walletDialog: StateDialog?, fragment: WalletFragment) { - val context = fragment.context ?: return - when (walletDialog) { - is WalletDialog.SelectAmountToSendDialog -> { - if (dialog == null) dialog = AmountToSendDialog(context).apply { - this.show(walletDialog.amounts) - } - } - is WalletDialog.SignedHashesMultiWalletDialog -> { - if (dialog == null) { - dialog = SignedHashesWarningDialog.create(context).apply { show() } - } - } - is WalletDialog.ChooseTradeActionDialog -> { - if (dialog == null) dialog = ChooseTradeActionDialog(context).apply { show() } - } - null -> { - dialog?.dismiss() - dialog = null - } - } - } - } \ No newline at end of file From b2cb46f21a3605de78fdc29b786f9cd1fc3e9fc5 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 30 May 2022 15:32:04 +0300 Subject: [PATCH 8/8] 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), ) }