From e44dcb4e0b2573a8579d3f2cd476d49cbf20966a Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 7 Jun 2022 12:03:31 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../com/tangem/tap/common/DialogManager.kt | 31 +++--- .../tangem/tap/common/redux/StateDialog.kt | 2 +- .../tangem/tap/common/ui/SimpleAlertDialog.kt | 59 ++++++++++ .../com/tangem/tap/domain/RatesRepository.kt | 2 +- .../extensions/CurrencyExchangeManager.kt | 2 +- .../domain/extensions/WalletManagerFactory.kt | 2 +- .../tap/features/demo/DemoMiddlewares.kt | 2 +- .../walletconnect/WalletConnectMiddleware.kt | 2 +- .../features/details/ui/DetailsFragment.kt | 2 +- .../dialogs/SimpleAlertDialog.kt | 28 ----- .../AddressInfoBottomSheetDialog.kt | 2 +- .../features/onboarding/OnboardingManager.kt | 2 +- .../note/redux/OnboardingNoteMiddleware.kt | 2 +- .../twins/redux/TwinCardsMiddleware.kt | 2 +- .../features/tokens/redux/TokensMiddleware.kt | 7 +- .../tap/features/tokens/redux/TokensState.kt | 8 +- .../tap/features/wallet/models/Currency.kt | 97 +++++++++++++++++ .../tap/features/wallet/redux/WalletAction.kt | 4 +- .../tap/features/wallet/redux/WalletState.kt | 102 +----------------- .../middlewares/AppCurrencyMiddleware.kt | 2 +- .../middlewares/MultiWalletMiddleware.kt | 63 +++++++++-- .../middlewares/TradeCryptoMiddleware.kt | 2 +- .../middlewares/WalletDialogsMiddleware.kt | 2 +- .../redux/middlewares/WalletMiddleware.kt | 6 +- .../wallet/redux/models/WalletDialog.kt | 39 +++++++ .../redux/reducers/MultiWalletReducer.kt | 10 +- .../redux/reducers/OnWalletLoadedReducer.kt | 3 +- .../wallet/redux/reducers/WalletReducer.kt | 17 +-- .../wallet/ui/WalletDetailsFragment.kt | 57 ++++------ .../wallet/ui/adapters/WalletAdapter.kt | 2 +- .../dialogs/AmountToSendBottomSheetDialog.kt | 8 +- .../ui/wallet/CurrencySelectionDialog.kt | 2 +- .../wallet/ui/wallet/SingleWalletView.kt | 8 +- app/src/main/res/values-de/strings_final.xml | 8 ++ app/src/main/res/values-fr/strings_final.xml | 8 ++ app/src/main/res/values-it/strings_final.xml | 8 ++ app/src/main/res/values-ru/strings_final.xml | 9 ++ app/src/main/res/values/strings_final.xml | 9 ++ 38 files changed, 379 insertions(+), 242 deletions(-) create mode 100644 app/src/main/java/com/tangem/tap/common/ui/SimpleAlertDialog.kt delete mode 100644 app/src/main/java/com/tangem/tap/features/details/ui/walletconnect/dialogs/SimpleAlertDialog.kt create mode 100644 app/src/main/java/com/tangem/tap/features/wallet/models/Currency.kt create mode 100644 app/src/main/java/com/tangem/tap/features/wallet/redux/models/WalletDialog.kt 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 8af2818c0a..2895613815 100644 --- a/app/src/main/java/com/tangem/tap/common/DialogManager.kt +++ b/app/src/main/java/com/tangem/tap/common/DialogManager.kt @@ -4,13 +4,10 @@ import android.app.Dialog import android.content.Context import com.tangem.tap.common.redux.AppDialog import com.tangem.tap.common.redux.global.GlobalState +import com.tangem.tap.common.ui.SimpleAlertDialog +import com.tangem.tap.common.ui.SimpleCancelableAlertDialog import com.tangem.tap.features.details.redux.walletconnect.WalletConnectDialog -import com.tangem.tap.features.details.ui.walletconnect.dialogs.ApproveWcSessionDialog -import com.tangem.tap.features.details.ui.walletconnect.dialogs.BnbTransactionDialog -import com.tangem.tap.features.details.ui.walletconnect.dialogs.ClipboardOrScanQrDialog -import com.tangem.tap.features.details.ui.walletconnect.dialogs.PersonalSignDialog -import com.tangem.tap.features.details.ui.walletconnect.dialogs.SimpleAlertDialog -import com.tangem.tap.features.details.ui.walletconnect.dialogs.TransactionDialog +import com.tangem.tap.features.details.ui.walletconnect.dialogs.* import com.tangem.tap.features.onboarding.AddressInfoBottomSheetDialog import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsAction import com.tangem.tap.features.onboarding.products.twins.ui.dialog.CreateWalletInterruptDialog @@ -19,12 +16,8 @@ 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.redux.models.WalletDialog +import com.tangem.tap.features.wallet.ui.dialogs.* import com.tangem.tap.features.wallet.ui.wallet.CurrencySelectionDialog import com.tangem.tap.store import com.tangem.wallet.R @@ -115,6 +108,20 @@ class DialogManager : StoreSubscriber { AmountToSendBottomSheetDialog(context, state.dialog) is WalletDialog.SignedHashesMultiWalletDialog -> SignedHashesWarningDialog.create(context) + is WalletDialog.TokensAreLinkedDialog -> SimpleAlertDialog.create( + title = context.getString(state.dialog.titleRes, state.dialog.currencySymbol), + message = context.getString( + state.dialog.messageRes, state.dialog.currencySymbol, state.dialog.currencyTitle + ), + context = context, + ) + is WalletDialog.RemoveWalletDialog -> SimpleCancelableAlertDialog.create( + title = context.getString(state.dialog.titleRes, state.dialog.currencyTitle), + messageRes = state.dialog.messageRes, + context = context, + primaryButtonRes = state.dialog.primaryButtonRes, + primaryButtonAction = state.dialog.action + ) 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 591a20e896..89d609b32c 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,8 +2,8 @@ package com.tangem.tap.common.redux import com.tangem.common.extensions.VoidCallback import com.tangem.tap.common.TestAction +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.AddressData -import com.tangem.tap.features.wallet.redux.Currency /** [REDACTED_AUTHOR] diff --git a/app/src/main/java/com/tangem/tap/common/ui/SimpleAlertDialog.kt b/app/src/main/java/com/tangem/tap/common/ui/SimpleAlertDialog.kt new file mode 100644 index 0000000000..8cd6e7e5ba --- /dev/null +++ b/app/src/main/java/com/tangem/tap/common/ui/SimpleAlertDialog.kt @@ -0,0 +1,59 @@ +package com.tangem.tap.common.ui + +import android.content.Context +import androidx.appcompat.app.AlertDialog +import com.tangem.tap.common.redux.global.GlobalAction +import com.tangem.tap.store +import com.tangem.wallet.R + +class SimpleAlertDialog { + companion object { + fun create( + titleRes: Int? = null, + messageRes: Int? = null, + title: String? = null, + message: String? = null, + primaryButtonRes: Int = R.string.common_ok, + context: Context, + ): AlertDialog { + return SimpleCancelableAlertDialog.create( + titleRes = titleRes, + messageRes = messageRes, + title = title, + message = message, + primaryButtonRes = primaryButtonRes, + secondaryButtonRes = null, + context = context + ) + } + } +} + +class SimpleCancelableAlertDialog { + companion object { + fun create( + titleRes: Int? = null, + messageRes: Int? = null, + title: String? = null, + message: String? = null, + primaryButtonRes: Int = R.string.common_ok, + secondaryButtonRes: Int? = R.string.common_cancel, + primaryButtonAction: () -> Unit = {}, + secondaryButtonAction: () -> Unit = {}, + context: Context, + ): AlertDialog { + + return AlertDialog.Builder(context).apply { + setTitle(titleRes?.let { context.getString(it) } ?: title ) + setMessage(messageRes?.let { context.getString(it) } ?: message) + setPositiveButton(context.getText(primaryButtonRes)) { _, _ -> primaryButtonAction() } + if (secondaryButtonRes != null) { + setNegativeButton(context.getText(secondaryButtonRes)) { _, _ -> secondaryButtonAction()} + } + setOnDismissListener { + store.dispatch(GlobalAction.HideDialog) + } + }.create() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/domain/RatesRepository.kt b/app/src/main/java/com/tangem/tap/domain/RatesRepository.kt index 4c9cafbdee..51252c819c 100644 --- a/app/src/main/java/com/tangem/tap/domain/RatesRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/RatesRepository.kt @@ -3,7 +3,7 @@ package com.tangem.tap.domain import com.tangem.common.services.Result import com.tangem.domain.common.ThrottlerWithValues import com.tangem.network.api.tangemTech.TangemTechService -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.store import java.math.BigDecimal diff --git a/app/src/main/java/com/tangem/tap/domain/extensions/CurrencyExchangeManager.kt b/app/src/main/java/com/tangem/tap/domain/extensions/CurrencyExchangeManager.kt index d3f7730510..86288ba9aa 100644 --- a/app/src/main/java/com/tangem/tap/domain/extensions/CurrencyExchangeManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/extensions/CurrencyExchangeManager.kt @@ -1,7 +1,7 @@ package com.tangem.tap.domain.extensions import com.tangem.blockchain.common.Blockchain -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager import com.tangem.tap.network.exchangeServices.CurrencyExchangeStatus import com.tangem.tap.store diff --git a/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt b/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt index bff4c0c3b7..e636c4fa07 100644 --- a/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt +++ b/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt @@ -11,7 +11,7 @@ import com.tangem.domain.common.ScanResponse import com.tangem.domain.common.TapWorkarounds.isTestCard import com.tangem.domain.common.TapWorkarounds.useOldStyleDerivation import com.tangem.tap.domain.tokens.models.BlockchainNetwork -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency fun WalletManagerFactory.makeWalletManagerForApp( scanResponse: ScanResponse, diff --git a/app/src/main/java/com/tangem/tap/features/demo/DemoMiddlewares.kt b/app/src/main/java/com/tangem/tap/features/demo/DemoMiddlewares.kt index 92551d6411..87af003060 100644 --- a/app/src/main/java/com/tangem/tap/features/demo/DemoMiddlewares.kt +++ b/app/src/main/java/com/tangem/tap/features/demo/DemoMiddlewares.kt @@ -5,7 +5,7 @@ import com.tangem.domain.common.ScanResponse import com.tangem.domain.common.extensions.withMainContext import com.tangem.tap.domain.extensions.makePrimaryWalletManager import com.tangem.tap.features.onboarding.products.note.redux.OnboardingNoteAction -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.ProgressState import com.tangem.tap.scope import com.tangem.tap.store diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt index 8dbaafc988..2bdc6edf5f 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt @@ -21,7 +21,7 @@ import com.tangem.tap.domain.walletconnect.BnbHelper import com.tangem.tap.domain.walletconnect.WalletConnectManager import com.tangem.tap.domain.walletconnect.WalletConnectNetworkUtils import com.tangem.tap.features.demo.DemoHelper -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.scope import com.tangem.tap.store diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt index d4ad890b8b..8270345132 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt @@ -66,7 +66,7 @@ class DetailsFragment : Fragment(R.layout.fragment_details), StoreSubscriber } - setOnDismissListener { - store.dispatch(GlobalAction.HideDialog) - } - }.create() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/AddressInfoBottomSheetDialog.kt b/app/src/main/java/com/tangem/tap/features/onboarding/AddressInfoBottomSheetDialog.kt index e9f47acef9..50faf24376 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/AddressInfoBottomSheetDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/AddressInfoBottomSheetDialog.kt @@ -10,8 +10,8 @@ import com.tangem.tap.common.extensions.dispatchDialogHide import com.tangem.tap.common.extensions.dispatchShare import com.tangem.tap.common.extensions.dispatchToastNotification import com.tangem.tap.common.redux.AppDialog +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.AddressData -import com.tangem.tap.features.wallet.redux.Currency import com.tangem.tap.store import com.tangem.wallet.R import com.tangem.wallet.databinding.DialogOnboardingAddressInfoBinding diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingManager.kt b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingManager.kt index f0873595ff..26d719d0c6 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingManager.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingManager.kt @@ -12,8 +12,8 @@ import com.tangem.tap.common.extensions.isPositive import com.tangem.tap.common.extensions.safeUpdate import com.tangem.tap.domain.TapError import com.tangem.tap.domain.extensions.getOrLoadCardArtworkUrl +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.models.hasPendingTransactions -import com.tangem.tap.features.wallet.redux.Currency import com.tangem.tap.features.wallet.redux.ProgressState import com.tangem.tap.persistence.UsedCardsPrefStorage import timber.log.Timber diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteMiddleware.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteMiddleware.kt index 2c854ab5a0..34c0d381b2 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteMiddleware.kt @@ -15,7 +15,7 @@ import com.tangem.tap.domain.TapError import com.tangem.tap.domain.extensions.hasWallets import com.tangem.tap.domain.extensions.makePrimaryWalletManager import com.tangem.tap.features.demo.DemoHelper -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.ProgressState import com.tangem.tap.scope import com.tangem.tap.store diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsMiddleware.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsMiddleware.kt index 3ba1648a4b..e95d03c36e 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsMiddleware.kt @@ -16,7 +16,7 @@ import com.tangem.tap.common.redux.navigation.NavigationAction import com.tangem.tap.domain.TapError import com.tangem.tap.domain.extensions.makePrimaryWalletManager import com.tangem.tap.domain.twins.TwinCardsManager -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.ProgressState import com.tangem.tap.preferencesStorage import com.tangem.tap.scope diff --git a/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensMiddleware.kt b/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensMiddleware.kt index 48f848e65a..03ad95cbb0 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensMiddleware.kt @@ -30,7 +30,7 @@ import com.tangem.tap.domain.TapError import com.tangem.tap.domain.extensions.makeWalletManagerForApp import com.tangem.tap.domain.tokens.LoadAvailableCoinsService import com.tangem.tap.domain.tokens.models.BlockchainNetwork -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.WalletAction import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -303,7 +303,10 @@ class TokensMiddleware { if (currencies.isNotEmpty()) { currencies.forEach { currency -> store.state.walletState.getWalletData(currency)?.let { - store.dispatch(WalletAction.MultiWallet.RemoveWallet(it)) + store.dispatch(WalletAction.MultiWallet.RemoveWallet( + walletData = it, + fromWalletDetails = false + )) } } } diff --git a/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensState.kt b/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensState.kt index 1c60655d24..5fcc7510f2 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensState.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensState.kt @@ -34,18 +34,18 @@ data class TokensState( typealias ContractAddress = String fun List.toTokensContractAddresses(): List { - return mapNotNull { (it.currency as? com.tangem.tap.features.wallet.redux.Currency.Token)?.token?.contractAddress }.distinct() + return mapNotNull { (it.currency as? com.tangem.tap.features.wallet.models.Currency.Token)?.token?.contractAddress }.distinct() } fun List.toNonCustomTokens(derivationStyle: DerivationStyle?): List { return filter { !it.currency.isCustomCurrency(derivationStyle) } - .mapNotNull { (it.currency as? com.tangem.tap.features.wallet.redux.Currency.Token)?.token } + .mapNotNull { (it.currency as? com.tangem.tap.features.wallet.models.Currency.Token)?.token } .distinct() } fun List.toNonCustomTokensWithBlockchains(derivationStyle: DerivationStyle?): List { return mapNotNull { - if (it.currency !is com.tangem.tap.features.wallet.redux.Currency.Token) return@mapNotNull null + if (it.currency !is com.tangem.tap.features.wallet.models.Currency.Token) return@mapNotNull null if (it.currency.isCustomCurrency(derivationStyle)) return@mapNotNull null TokenWithBlockchain(it.currency.token, it.currency.blockchain) }.distinct() @@ -56,7 +56,7 @@ fun List.toNonCustomBlockchains(derivationStyle: DerivationStyle?): if (it.currency.isCustomCurrency(derivationStyle)) { null } else { - (it.currency as? com.tangem.tap.features.wallet.redux.Currency.Blockchain)?.blockchain + (it.currency as? com.tangem.tap.features.wallet.models.Currency.Blockchain)?.blockchain } }.distinct() } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/models/Currency.kt b/app/src/main/java/com/tangem/tap/features/wallet/models/Currency.kt new file mode 100644 index 0000000000..76945c588f --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/wallet/models/Currency.kt @@ -0,0 +1,97 @@ +package com.tangem.tap.features.wallet.models + +import com.tangem.blockchain.common.Blockchain +import com.tangem.blockchain.common.DerivationStyle +import com.tangem.blockchain.common.Token +import com.tangem.domain.common.extensions.toCoinId +import com.tangem.domain.features.addCustomToken.CustomCurrency +import com.tangem.tap.common.redux.global.CryptoCurrencyName +import com.tangem.tap.domain.tokens.models.BlockchainNetwork +import com.tangem.tap.features.tokens.redux.TokenWithBlockchain + +sealed interface Currency { + + val coinId: String? + get() = when (this) { + is Blockchain -> blockchain.toCoinId() + is Token -> token.id + } + val blockchain: com.tangem.blockchain.common.Blockchain + val currencySymbol: CryptoCurrencyName + val derivationPath: String? + + val currencyName: String + get() = when (this) { + is Blockchain -> blockchain.fullName + is Token -> token.name + } + + data class Token( + val token: com.tangem.blockchain.common.Token, + override val blockchain: com.tangem.blockchain.common.Blockchain, + override val derivationPath: String? + ) : Currency { + override val currencySymbol = token.symbol + } + + data class Blockchain( + override val blockchain: com.tangem.blockchain.common.Blockchain, + override val derivationPath: String? + ) : Currency { + override val currencySymbol: CryptoCurrencyName = blockchain.currency + } + + fun isCustomCurrency(derivationStyle: DerivationStyle?): Boolean { + if (this is Token && this.token.id == null) return true + + if (derivationPath == null || derivationStyle == null) return false + + return derivationPath != blockchain.derivationPath(derivationStyle)?.rawPath + } + + fun isBlockchain(): Boolean = this is Blockchain + + fun isToken(): Boolean = this is Token + + companion object { + fun fromBlockchainNetwork( + blockchainNetwork: BlockchainNetwork, + token: com.tangem.blockchain.common.Token? = null + ): Currency { + return if (token != null) { + Token( + token = token, + blockchain = blockchainNetwork.blockchain, + derivationPath = blockchainNetwork.derivationPath + ) + } else { + Blockchain( + blockchain = blockchainNetwork.blockchain, + derivationPath = blockchainNetwork.derivationPath + ) + } + } + + fun fromCustomCurrency(customCurrency: CustomCurrency): Currency { + return when (customCurrency) { + is CustomCurrency.CustomBlockchain -> Blockchain( + blockchain = customCurrency.network, + derivationPath = customCurrency.derivationPath?.rawPath + ) + is CustomCurrency.CustomToken -> Token( + token = customCurrency.token, + blockchain = customCurrency.network, + derivationPath = customCurrency.derivationPath?.rawPath, + ) + } + } + + fun fromTokenWithBlockchain(tokenWithBlockchain: TokenWithBlockchain): Token { + return Token( + token = tokenWithBlockchain.token, + blockchain = tokenWithBlockchain.blockchain, + derivationPath = null + ) + } + } +} \ No newline at end of file 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 6ca5098dd8..5d75dcfc48 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 @@ -10,6 +10,7 @@ import com.tangem.tap.common.redux.NotificationAction import com.tangem.tap.domain.TapError import com.tangem.tap.domain.configurable.warningMessage.WarningMessage import com.tangem.tap.domain.tokens.models.BlockchainNetwork +import com.tangem.tap.features.wallet.models.Currency import com.tangem.wallet.R import org.rekotlin.Action import java.math.BigDecimal @@ -69,7 +70,8 @@ sealed class WalletAction : Action { ) : MultiWallet() data class SelectWallet(val walletData: WalletData?) : MultiWallet() - data class RemoveWallet(val walletData: WalletData) : MultiWallet() + data class RemoveWallet(val walletData: WalletData, val fromWalletDetails: Boolean = true) : MultiWallet() + data class TryToRemoveWallet(val walletData: WalletData) : MultiWallet() data class SetPrimaryBlockchain(val blockchain: Blockchain) : MultiWallet() data class SetPrimaryToken(val token: Token) : MultiWallet() } 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 aecdd574e8..991a27a047 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,16 +1,15 @@ package com.tangem.tap.features.wallet.redux import android.graphics.Bitmap -import com.tangem.blockchain.common.* +import com.tangem.blockchain.common.Blockchain +import com.tangem.blockchain.common.Token +import com.tangem.blockchain.common.Wallet +import com.tangem.blockchain.common.WalletManager import com.tangem.blockchain.common.address.AddressType import com.tangem.common.extensions.isZero 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 import com.tangem.tap.common.toggleWidget.WidgetState import com.tangem.tap.domain.configurable.warningMessage.WarningMessage @@ -18,7 +17,6 @@ import com.tangem.tap.domain.extensions.buyIsAllowed import com.tangem.tap.domain.extensions.sellIsAllowed import com.tangem.tap.domain.tokens.models.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.* import com.tangem.tap.features.wallet.redux.reducers.calculateTotalFiatAmount import com.tangem.tap.features.wallet.redux.reducers.findTotalBalanceState @@ -211,6 +209,7 @@ data class WalletState( } fun removeWallet(walletData: WalletData?): WalletState { + if (walletData == null) return this if (walletData == null) return this return if (walletData.currency is Currency.Blockchain) { val walletStores = wallets.filterNot { @@ -285,16 +284,6 @@ data class WalletState( } } -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 } enum class ErrorType { NoInternetConnection } @@ -407,87 +396,6 @@ data class WalletData( private fun tokenAmountIsEmpty(): Boolean = currencyData.amount?.isZero() == true } -sealed interface Currency { - - val coinId: String? - get() = when (this) { - is Blockchain -> blockchain.toCoinId() - is Token -> token.id - } - val blockchain: com.tangem.blockchain.common.Blockchain - val currencySymbol: CryptoCurrencyName - val derivationPath: String? - - data class Token( - val token: com.tangem.blockchain.common.Token, - override val blockchain: com.tangem.blockchain.common.Blockchain, - override val derivationPath: String? - ) : Currency { - override val currencySymbol = token.symbol - } - - data class Blockchain( - override val blockchain: com.tangem.blockchain.common.Blockchain, - override val derivationPath: String? - ) : Currency { - override val currencySymbol: CryptoCurrencyName = blockchain.currency - } - - fun isCustomCurrency(derivationStyle: DerivationStyle?): Boolean { - if (this is Token && this.token.id == null) return true - - if (derivationPath == null || derivationStyle == null) return false - - return derivationPath != blockchain.derivationPath(derivationStyle)?.rawPath - } - - fun isBlockchain(): Boolean = this is Blockchain - - fun isToken(): Boolean = this is Token - - companion object { - fun fromBlockchainNetwork( - blockchainNetwork: BlockchainNetwork, - token: com.tangem.blockchain.common.Token? = null - ): Currency { - return if (token != null) { - Token( - token = token, - blockchain = blockchainNetwork.blockchain, - derivationPath = blockchainNetwork.derivationPath - ) - } else { - Blockchain( - blockchain = blockchainNetwork.blockchain, - derivationPath = blockchainNetwork.derivationPath - ) - } - } - - fun fromCustomCurrency(customCurrency: CustomCurrency): Currency { - return when (customCurrency) { - is CustomCurrency.CustomBlockchain -> Blockchain( - blockchain = customCurrency.network, - derivationPath = customCurrency.derivationPath?.rawPath - ) - is CustomCurrency.CustomToken -> Token( - token = customCurrency.token, - blockchain = customCurrency.network, - derivationPath = customCurrency.derivationPath?.rawPath, - ) - } - } - - fun fromTokenWithBlockchain(tokenWithBlockchain: TokenWithBlockchain): Token { - return Token( - token = tokenWithBlockchain.token, - blockchain = tokenWithBlockchain.blockchain, - derivationPath = null - ) - } - } -} - data class WalletStore( val walletManager: WalletManager?, val blockchainNetwork: BlockchainNetwork, 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 904aecab65..2aa438dc24 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 @@ -8,7 +8,7 @@ import com.tangem.tap.common.extensions.dispatchDialogShow 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.features.wallet.redux.models.WalletDialog import com.tangem.tap.persistence.FiatCurrenciesPrefStorage import com.tangem.tap.scope import com.tangem.tap.store diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/MultiWalletMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/MultiWalletMiddleware.kt index ace70c1988..97a35f59c2 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/MultiWalletMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/MultiWalletMiddleware.kt @@ -3,6 +3,8 @@ package com.tangem.tap.features.wallet.redux.middlewares import com.tangem.blockchain.common.AmountType import com.tangem.blockchain.common.Token import com.tangem.blockchain.common.WalletManager +import com.tangem.common.extensions.guard +import com.tangem.tap.common.extensions.dispatchDialogShow import com.tangem.tap.common.extensions.safeUpdate import com.tangem.tap.common.redux.global.GlobalState import com.tangem.tap.common.redux.navigation.AppScreen @@ -12,9 +14,10 @@ import com.tangem.tap.domain.extensions.makeWalletManagerForApp import com.tangem.tap.domain.tokens.models.BlockchainNetwork import com.tangem.tap.features.demo.DemoHelper import com.tangem.tap.features.demo.isDemoCard -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.features.wallet.redux.WalletState +import com.tangem.tap.features.wallet.redux.models.WalletDialog import com.tangem.tap.scope import com.tangem.tap.store import kotlinx.coroutines.Dispatchers @@ -55,23 +58,55 @@ class MultiWalletMiddleware { blockchainNetwork = action.blockchain ) } - store.dispatch(WalletAction.LoadFiatRate( - coinsList = listOf( - Currency.Blockchain( - action.blockchain.blockchain, - action.blockchain.derivationPath + store.dispatch( + WalletAction.LoadFiatRate( + coinsList = listOf( + Currency.Blockchain( + action.blockchain.blockchain, + action.blockchain.derivationPath + ) ) ) - )) - store.dispatch(WalletAction.LoadWallet( - action.blockchain, action.walletManager - )) + ) + store.dispatch( + WalletAction.LoadWallet( + action.blockchain, action.walletManager + ) + ) } is WalletAction.MultiWallet.SaveCurrencies -> { globalState.scanResponse?.card?.cardId?.let { currenciesRepository.saveCurrencies(it, action.blockchainNetworks) } } + is WalletAction.MultiWallet.TryToRemoveWallet -> { + val walletState = store.state.walletState + val currency = action.walletData.currency + val walletCanBeRemoved = store.state.walletState.canBeRemoved( + store.state.walletState.getSelectedWalletData() + ) + if (walletCanBeRemoved) { + store.dispatch(WalletAction.MultiWallet.RemoveWallet(action.walletData)) + return + } + + val walletManager = walletState.getWalletManager(currency).guard { + store.dispatch(WalletAction.MultiWallet.RemoveWallet(action.walletData)) + return + } + + val dialog = when { + currency is Currency.Blockchain && + walletManager.cardTokens.isNotEmpty() -> + WalletDialog.TokensAreLinkedDialog( + currency.currencyName, currency.currencySymbol + ) + + else -> + WalletDialog.RemoveWalletDialog(currency.currencyName, action.walletData) + } + store.dispatchDialogShow(dialog) + } is WalletAction.MultiWallet.RemoveWallet -> { val cardId = globalState.scanResponse?.card?.cardId when (val currency = action.walletData.currency) { @@ -94,12 +129,18 @@ class MultiWalletMiddleware { currenciesRepository.removeToken( cardId = it, token = currency.token, - blockchainNetwork = BlockchainNetwork.fromWalletManager(walletManager) + blockchainNetwork = BlockchainNetwork.fromWalletManager( + walletManager + ) ) } } } } + if (action.fromWalletDetails) { + store.dispatch(WalletAction.MultiWallet.SelectWallet(null)) + store.dispatch(NavigationAction.PopBackTo()) + } } // is WalletAction.MultiWallet.FindBlockchainsInUse -> { // val scanResponse = globalState.scanResponse ?: return 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 3e4210fe42..9590452975 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 @@ -10,7 +10,7 @@ import com.tangem.tap.common.redux.navigation.NavigationAction import com.tangem.tap.features.demo.DemoHelper import com.tangem.tap.features.send.redux.PrepareSendScreen import com.tangem.tap.features.send.redux.SendAction -import com.tangem.tap.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager import com.tangem.tap.network.exchangeServices.buyErc20Tokens 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 index e495c55c94..9ae3127317 100644 --- 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 @@ -4,7 +4,7 @@ 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.features.wallet.redux.models.WalletDialog import com.tangem.tap.store class WalletDialogsMiddleware { 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 a4862b21b8..c0993defc4 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 @@ -25,10 +25,14 @@ import com.tangem.tap.domain.loadedRates import com.tangem.tap.features.demo.DemoHelper import com.tangem.tap.features.home.redux.HomeAction import com.tangem.tap.features.send.redux.PrepareSendScreen +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.models.PendingTransactionType import com.tangem.tap.features.wallet.models.getPendingTransactions import com.tangem.tap.features.wallet.models.getSendableAmounts -import com.tangem.tap.features.wallet.redux.* +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.network.NetworkStateChanged import com.tangem.tap.preferencesStorage import com.tangem.tap.scope diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/models/WalletDialog.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/models/WalletDialog.kt new file mode 100644 index 0000000000..5e2458c15d --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/models/WalletDialog.kt @@ -0,0 +1,39 @@ +package com.tangem.tap.features.wallet.redux.models + +import com.tangem.blockchain.common.Amount +import com.tangem.tap.common.entities.FiatCurrency +import com.tangem.tap.common.redux.StateDialog +import com.tangem.tap.features.wallet.redux.WalletAction +import com.tangem.tap.features.wallet.redux.WalletData +import com.tangem.tap.store +import com.tangem.wallet.R + +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 + + data class RemoveWalletDialog( + val currencyTitle: String, + private val walletData: WalletData + ): WalletDialog { + val messageRes: Int = R.string.token_details_hide_alert_message + val titleRes: Int = R.string.token_details_hide_alert_title + val primaryButtonRes: Int = R.string.token_details_hide_alert_hide + val action = { store.dispatch(WalletAction.MultiWallet.RemoveWallet(walletData)) } + } + + data class TokensAreLinkedDialog( + val currencyTitle: String, + val currencySymbol: String + ): WalletDialog { + val messageRes: Int = R.string.token_details_unable_hide_alert_message + val titleRes: Int = R.string.token_details_unable_hide_alert_title + } + + +} \ No newline at end of file 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 28a7675472..bcaca36f3c 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,16 +8,11 @@ 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.models.BlockchainNetwork +import com.tangem.tap.features.wallet.models.Currency 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.Currency -import com.tangem.tap.features.wallet.redux.WalletAction -import com.tangem.tap.features.wallet.redux.WalletData -import com.tangem.tap.features.wallet.redux.WalletMainButton -import com.tangem.tap.features.wallet.redux.WalletState -import com.tangem.tap.features.wallet.redux.WalletStore +import com.tangem.tap.features.wallet.redux.* import com.tangem.tap.features.wallet.ui.BalanceStatus import com.tangem.tap.features.wallet.ui.BalanceWidgetData import com.tangem.tap.features.wallet.ui.TokenData @@ -163,6 +158,7 @@ class MultiWalletReducer { // is WalletAction.MultiWallet.FindTokensInUse -> state // is WalletAction.MultiWallet.FindBlockchainsInUse -> state is WalletAction.MultiWallet.SaveCurrencies -> state + is WalletAction.MultiWallet.TryToRemoveWallet -> state } } } 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 442cbf46ec..b8be48e6cf 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,11 +9,10 @@ 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.models.BlockchainNetwork +import com.tangem.tap.features.wallet.models.Currency 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.Currency import com.tangem.tap.features.wallet.redux.ProgressState import com.tangem.tap.features.wallet.redux.TradeCryptoState import com.tangem.tap.features.wallet.redux.WalletMainButton 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 11ea7236c0..baad6ad45e 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 @@ -15,25 +15,14 @@ import com.tangem.tap.domain.TapError import com.tangem.tap.domain.extensions.getArtworkUrl import com.tangem.tap.domain.getFirstToken import com.tangem.tap.domain.tokens.models.BlockchainNetwork +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.models.WalletRent -import com.tangem.tap.features.wallet.redux.AddressData -import com.tangem.tap.features.wallet.redux.Artwork -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.TradeCryptoState -import com.tangem.tap.features.wallet.redux.WalletAction -import com.tangem.tap.features.wallet.redux.WalletAddresses -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.redux.WalletStore +import com.tangem.tap.features.wallet.redux.* import com.tangem.tap.features.wallet.ui.BalanceStatus import com.tangem.tap.features.wallet.ui.BalanceWidgetData import com.tangem.tap.store -import java.math.BigDecimal import org.rekotlin.Action +import java.math.BigDecimal class WalletReducer { companion object { 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 77ed03ebfa..a01e075a8b 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,11 +1,7 @@ package com.tangem.tap.features.wallet.ui import android.os.Bundle -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem -import android.view.View -import android.view.ViewGroup +import android.view.* import android.widget.TextView import androidx.activity.OnBackPressedCallback import androidx.annotation.ColorRes @@ -18,26 +14,14 @@ 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.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.extensions.* import com.tangem.tap.common.recyclerView.SpaceItemDecoration import com.tangem.tap.common.redux.navigation.NavigationAction import com.tangem.tap.domain.tokens.models.BlockchainNetwork import com.tangem.tap.features.onboarding.getQRReceiveMessage +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.models.PendingTransaction -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.redux.* 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.test.TestWalletDetails @@ -146,13 +130,15 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), binding.srlWalletDetails.setOnRefreshListener { if (selectedWallet.currencyData.status != BalanceStatus.Loading) { - store.dispatch(WalletAction.LoadWallet( - blockchain = BlockchainNetwork( - selectedWallet.currency.blockchain, - selectedWallet.currency.derivationPath, - emptyList() + store.dispatch( + WalletAction.LoadWallet( + blockchain = BlockchainNetwork( + selectedWallet.currency.blockchain, + selectedWallet.currency.derivationPath, + emptyList() + ) ) - )) + ) } } @@ -295,7 +281,10 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), lBalance.root.show() lBalance.groupBalance.hide() lBalance.tvError.show() - lBalance.tvError.setWarningStatus(R.string.wallet_balance_blockchain_unreachable, data.errorMessage) + lBalance.tvError.setWarningStatus( + R.string.wallet_balance_blockchain_unreachable, + data.errorMessage + ) } BalanceStatus.NoAccount -> { lBalance.root.hide() @@ -314,9 +303,7 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), return when (item.itemId) { R.id.menu_remove -> { store.state.walletState.getSelectedWalletData()?.let { walletData -> - store.dispatch(WalletAction.MultiWallet.RemoveWallet(walletData)) - store.dispatch(WalletAction.MultiWallet.SelectWallet(null)) - store.dispatch(NavigationAction.PopBackTo()) + store.dispatch(WalletAction.MultiWallet.TryToRemoveWallet(walletData)) true } false @@ -327,10 +314,6 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.wallet_details, menu) - val walletCanBeRemoved = store.state.walletState.canBeRemoved( - store.state.walletState.getSelectedWalletData() - ) - menu.getItem(0).isEnabled = walletCanBeRemoved } private fun TextView.setWarningStatus(mainMessage: Int, error: String? = null) { @@ -346,7 +329,11 @@ class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), setStatus(getString(mainMessage), R.color.darkGray4, null) } - private fun TextView.setStatus(text: String, @ColorRes color: Int, @DrawableRes drawable: Int?) { + private fun TextView.setStatus( + text: String, + @ColorRes color: Int, + @DrawableRes drawable: Int? + ) { this.text = text setTextColor(getColor(color)) setCompoundDrawablesWithIntrinsicBounds(drawable ?: 0, 0, 0, 0) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt index 6230fd27a3..a883fbc62f 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt @@ -14,7 +14,7 @@ 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.features.wallet.redux.Currency +import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.features.wallet.redux.WalletData import com.tangem.tap.features.wallet.ui.BalanceStatus diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendBottomSheetDialog.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendBottomSheetDialog.kt index 2f9e597096..ff82942f2b 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendBottomSheetDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/dialogs/AmountToSendBottomSheetDialog.kt @@ -5,16 +5,12 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.view.ContextThemeWrapper -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 androidx.recyclerview.widget.* 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.features.wallet.redux.models.WalletDialog import com.tangem.tap.store import com.tangem.wallet.R import com.tangem.wallet.databinding.DialogWalletSendBinding 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 78b665cde6..4e80ebb489 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 @@ -4,7 +4,7 @@ import android.content.Context import androidx.appcompat.app.AlertDialog import com.tangem.tap.common.extensions.dispatchDialogHide import com.tangem.tap.features.wallet.redux.WalletAction -import com.tangem.tap.features.wallet.redux.WalletDialog +import com.tangem.tap.features.wallet.redux.models.WalletDialog import com.tangem.tap.store import com.tangem.wallet.R 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 4fb9b0ca0b..7ea7acf213 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 @@ -10,13 +10,9 @@ 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.features.onboarding.products.twins.redux.TwinCardsState +import com.tangem.tap.features.wallet.models.Currency 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.WalletMainButton -import com.tangem.tap.features.wallet.redux.WalletState +import com.tangem.tap.features.wallet.redux.* import com.tangem.tap.features.wallet.ui.BalanceWidget import com.tangem.tap.features.wallet.ui.MultipleAddressUiHelper import com.tangem.tap.features.wallet.ui.WalletFragment diff --git a/app/src/main/res/values-de/strings_final.xml b/app/src/main/res/values-de/strings_final.xml index de09eb54fd..d2c6336c24 100644 --- a/app/src/main/res/values-de/strings_final.xml +++ b/app/src/main/res/values-de/strings_final.xml @@ -45,5 +45,13 @@ If you chose the wrong network during your crypto transfer from the exchange, this guide will help you recover your funds Custom + Notice + Attention + + Hide %s + Hide + You hide the token from the main screen, but you can add it back at any time. + Unable to hide %s + The %s token is the main currency on the %s network and cannot be hidden as long as you have other tokens on this network in the list. \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings_final.xml b/app/src/main/res/values-fr/strings_final.xml index de09eb54fd..d2c6336c24 100644 --- a/app/src/main/res/values-fr/strings_final.xml +++ b/app/src/main/res/values-fr/strings_final.xml @@ -45,5 +45,13 @@ If you chose the wrong network during your crypto transfer from the exchange, this guide will help you recover your funds Custom + Notice + Attention + + Hide %s + Hide + You hide the token from the main screen, but you can add it back at any time. + Unable to hide %s + The %s token is the main currency on the %s network and cannot be hidden as long as you have other tokens on this network in the list. \ No newline at end of file diff --git a/app/src/main/res/values-it/strings_final.xml b/app/src/main/res/values-it/strings_final.xml index de09eb54fd..d2c6336c24 100644 --- a/app/src/main/res/values-it/strings_final.xml +++ b/app/src/main/res/values-it/strings_final.xml @@ -45,5 +45,13 @@ If you chose the wrong network during your crypto transfer from the exchange, this guide will help you recover your funds Custom + Notice + Attention + + Hide %s + Hide + You hide the token from the main screen, but you can add it back at any time. + Unable to hide %s + The %s token is the main currency on the %s network and cannot be hidden as long as you have other tokens on this network in the list. \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings_final.xml b/app/src/main/res/values-ru/strings_final.xml index ea424b57b6..569ce107b5 100644 --- a/app/src/main/res/values-ru/strings_final.xml +++ b/app/src/main/res/values-ru/strings_final.xml @@ -45,9 +45,18 @@ Если вы совершили ошибку с выбором сети при переводе средств с биржи, эта инструкция поможет вам восстановить средства Пользовательский + Уведомление + Внимание Баланс Обработка полной суммы… Управление токенами Нет цены + + Скрыть %s + Скрыть + Вы скрываете токен с главного экрана, но в любой момент сможете добавить его обратно. + Невозможно скрыть %s + Токен %s является основной валютой в сети %s и не может быть скрыт, до тех пор пока у вас в списке есть другие токены этой сети. + diff --git a/app/src/main/res/values/strings_final.xml b/app/src/main/res/values/strings_final.xml index 2478dee488..ef91b7dcc3 100644 --- a/app/src/main/res/values/strings_final.xml +++ b/app/src/main/res/values/strings_final.xml @@ -45,9 +45,18 @@ If you chose the wrong network during your crypto transfer from the exchange, this guide will help you recover your funds Custom + Notice + Attention Total balance Some networks are unreachable Manage tokens No rate + + Hide %s + Hide + You hide the token from the main screen, but you can add it back at any time. + Unable to hide %s + The %s token is the main currency on the %s network and cannot be hidden as long as you have other tokens on this network in the list. +