From 9dc744b5a7314b04b5c707c4ffc61229e8fd442b Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 12 May 2023 22:21:23 +0800 Subject: [PATCH] Updated on 2026-08-14 --- .../utils/WalletDataOperations.kt | 36 +++--- .../wallet/ui/WalletDetailsFragment.kt | 110 ++++++++++-------- gradle/dependencies.toml | 2 +- 3 files changed, 77 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletDataOperations.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletDataOperations.kt index 55d0faa5d2..e342ff4e70 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletDataOperations.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletDataOperations.kt @@ -52,42 +52,36 @@ internal fun List.updateWithAmounts(wallet: Wallet): List { val amount = wallet.fundsAvailable(AmountType.Coin) if (pendingTransactions.isEmpty()) { - WalletDataModel.VerifiedOnline( - amount = amount, - ) + WalletDataModel.VerifiedOnline(amount) } else { - WalletDataModel.TransactionInProgress( - amount = amount, - pendingTransactions = pendingTransactions, - ) + WalletDataModel.TransactionInProgress(amount, pendingTransactions) } } + is Currency.Token -> { val token = currency.token val amount = wallet.fundsAvailable(AmountType.Token(token)) - val hasTokenPendingTransactions = pendingTransactions - .any { it.transactionData.amount.currencySymbol == token.symbol } + val hasTokenPendingTransactions = pendingTransactions.any { + it.transactionData.amount.currencySymbol == token.symbol + } + when { hasTokenPendingTransactions -> { - WalletDataModel.TransactionInProgress( - amount = amount, - pendingTransactions = pendingTransactions, - ) + WalletDataModel.TransactionInProgress(amount, pendingTransactions) } + pendingTransactions.isNotEmpty() -> { - WalletDataModel.SameCurrencyTransactionInProgress( - amount = amount, - pendingTransactions = pendingTransactions, - ) + // FIXME: Necessary to avoid passing pending transactions + // because SameCurrencyTransactionInProgress didn't use it. It used only to define main button + // availability. UI layer turned off pending transaction visibility for this state. + WalletDataModel.SameCurrencyTransactionInProgress(amount, pendingTransactions) } else -> { - WalletDataModel.VerifiedOnline( - amount = amount, - ) + WalletDataModel.VerifiedOnline(amount) } } } 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 4ea69fa30f..afee65593c 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,7 +1,11 @@ package com.tangem.tap.features.wallet.ui 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 @@ -27,8 +31,16 @@ import com.tangem.tap.common.SnackbarHandler import com.tangem.tap.common.TestActions import com.tangem.tap.common.analytics.events.DetailsScreen import com.tangem.tap.common.analytics.events.Token -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.show +import com.tangem.tap.common.extensions.toQrCode import com.tangem.tap.common.recyclerView.SpaceItemDecoration +import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.navigation.NavigationAction import com.tangem.tap.common.utils.SafeStoreSubscriber import com.tangem.tap.domain.model.WalletDataModel @@ -45,7 +57,15 @@ 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.images.load import com.tangem.tap.features.wallet.ui.test.TestWallet -import com.tangem.tap.features.wallet.ui.utils.* +import com.tangem.tap.features.wallet.ui.utils.assembleWarnings +import com.tangem.tap.features.wallet.ui.utils.getAvailableActions +import com.tangem.tap.features.wallet.ui.utils.getFormattedAmount +import com.tangem.tap.features.wallet.ui.utils.getFormattedFiatAmount +import com.tangem.tap.features.wallet.ui.utils.isAvailableToBuy +import com.tangem.tap.features.wallet.ui.utils.isAvailableToSell +import com.tangem.tap.features.wallet.ui.utils.isAvailableToSwap +import com.tangem.tap.features.wallet.ui.utils.mainButton +import com.tangem.tap.features.wallet.ui.utils.shouldShowMultipleAddress import com.tangem.tap.store import com.tangem.tap.userWalletsListManagerSafe import com.tangem.tap.walletCurrenciesManager @@ -63,9 +83,7 @@ import javax.inject.Inject */ @Suppress("LargeClass", "MagicNumber") @AndroidEntryPoint -class WalletDetailsFragment : - Fragment(R.layout.fragment_wallet_details), - SafeStoreSubscriber { +class WalletDetailsFragment : Fragment(R.layout.fragment_wallet_details), SafeStoreSubscriber { @Inject lateinit var swapInteractor: SwapInteractor @@ -157,18 +175,6 @@ class WalletDetailsFragment : exitTransition = inflater.inflateTransition(R.transition.fade) } - override fun onStart() { - super.onStart() - store.subscribe(this) { state -> - state.select { it.walletState } - } - } - - override fun onStop() { - super.onStop() - store.unsubscribe(this) - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) (activity as? AppCompatActivity)?.setSupportActionBar(binding.toolbar) @@ -180,6 +186,16 @@ class WalletDetailsFragment : setupTestActionButton() } + override fun onStart() { + super.onStart() + store.subscribe(this) { state -> state.select(AppState::walletState) } + } + + override fun onStop() { + super.onStop() + store.unsubscribe(this) + } + override fun onDestroyView() { super.onDestroyView() clearWatchers() @@ -198,18 +214,13 @@ class WalletDetailsFragment : rvWarningMessages.addItemDecoration(SpaceItemDecoration.vertical(8f)) } - private fun setupButtons() = with(binding) { - rowButtons.onSendClick = { - store.dispatch(WalletAction.Send()) - } + private fun setupButtons() { + binding.rowButtons.onSendClick = { store.dispatch(WalletAction.Send()) } } private fun setupTestActionButton() { view?.findViewById(R.id.l_balance)?.let { view -> - TestActions.initFor( - view = view, - actions = TestWallet.solanaRentExemptWarning(), - ) + TestActions.initFor(view = view, actions = TestWallet.solanaRentExemptWarning()) } } @@ -223,10 +234,8 @@ class WalletDetailsFragment : private fun updateViewMeasurements() { val tvFiatAmount = binding.lWalletDetails.lBalance.tvFiatAmount - val paddingStart = when (tvFiatAmount.text) { - UNKNOWN_AMOUNT_SIGN -> 16f - else -> 12f - } + val paddingStart = if (tvFiatAmount.text == UNKNOWN_AMOUNT_SIGN) 16f else 12f + tvFiatAmount.setPadding( tvFiatAmount.dpToPx(paddingStart).toInt(), tvFiatAmount.paddingTop, @@ -259,12 +268,11 @@ class WalletDetailsFragment : } binding.srlWalletDetails.isRefreshing = true lifecycleScope.launch(Dispatchers.Default) { - walletCurrenciesManager.update(selectedUserWallet, walletData.currency) - .doOnResult { - withMainContext { - binding.srlWalletDetails.isRefreshing = false - } + walletCurrenciesManager.update(selectedUserWallet, walletData.currency).doOnResult { + withMainContext { + binding.srlWalletDetails.isRefreshing = false } + } } } } @@ -272,14 +280,11 @@ class WalletDetailsFragment : private fun setupCopyAndShareButtons(walletAddress: String?) { binding.lWalletDetails.btnCopy.setOnClickListener { - if (walletAddress != null) { - store.dispatch(WalletAction.CopyAddress(walletAddress, requireContext())) - } + if (walletAddress != null) store.dispatch(WalletAction.CopyAddress(walletAddress, requireContext())) } + binding.lWalletDetails.btnShare.setOnClickListener { - if (walletAddress != null) { - store.dispatch(WalletAction.ShareAddress(walletAddress, requireContext())) - } + if (walletAddress != null) store.dispatch(WalletAction.ShareAddress(walletAddress, requireContext())) } } @@ -339,9 +344,7 @@ class WalletDetailsFragment : } private fun showPendingTransactionsIfPresent(pendingTransactions: List) { - val knownTransactions = pendingTransactions.filterNot { - it.type == PendingTransactionType.Unknown - } + val knownTransactions = pendingTransactions.filterNot { it.type == PendingTransactionType.Unknown } pendingTransactionAdapter.submitList(knownTransactions) binding.rvPendingTransaction.show(knownTransactions.isNotEmpty()) } @@ -387,8 +390,7 @@ class WalletDetailsFragment : chipGroupAddressType.show() chipGroupAddressType.fitChipsByGroupWidth() - val checkedId = - MultipleAddressUiHelper.typeToId(selectedAddress.type) + val checkedId = MultipleAddressUiHelper.typeToId(selectedAddress.type) if (checkedId != View.NO_ID) chipGroupAddressType.check(checkedId) chipGroupAddressType.setOnCheckedChangeListener { _, checkedId -> @@ -443,11 +445,14 @@ class WalletDetailsFragment : -> { lBalance.tvStatus.setVerifiedBalanceStatus(R.string.wallet_balance_verified) } - else -> { + + is WalletDataModel.TransactionInProgress -> { lBalance.tvStatus.setWarningStatus(R.string.wallet_balance_tx_in_progress) + showPendingTransactionsIfPresent(status.pendingTransactions) } + + else -> Unit } - showPendingTransactionsIfPresent(status.pendingTransactions) } is WalletDataModel.Unreachable -> { lBalanceError.root.hide() @@ -470,10 +475,12 @@ class WalletDetailsFragment : walletData.currency.currencySymbol, ) } - else -> {} + + else -> Unit } } + @Deprecated("Deprecated in Java") override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { R.id.menu_remove -> { @@ -483,10 +490,15 @@ class WalletDetailsFragment : } false } + else -> super.onOptionsItemSelected(item) } } + @Deprecated( + message = "Deprecated in Java", + replaceWith = ReplaceWith("inflater.inflate(R.menu.menu_wallet_details, menu)", "com.tangem.wallet.R"), + ) override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.menu_wallet_details, menu) } diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index f6cde60962..429afc11d1 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -74,7 +74,7 @@ arrow = "1.2.0-RC" # region Tangem tangemBlockchainSdk = "develop-210" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds -tangemCardSdk = "develop-235" +tangemCardSdk = "develop-236" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds # endregion Tangem