From cb38a5783a6d62caaee3f8cb856e23457e77d7f8 Mon Sep 17 00:00:00 2001 From: Tangem Date: Sun, 7 Aug 2022 21:35:34 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../features/details/redux/DetailsReducer.kt | 8 +- .../tap/features/wallet/ui/WalletFragment.kt | 29 +++-- .../wallet/ui/wallet/MultiWalletView.kt | 18 +-- .../wallet/ui/wallet/SaltPayBalanceWidget.kt | 51 ++++++++ .../ui/wallet/SaltPaySingleWalletView.kt | 51 ++++++++ .../wallet/ui/wallet/SingleWalletView.kt | 38 ++---- .../features/wallet/ui/wallet/WalletView.kt | 24 ++-- app/src/main/res/layout/fragment_wallet.xml | 10 ++ .../layout/layout_single_wallet_balance.xml | 116 ++++++++++++++++++ .../tangem/domain/common/TapWorkarounds.kt | 16 +-- 10 files changed, 280 insertions(+), 81 deletions(-) create mode 100644 app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SaltPayBalanceWidget.kt create mode 100644 app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/SaltPaySingleWalletView.kt create mode 100644 app/src/main/res/layout/layout_single_wallet_balance.xml diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt index 99024b0c20..8db64e1cee 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt @@ -1,6 +1,7 @@ package com.tangem.tap.features.details.redux import com.tangem.common.card.Card +import com.tangem.domain.common.TapWorkarounds.isSaltPay import com.tangem.domain.common.TapWorkarounds.isStart2Coin import com.tangem.domain.common.TapWorkarounds.isTangemNote import com.tangem.domain.common.isTangemTwin @@ -19,7 +20,6 @@ class DetailsReducer { private fun internalReduce(action: Action, state: AppState): DetailsState { if (action !is DetailsAction) return state.detailsState - val detailsState = state.detailsState return when (action) { is DetailsAction.PrepareScreen -> { @@ -40,7 +40,6 @@ private fun internalReduce(action: Action, state: AppState): DetailsState { } is DetailsAction.ChangeAppCurrency -> detailsState.copy(appCurrency = action.fiatCurrency) - else -> detailsState } } @@ -48,7 +47,6 @@ private fun internalReduce(action: Action, state: AppState): DetailsState { private fun handlePrepareScreen( action: DetailsAction.PrepareScreen, ): DetailsState { - return DetailsState( scanResponse = action.scanResponse, wallets = action.wallets, @@ -99,7 +97,8 @@ private fun prepareSecurityOptions(card: Card): ManageSecurityState { private fun isResetToFactoryAllowedByCard(card: Card): Boolean { val notAllowedByAnyWallet = card.wallets.any { it.settings.isPermanent } val notAllowedByCard = notAllowedByAnyWallet || - (card.isWalletDataSupported && (!card.isTangemNote() && !card.settings.isBackupAllowed)) + (card.isWalletDataSupported && (!card.isTangemNote() && !card.settings.isBackupAllowed)) || + card.isSaltPay return !notAllowedByCard } @@ -140,7 +139,6 @@ private fun handleSecurityAction( ), ) } - else -> state } } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt index 73f315e29b..fe3c9131e4 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt @@ -14,6 +14,7 @@ import androidx.transition.TransitionInflater import by.kirich1409.viewbindingdelegate.viewBinding import coil.load import coil.size.Scale +import com.tangem.domain.common.TapWorkarounds.isSaltPay import com.tangem.tap.MainActivity import com.tangem.tap.common.extensions.show import com.tangem.tap.common.recyclerView.SpaceItemDecoration @@ -32,6 +33,7 @@ import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.features.wallet.redux.WalletState import com.tangem.tap.features.wallet.ui.adapters.WarningMessagesAdapter import com.tangem.tap.features.wallet.ui.wallet.MultiWalletView +import com.tangem.tap.features.wallet.ui.wallet.SaltPaySingleWalletView import com.tangem.tap.features.wallet.ui.wallet.SingleWalletView import com.tangem.tap.features.wallet.ui.wallet.WalletView import com.tangem.tap.store @@ -112,17 +114,22 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber { + walletView = SaltPaySingleWalletView() + } + state.isMultiwalletAllowed && + state.primaryWallet?.currencyData?.status != BalanceStatus.EmptyCard && + walletView is SingleWalletView -> { + walletView = MultiWalletView() + } + !state.isMultiwalletAllowed && walletView is MultiWalletView -> { + walletView = SingleWalletView() + } } + + walletView.changeWalletView(this, binding) walletView.onNewState(state) if (!state.shouldShowDetails) { @@ -134,7 +141,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber tvTwinCardNumber.show() @@ -113,11 +97,9 @@ class SingleWalletView : WalletView { } private fun setupButtons( - state: WalletData, isTwinsWallet: Boolean, binding: FragmentWalletBinding + state: WalletData, isTwinsWallet: Boolean, binding: FragmentWalletBinding, ) = with(binding) { - setupButtonsType(state, binding) - val tradeState = state.tradeCryptoState val btnConfirm = if (tradeState.isAvailableToSell() || tradeState.isAvailableToBuy()) { lButtonsShort.btnConfirm @@ -137,8 +119,8 @@ class SingleWalletView : WalletView { store.dispatch( WalletAction.DialogAction.QrCode( currency = state.currency, - selectedAddress = selectedAddress - ) + selectedAddress = selectedAddress, + ), ) } } @@ -207,7 +189,6 @@ class SingleWalletView : WalletView { } } - private fun setupAddressCard(state: WalletData, binding: FragmentWalletBinding) = with(binding.lAddress) { if (state.walletAddresses != null && state.currency is Currency.Blockchain) { binding.lAddress.root.show() @@ -215,7 +196,6 @@ class SingleWalletView : WalletView { (binding.lAddress.root as? ViewGroup)?.beginDelayedTransition() chipGroupAddressType.show() chipGroupAddressType.fitChipsByGroupWidth() - val checkedId = MultipleAddressUiHelper.typeToId(state.walletAddresses.selectedAddress.type) if (checkedId != View.NO_ID) chipGroupAddressType.check(checkedId) @@ -234,8 +214,8 @@ class SingleWalletView : WalletView { store.dispatch( WalletAction.ExploreAddress( state.walletAddresses.selectedAddress.exploreUrl, - fragment!!.requireContext() - ) + fragment!!.requireContext(), + ), ) } } else { diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/WalletView.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/WalletView.kt index 1d9ea0eac0..a3b09aab12 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/WalletView.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/wallet/WalletView.kt @@ -4,16 +4,20 @@ import com.tangem.tap.features.wallet.redux.WalletState import com.tangem.tap.features.wallet.ui.WalletFragment import com.tangem.wallet.databinding.FragmentWalletBinding -interface WalletView { +abstract class WalletView { + protected var fragment: WalletFragment? = null + protected var binding: FragmentWalletBinding? = null + fun setFragment(fragment: WalletFragment, binding: FragmentWalletBinding) { + this.fragment = fragment + this.binding = binding + } - fun setFragment(fragment: WalletFragment, binding: FragmentWalletBinding) - - fun removeFragment() - - fun changeWalletView(fragment: WalletFragment, binding: FragmentWalletBinding) - - fun onViewCreated() - - fun onNewState(state: WalletState) + fun removeFragment() { + fragment = null + binding = null + } + abstract fun changeWalletView(fragment: WalletFragment, binding: FragmentWalletBinding) + abstract fun onViewCreated() + abstract fun onNewState(state: WalletState) } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_wallet.xml b/app/src/main/res/layout/fragment_wallet.xml index 102ae199f4..b2118902ec 100644 --- a/app/src/main/res/layout/fragment_wallet.xml +++ b/app/src/main/res/layout/fragment_wallet.xml @@ -148,6 +148,16 @@ android:visibility="gone" app:layout_constraintTop_toBottomOf="@id/rv_pending_transaction" /> + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt b/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt index e273a4dae2..a11441c51c 100644 --- a/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt +++ b/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt @@ -9,20 +9,18 @@ import java.util.* [REDACTED_AUTHOR] */ object TapWorkarounds { - fun isStart2CoinIssuer(cardIssuer: String?): Boolean { return cardIssuer?.lowercase(Locale.US) == START_2_COIN_ISSUER } val Card.isStart2Coin: Boolean get() = isStart2CoinIssuer(issuer.name) - + val Card.isSaltPay: Boolean + get() = false //TODO fix when we know which cards are SaltPay cards val Card.isTestCard: Boolean get() = batchId == TEST_CARD_BATCH && cardId.startsWith(TEST_CARD_ID_STARTS_WITH) - val Card.useOldStyleDerivation: Boolean get() = batchId == "AC01" || batchId == "AC02" || batchId == "CB95" - val Card.derivationStyle: DerivationStyle? get() = if (!settings.isHDWalletAllowed) { null @@ -42,21 +40,19 @@ object TapWorkarounds { return false } - fun Card.isTangemNote(): Boolean = tangemNoteBatches.contains(batchId) - + fun Card.isTangemNote(): Boolean = tangemNoteBatches.contains(batchId) || isSaltPay fun isTangemWalletBatch(card: Card): Boolean = tangemWalletBatches.contains(card.batchId) - - fun Card.getTangemNoteBlockchain(): Blockchain? = tangemNoteBatches[batchId] + fun Card.getTangemNoteBlockchain(): Blockchain? = + tangemNoteBatches[batchId] ?: if (isSaltPay) Blockchain.Gnosis else null private const val START_2_COIN_ISSUER = "start2coin" private const val TEST_CARD_BATCH = "99FF" private const val TEST_CARD_ID_STARTS_WITH = "FF99" - private val excludedBatches = listOf( "0027", "0030", "0031", - "0035" + "0035", ) private val excludedIssuers = listOf(