diff --git a/app/src/main/java/com/tangem/tap/common/analytics/topup/TopUpController.kt b/app/src/main/java/com/tangem/tap/common/analytics/topup/TopUpController.kt index 42d9e80686..2435646fed 100644 --- a/app/src/main/java/com/tangem/tap/common/analytics/topup/TopUpController.kt +++ b/app/src/main/java/com/tangem/tap/common/analytics/topup/TopUpController.kt @@ -9,6 +9,7 @@ import com.tangem.domain.common.util.UserWalletId import com.tangem.tap.common.analytics.converters.TopUpEventConverter import com.tangem.tap.common.analytics.events.AnalyticsParam import com.tangem.tap.common.extensions.copy +import com.tangem.tap.domain.model.TotalFiatBalance import com.tangem.tap.domain.model.UserWallet import com.tangem.tap.domain.model.WalletDataModel import com.tangem.tap.domain.model.WalletStoreModel @@ -17,7 +18,6 @@ import com.tangem.tap.domain.tokens.models.BlockchainNetwork import com.tangem.tap.domain.walletCurrencies.WalletCurrenciesManager import com.tangem.tap.domain.walletStores.WalletStoresManager import com.tangem.tap.features.wallet.models.Currency -import com.tangem.tap.features.wallet.redux.ProgressState import com.tangem.tap.persistence.ToppedUpWalletStorage import com.tangem.tap.scope import kotlinx.coroutines.launch @@ -60,8 +60,8 @@ class TopUpController( hadMissedDerivations = blockchains.isNotEmpty() } - fun totalBalanceStateChanged(state: ProgressState) { - if (state == ProgressState.Done) tryToSend() + fun totalBalanceStateChanged(totalFiatBalance: TotalFiatBalance) { + if (totalFiatBalance is TotalFiatBalance.Loaded) tryToSend() } fun loadDataSuccess() { diff --git a/app/src/main/java/com/tangem/tap/common/extensions/WalletManager.kt b/app/src/main/java/com/tangem/tap/common/extensions/WalletManager.kt index 0930704d50..925cb0c728 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/WalletManager.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/WalletManager.kt @@ -12,9 +12,8 @@ import com.tangem.tap.common.TestActions import com.tangem.tap.domain.TapError import com.tangem.tap.domain.extensions.amountToCreateAccount import com.tangem.tap.domain.getFirstToken +import com.tangem.tap.domain.model.WalletDataModel import com.tangem.tap.features.demo.isDemoCard -import com.tangem.tap.features.wallet.models.Currency -import com.tangem.tap.features.wallet.redux.AddressData import com.tangem.tap.features.wallet.redux.reducers.createAddressesData import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager import com.tangem.tap.proxy.redux.DaggerGraphState @@ -81,7 +80,7 @@ fun WalletManager.getTopUpUrl(): String? { ) } -fun WalletManager?.getAddressData(): AddressData? { +fun WalletManager?.getAddressData(): WalletDataModel.AddressData? { val wallet = this?.wallet ?: return null val addressDataList = wallet.createAddressesData() @@ -100,11 +99,6 @@ fun WalletManager.Companion.stub(): T { } as T } -fun Wallet.getTxHistory(currency: Currency): List { - return (currency as? Currency.Token)?.let { this.getTokenTxHistory(it.token) } - ?: getBlockchainTxHistory() -} - fun Wallet.getBlockchainTxHistory(): List { return historyTransactions.filter { it.contractAddress.isNullOrEmpty() 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 e216493dd6..ab957b81b1 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.domain.model.WalletDataModel import com.tangem.tap.features.wallet.models.Currency -import com.tangem.tap.features.wallet.redux.AddressData /** [REDACTED_AUTHOR] @@ -24,7 +24,7 @@ sealed class AppDialog : StateDialog { data class AddressInfoDialog( val currency: Currency, - val addressData: AddressData, + val addressData: WalletDataModel.AddressData, ) : AppDialog() data class TestActionsDialog( diff --git a/app/src/main/java/com/tangem/tap/domain/model/builders/WalletStoreBuilder.kt b/app/src/main/java/com/tangem/tap/domain/model/builders/WalletStoreBuilder.kt index ebc45e991e..65405fa242 100644 --- a/app/src/main/java/com/tangem/tap/domain/model/builders/WalletStoreBuilder.kt +++ b/app/src/main/java/com/tangem/tap/domain/model/builders/WalletStoreBuilder.kt @@ -184,10 +184,6 @@ private fun getExistentialDeposit(walletManager: WalletManager?): BigDecimal? { private fun Wallet.getWalletAddresses(): WalletDataModel.WalletAddresses? { return this.createAddressesData() .takeIf { it.isNotEmpty() } - ?.map { - // TODO: Will be removed in next MR - with(it) { WalletDataModel.AddressData(address, type, shareUrl, exploreUrl) } - } ?.let { addresses -> WalletDataModel.WalletAddresses( list = addresses, 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 66e30fe595..280ca66499 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 @@ -12,8 +12,9 @@ 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.extensions.getString +import com.tangem.tap.common.extensions.toQrCode import com.tangem.tap.common.redux.AppDialog -import com.tangem.tap.features.wallet.redux.AddressData +import com.tangem.tap.domain.model.WalletDataModel import com.tangem.tap.store import com.tangem.wallet.R import com.tangem.wallet.databinding.DialogOnboardingAddressInfoBinding @@ -46,12 +47,12 @@ class AddressInfoBottomSheetDialog( showData(data = stateDialog.addressData) } - private fun showData(data: AddressData) = with(binding!!) { + private fun showData(data: WalletDataModel.AddressData) = with(binding!!) { pseudoToolbar.imvClose.setOnClickListener { dismissWithAnimation = true cancel() } - imvQrCode.setImageBitmap(data.qrCode) + imvQrCode.setImageBitmap(data.shareUrl.toQrCode()) tvAddress.text = data.address btnFlCopyAddress.setOnClickListener { Analytics.send(Token.Receive.ButtonCopyAddress()) diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/ReceiptReducer.kt b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/ReceiptReducer.kt index 3f403ea92c..ebfa2a391a 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/ReceiptReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/ReceiptReducer.kt @@ -17,8 +17,8 @@ import com.tangem.tap.features.send.redux.states.ReceiptSymbols import com.tangem.tap.features.send.redux.states.ReceiptTokenCrypto import com.tangem.tap.features.send.redux.states.ReceiptTokenFiat import com.tangem.tap.features.send.redux.states.SendState -import com.tangem.tap.features.wallet.redux.WalletState.Companion.CAN_BE_LOWER_SIGN -import com.tangem.tap.features.wallet.redux.WalletState.Companion.UNKNOWN_AMOUNT_SIGN +import com.tangem.tap.features.wallet.redux.utils.CAN_BE_LOWER_SIGN +import com.tangem.tap.features.wallet.redux.utils.UNKNOWN_AMOUNT_SIGN import com.tangem.tap.store import java.math.BigDecimal diff --git a/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt b/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt index e250ad075e..6e2bf1f5e9 100644 --- a/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt +++ b/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt @@ -38,8 +38,8 @@ import com.tangem.tap.features.send.ui.dialogs.RequestFeeErrorDialog import com.tangem.tap.features.send.ui.dialogs.SendTransactionFailsDialog import com.tangem.tap.features.send.ui.dialogs.TezosWarningDialog import com.tangem.tap.features.wallet.redux.ProgressState -import com.tangem.tap.features.wallet.redux.WalletState.Companion.ROUGH_SIGN -import com.tangem.tap.features.wallet.redux.WalletState.Companion.UNKNOWN_AMOUNT_SIGN +import com.tangem.tap.features.wallet.redux.utils.ROUGH_SIGN +import com.tangem.tap.features.wallet.redux.utils.UNKNOWN_AMOUNT_SIGN import com.tangem.tap.features.wallet.ui.adapters.WarningMessagesAdapter import com.tangem.wallet.R diff --git a/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensAction.kt b/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensAction.kt index 78cfc5ac9e..0c87bc313a 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensAction.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensAction.kt @@ -3,8 +3,8 @@ package com.tangem.tap.features.tokens.redux import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.DerivationStyle import com.tangem.domain.common.ScanResponse +import com.tangem.tap.domain.model.WalletDataModel import com.tangem.tap.domain.tokens.Currency -import com.tangem.tap.features.wallet.redux.WalletData import org.rekotlin.Action sealed class TokensAction : Action { @@ -23,7 +23,7 @@ sealed class TokensAction : Action { ) : TokensAction() data class SetAddedCurrencies( - val wallets: List, + val wallets: List, val derivationStyle: DerivationStyle?, ) : TokensAction() 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 3cb59514c8..8015b9d1d5 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 @@ -6,13 +6,13 @@ import com.tangem.blockchain.common.Token import com.tangem.domain.common.ScanResponse import com.tangem.domain.common.extensions.canHandleToken import com.tangem.domain.common.extensions.fromNetworkId +import com.tangem.tap.domain.model.WalletDataModel import com.tangem.tap.domain.tokens.Currency -import com.tangem.tap.features.wallet.redux.WalletData import org.rekotlin.StateType import com.tangem.tap.features.wallet.models.Currency.Token as CurrencyToken data class TokensState( - val addedWallets: List = emptyList(), + val addedWallets: List = emptyList(), val addedTokens: List = emptyList(), val addedBlockchains: List = emptyList(), val currencies: List = emptyList(), @@ -31,17 +31,9 @@ data class TokensState( typealias ContractAddress = String -fun List.toTokensContractAddresses(): List { - return mapNotNull { (it.currency as? CurrencyToken)?.token?.contractAddress }.distinct() -} - -fun List.toNonCustomTokens(derivationStyle: DerivationStyle?): List { - return filter { !it.currency.isCustomCurrency(derivationStyle) } - .mapNotNull { (it.currency as? CurrencyToken)?.token } - .distinct() -} - -fun List.toNonCustomTokensWithBlockchains(derivationStyle: DerivationStyle?): List { +fun List.toNonCustomTokensWithBlockchains( + derivationStyle: DerivationStyle?, +): List { return mapNotNull { if (it.currency !is CurrencyToken) return@mapNotNull null if (it.currency.isCustomCurrency(derivationStyle)) return@mapNotNull null @@ -49,7 +41,7 @@ fun List.toNonCustomTokensWithBlockchains(derivationStyle: Derivatio }.distinct() } -fun List.toNonCustomBlockchains(derivationStyle: DerivationStyle?): List { +fun List.toNonCustomBlockchains(derivationStyle: DerivationStyle?): List { return mapNotNull { if (it.currency.isCustomCurrency(derivationStyle)) { null diff --git a/app/src/main/java/com/tangem/tap/features/wallet/models/WalletWarning.kt b/app/src/main/java/com/tangem/tap/features/wallet/models/WalletWarning.kt index 951d4f1e10..421bfa85fe 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/models/WalletWarning.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/models/WalletWarning.kt @@ -1,5 +1,7 @@ package com.tangem.tap.features.wallet.models +import com.tangem.tap.domain.model.WalletStoreModel + sealed class WalletWarning(val showingPosition: Int) { data class ExistentialDeposit( @@ -15,7 +17,7 @@ sealed class WalletWarning(val showingPosition: Int) { val blockchainSymbol: String, ) : WalletWarning(showingPosition = 30) - data class Rent(val walletRent: WalletRent) : WalletWarning(showingPosition = 40) + data class Rent(val walletRent: WalletStoreModel.WalletRent) : WalletWarning(showingPosition = 40) } data class WalletWarningDescription(val title: String, val message: String) 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 390b337f30..c026cc9e0f 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 @@ -8,11 +8,12 @@ import com.tangem.tap.common.entities.FiatCurrency 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.model.TotalFiatBalance import com.tangem.tap.domain.model.UserWallet +import com.tangem.tap.domain.model.WalletDataModel import com.tangem.tap.domain.model.WalletStoreModel import com.tangem.tap.domain.tokens.models.BlockchainNetwork import com.tangem.tap.features.wallet.models.Currency -import com.tangem.tap.features.wallet.models.TotalBalance import com.tangem.tap.features.wallet.redux.models.WalletDialog import com.tangem.wallet.R import org.rekotlin.Action @@ -38,7 +39,6 @@ sealed class WalletAction : Action { data class RemoveWallet(val currency: Currency) : MultiWallet() object BackupWallet : MultiWallet() - object ScheduleCheckForMissingDerivation : MultiWallet() data class AddMissingDerivations(val blockchains: List) : MultiWallet() object ScanToGetDerivations : MultiWallet() } @@ -78,7 +78,7 @@ sealed class WalletAction : Action { sealed class DialogAction : WalletAction() { data class QrCode( val currency: Currency, - val selectedAddress: AddressData, + val selectedAddress: WalletDataModel.AddressData, ) : DialogAction() object SignedHashesMultiWalletDialog : DialogAction() @@ -127,9 +127,7 @@ sealed class WalletAction : Action { } data class UserWalletChanged(val userWallet: UserWallet) : WalletAction() - data class WalletStoresChanged(val walletStores: List) : WalletAction() { - data class UpdateWalletStores(val reduxWalletStores: List) : WalletAction() - } + data class WalletStoresChanged(val walletStores: List) : WalletAction() - data class TotalFiatBalanceChanged(val balance: TotalBalance) : WalletAction() + data class TotalFiatBalanceChanged(val balance: TotalFiatBalance) : WalletAction() } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletData.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletData.kt index e4e5f8e78c..423306eec6 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletData.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/WalletData.kt @@ -85,7 +85,8 @@ data class WalletData( walletWarnings.add(WalletWarning.TransactionInProgress(currency.currencyName)) } if (walletRent != null) { - walletWarnings.add(WalletWarning.Rent(walletRent)) + // TODO: Will be removed in next MR + // walletWarnings.add(WalletWarning.Rent(walletRent)) } } 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 b55d54277d..6d4a5c788a 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 @@ -9,29 +9,30 @@ import com.tangem.tap.common.extensions.toQrCode import com.tangem.tap.common.redux.global.CryptoCurrencyName import com.tangem.tap.common.toggleWidget.WidgetState import com.tangem.tap.domain.configurable.warningMessage.WarningMessage +import com.tangem.tap.domain.model.TotalFiatBalance +import com.tangem.tap.domain.model.UserWallet +import com.tangem.tap.domain.model.WalletDataModel +import com.tangem.tap.domain.model.WalletStoreModel import com.tangem.tap.domain.tokens.models.BlockchainNetwork 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.TotalBalance -import com.tangem.tap.features.wallet.redux.reducers.findProgressState -import com.tangem.tap.features.wallet.ui.BalanceStatus import com.tangem.tap.store import org.rekotlin.StateType import kotlin.properties.ReadOnlyProperty data class WalletState( - val cardId: String = "", + val userWallet: UserWallet? = null, val state: ProgressState = ProgressState.Done, val error: ErrorType? = null, val cardImage: Artwork? = null, val hashesCountVerified: Boolean? = null, val mainWarningsList: List = mutableListOf(), - val walletsStores: List = listOf(), + val walletsStores: List = listOf(), val isMultiwalletAllowed: Boolean = false, val cardCurrency: CryptoCurrencyName? = null, val selectedCurrency: Currency? = null, val isTestnet: Boolean = false, - val totalBalance: TotalBalance? = null, + val totalBalance: TotalFiatBalance? = null, val showBackupWarning: Boolean = false, val missingDerivations: List = emptyList(), val loadingUserTokens: Boolean = false, @@ -39,10 +40,10 @@ data class WalletState( val canSaveUserWallets: Boolean = false, ) : StateType { - val walletsDataFromStores: List - get() = walletsStores.map { it.walletsData }.flatten() + val walletsDataFromStores: List + get() = walletsStores.flatMap { it.walletsData } - val selectedWalletData: WalletData? + val selectedWalletData: WalletDataModel? get() = walletsDataFromStores.firstOrNull { it.currency == selectedCurrency } // if you do not delegate - the application crashes on startup, @@ -66,7 +67,7 @@ data class WalletState( val walletManagers: List get() = walletsStores.mapNotNull { it.walletManager } - private val primaryWalletStore: WalletStore? + private val primaryWalletStore: WalletStoreModel? get() = if (isMultiwalletAllowed || walletsStores.isEmpty() || walletsStores.size > 1) { null } else { @@ -76,17 +77,15 @@ data class WalletState( val primaryWalletManager: WalletManager? get() = primaryWalletStore?.walletManager - val primaryWalletData: WalletData? - get() = primaryWalletStore?.walletsData?.firstOrNull() + val primaryWalletData: WalletDataModel? + get() = primaryWalletStore?.blockchainWalletData - val primaryTokenData: WalletData? - get() = primaryWalletStore?.walletsData?.toMutableList() - ?.apply { remove(primaryWalletData) } - ?.firstOrNull() + val primaryTokenData: WalletDataModel? + get() = primaryWalletStore?.walletsData + ?.firstOrNull { it.currency !is Currency.Blockchain } val shouldShowDetails: Boolean = - primaryWalletData?.currencyData?.status != BalanceStatus.EmptyCard && - primaryWalletData?.currencyData?.status != BalanceStatus.UnknownBlockchain + primaryWalletData?.status !is WalletDataModel.Unreachable fun getWalletManager(currency: Currency?): WalletManager? { if (currency?.blockchain == null) return null @@ -94,95 +93,27 @@ data class WalletState( } fun getWalletManager(blockchain: BlockchainNetwork): WalletManager? { - return walletsStores.find { it.blockchainNetwork == blockchain }?.walletManager + return walletsStores.firstOrNull { + it.blockchain == blockchain.blockchain && + it.derivationPath?.rawPath == blockchain.derivationPath + }?.walletManager } - fun getWalletData(blockchain: BlockchainNetwork?): WalletData? { - if (blockchain == null) return null - return walletsDataFromStores.find { - it.currency is Currency.Blockchain && - it.currency.blockchain == blockchain.blockchain && - it.currency.derivationPath == blockchain.derivationPath - } - } - - fun getWalletStore(currency: Currency?): WalletStore? { + fun getWalletStore(currency: Currency?): WalletStoreModel? { if (currency == null) return null return walletsStores.firstOrNull { - it.blockchainNetwork.derivationPath == currency.derivationPath && - it.blockchainNetwork.blockchain == currency.blockchain + it.blockchain == currency.blockchain && + it.derivationPath?.rawPath == currency.derivationPath } } - - private fun getWalletStore(blockchainNetwork: BlockchainNetwork?): WalletStore? { - if (blockchainNetwork == null) return null - return walletsStores.firstOrNull { - it.blockchainNetwork.derivationPath == blockchainNetwork.derivationPath && - it.blockchainNetwork.blockchain == blockchainNetwork.blockchain - } - } - - fun getWalletData(currency: Currency?): WalletData? { - if (currency == null) return null - return getWalletStore(currency)?.walletsData?.firstOrNull { it.currency == currency } - } - - fun updateWalletData(walletData: WalletData?): WalletState { - if (walletData == null) return this - return updateWalletsData(listOf(walletData)) - } - - private fun updateWalletsData(walletsData: List): WalletState { - val walletStores = walletsData - .map { BlockchainNetwork(it.currency.blockchain, it.currency.derivationPath, emptyList()) } - .distinct().map { getWalletStore(it) }.mapNotNull { it?.updateWallets(walletsData) } - - return updateWalletsStores(walletStores) - } - - private fun updateWalletsStores(walletStores: List): WalletState { - val walletStoresMutable = walletStores.toMutableList() - val updatedWallets = walletsStores.map { oldWalletStore -> - val walletStore = walletStoresMutable.find { - it.blockchainNetwork == oldWalletStore.blockchainNetwork - } - if (walletStore != null) { - walletStoresMutable.remove(walletStore) - walletStore - } else { - oldWalletStore - } - } - return copy(walletsStores = updatedWallets + walletStoresMutable) - .updateProgressState() - } - - private fun updateProgressState(): WalletState { - val walletsData = this.walletsStores - .flatMap(WalletStore::walletsData) - - return if (walletsData.isNotEmpty()) { - val newProgressState = walletsData.findProgressState() - - this.copy( - state = walletsData.findProgressState(), - error = this.error.takeIf { newProgressState == ProgressState.Error }, - ) - } else { - this - } - } - - companion object { - const val UNKNOWN_AMOUNT_SIGN = "—" - const val ROUGH_SIGN = "≈" - const val CAN_BE_LOWER_SIGN = "<" - } } enum class ProgressState : WidgetState { Loading, Refreshing, Done, Error } -enum class ErrorType { NoInternetConnection } +enum class ErrorType { + NoInternetConnection, + UnknownBlockchain, +} sealed class WalletMainButton(enabled: Boolean) : Button(enabled) { class SendButton(enabled: Boolean) : WalletMainButton(enabled) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/Mapper.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/Mapper.kt index cd9ac58574..e48f89ce52 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/Mapper.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/Mapper.kt @@ -77,7 +77,7 @@ private fun WalletDataModel.mapToReduxModel( return WalletData( currency = currency, - // TODO: Will be updated in next MR + // TODO: Will be updated in next MRs walletAddresses = walletAddresses?.let { addresses -> WalletAddresses( selectedAddress = with(addresses.selectedAddress) { 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 7893c448c5..404aa63a43 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 @@ -32,10 +32,7 @@ import com.tangem.tap.features.send.redux.PrepareSendScreen import com.tangem.tap.features.wallet.models.Currency import com.tangem.tap.features.wallet.models.getSendableAmounts 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.redux.reducers.findSelectedCurrency import com.tangem.tap.preferencesStorage import com.tangem.tap.proxy.redux.DaggerGraphState import com.tangem.tap.scope @@ -106,7 +103,7 @@ class WalletMiddleware { scope.launch { when (val result = tangemSdkManager.createWallet(globalState.scanResponse?.card?.cardId)) { is CompletionResult.Success -> { - val selectedUserWallet = userWalletsListManager.selectedUserWalletSync.guard { + val selectedUserWallet = walletState.userWallet.guard { Timber.e("Unable to create wallet, no user wallet selected") return@launch } @@ -132,7 +129,7 @@ class WalletMiddleware { is WalletAction.LoadData, is WalletAction.LoadData.Refresh, -> { - val selectedWallet = userWalletsListManager.selectedUserWalletSync.guard { + val selectedWallet = walletState.userWallet.guard { Timber.e("Unable to load/refresh wallets data, no user wallet selected") return } @@ -188,7 +185,6 @@ class WalletMiddleware { is WalletAction.WalletStoresChanged -> { // Cancel update job when new wallet stores received updateWalletStoresJob = scope.launch(Dispatchers.Default) { - ifActive { updateWalletStores(action.walletStores, walletState) } ifActive { fetchTotalFiatBalance(action.walletStores) } ifActive { findMissedDerivations(action.walletStores) } ifActive { tryToShowAppRatingWarning(action.walletStores) } @@ -227,26 +223,8 @@ class WalletMiddleware { } } - private fun updateWalletStores(walletsStores: List, state: WalletState) { - val reduxWalletStores = walletsStores.mapToReduxModels() - if (!state.isMultiwalletAllowed) { - findSelectedCurrency( - walletsStores = reduxWalletStores, - currentSelectedCurrency = null, - isMultiWalletAllowed = false, - )?.let { - store.dispatchOnMain(WalletAction.MultiWallet.SetSingleWalletCurrency(it)) - } - } - store.dispatchOnMain( - WalletAction.WalletStoresChanged.UpdateWalletStores( - reduxWalletStores = reduxWalletStores, - ), - ) - } - private suspend fun fetchTotalFiatBalance(walletStores: List) { - val totalFiatBalance = totalFiatBalanceCalculator.calculateOrNull(walletStores)?.mapToReduxModel() + val totalFiatBalance = totalFiatBalanceCalculator.calculateOrNull(walletStores) if (totalFiatBalance != null) { store.dispatchOnMain(WalletAction.TotalFiatBalanceChanged(totalFiatBalance)) @@ -300,7 +278,7 @@ class WalletMiddleware { return if (amount != null) { if (amount.type is AmountType.Token) { - prepareSendActionForToken(amount, state, selectedWalletData, walletStore) + prepareSendActionForToken(amount, selectedWalletData, walletStore) } else { PrepareSendScreen(amount, selectedWalletData?.fiatRate, walletStore?.walletManager) } @@ -322,7 +300,6 @@ class WalletMiddleware { ?: return WalletAction.DialogAction.ChooseCurrency(amounts) prepareSendActionForToken( amount = amountToSend, - state = state, selectedWalletData = selectedWalletData, walletStore = walletStore, ) @@ -346,11 +323,10 @@ class WalletMiddleware { private fun prepareSendActionForToken( amount: Amount, - state: WalletState?, - selectedWalletData: WalletData?, - walletStore: WalletStore?, + selectedWalletData: WalletDataModel?, + walletStore: WalletStoreModel?, ): PrepareSendScreen { - val coinRate = state?.getWalletData(walletStore?.blockchainNetwork)?.fiatRate + val coinRate = walletStore?.blockchainWalletData?.fiatRate val tokenRate = selectedWalletData?.fiatRate val coinAmount = walletStore?.walletManager?.wallet?.amounts?.get(AmountType.Coin) 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 49c0035b5a..b1d7fcfef0 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 @@ -1,23 +1,18 @@ package com.tangem.tap.features.wallet.redux.reducers -import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.Wallet import com.tangem.domain.common.CardDTO import com.tangem.domain.common.TapWorkarounds.isTestCard import com.tangem.tap.common.redux.AppState import com.tangem.tap.domain.TapError -import com.tangem.tap.domain.tokens.models.BlockchainNetwork +import com.tangem.tap.domain.model.WalletDataModel +import com.tangem.tap.domain.model.WalletStoreModel import com.tangem.tap.features.wallet.models.Currency -import com.tangem.tap.features.wallet.redux.AddressData import com.tangem.tap.features.wallet.redux.Artwork 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.WalletStore -import com.tangem.tap.features.wallet.ui.BalanceStatus -import com.tangem.tap.features.wallet.ui.BalanceWidgetData import com.tangem.tap.proxy.AppStateHolder import org.rekotlin.Action @@ -41,44 +36,15 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS is WalletAction.LoadData.Failure -> { when (action.error) { is TapError.NoInternetConnection -> { - val wallets = newState.walletsStores - .map { store -> - store.copy( - walletsData = store.walletsData.map { - it.copy( - currencyData = it.currencyData.copy( - status = BalanceStatus.Unreachable, - ), - ) - }, - ) - } - newState = newState.copy( state = ProgressState.Error, error = ErrorType.NoInternetConnection, - walletsStores = wallets, ) } is TapError.UnknownBlockchain -> { newState = newState.copy( - state = ProgressState.Done, - walletsStores = listOf( - WalletStore( - walletManager = null, - blockchainNetwork = BlockchainNetwork( - Blockchain.Unknown, - null, - emptyList(), - ), - walletsData = listOf( - WalletData( - currencyData = BalanceWidgetData(BalanceStatus.UnknownBlockchain), - currency = Currency.Blockchain(Blockchain.Unknown, null), - ), - ), - ), - ), + state = ProgressState.Error, + error = ErrorType.UnknownBlockchain, ) } else -> { @@ -107,7 +73,7 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS is WalletAction.UserWalletChanged -> with(action.userWallet) { val card = scanResponse.card newState = WalletState( - cardId = card.cardId, + userWallet = this, isMultiwalletAllowed = isMultiCurrency, cardImage = Artwork( artworkId = artworkUrl, @@ -126,10 +92,9 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS }, ) } - is WalletAction.WalletStoresChanged.UpdateWalletStores -> { + is WalletAction.WalletStoresChanged -> { newState = newState.copy( - state = action.reduxWalletStores.flatMap { it.walletsData }.findProgressState(newState.state), - walletsStores = action.reduxWalletStores, + walletsStores = action.walletStores, ) } is WalletAction.TotalFiatBalanceChanged -> { @@ -159,7 +124,7 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS } fun findSelectedCurrency( - walletsStores: List, + walletsStores: List, currentSelectedCurrency: Currency?, isMultiWalletAllowed: Boolean, ): Currency? = if (isMultiWalletAllowed) { @@ -175,11 +140,11 @@ private fun CardDTO.findCardsCount(): Int? { return (this.backupStatus as? CardDTO.BackupStatus.Active)?.cardCount?.inc() } -fun Wallet.createAddressesData(): List { - val listOfAddressData = mutableListOf() +fun Wallet.createAddressesData(): List { + val listOfAddressData = mutableListOf() // put a defaultAddress at the first place addresses.forEach { - val addressData = AddressData( + val addressData = WalletDataModel.AddressData( it.value, it.type, getShareUri(it.value), diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/utils/Constants.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/utils/Constants.kt new file mode 100644 index 0000000000..dfab28f18a --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/utils/Constants.kt @@ -0,0 +1,5 @@ +package com.tangem.tap.features.wallet.redux.utils + +const val UNKNOWN_AMOUNT_SIGN = "—" +const val ROUGH_SIGN = "≈" +const val CAN_BE_LOWER_SIGN = "<" \ No newline at end of file