Updated on 2026-08-14

This commit is contained in:
Tangem 2022-12-11 11:04:10 +03:00
parent 87c43ab20f
commit 4a14fb92db
6 changed files with 42 additions and 18 deletions

View file

@ -147,7 +147,7 @@ class TapWalletManager {
updateConfigManager(data)
withMainContext {
store.dispatch(WalletAction.ResetState(data.card.cardId))
store.dispatch(WalletAction.ResetState(data.card))
store.dispatch(WalletConnectAction.ResetState)
store.dispatch(GlobalAction.SaveScanNoteResponse(data))
store.dispatch(WalletAction.SetIfTestnetCard(data.card.isTestCard))

View file

@ -1,7 +1,11 @@
package com.tangem.tap.features.wallet.redux
import android.content.Context
import com.tangem.blockchain.common.*
import com.tangem.blockchain.common.Amount
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.domain.common.CardDTO
import com.tangem.tap.common.entities.FiatCurrency
@ -20,7 +24,7 @@ import java.math.BigDecimal
sealed class WalletAction : Action {
data class ResetState(val newCardId: String) : WalletAction()
data class ResetState(val newCard: CardDTO) : WalletAction()
data class SetIfTestnetCard(val isTestnet: Boolean) : WalletAction()

View file

@ -14,7 +14,11 @@ import com.tangem.tap.common.toggleWidget.WidgetState
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
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.*
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.models.PendingTransaction
import com.tangem.tap.features.wallet.models.TotalBalance
import com.tangem.tap.features.wallet.models.WalletRent
import com.tangem.tap.features.wallet.models.WalletWarning
import com.tangem.tap.features.wallet.redux.reducers.calculateTotalFiatAmount
import com.tangem.tap.features.wallet.redux.reducers.findProgressState
import com.tangem.tap.features.wallet.ui.BalanceStatus
@ -43,6 +47,7 @@ data class WalletState(
val showBackupWarning: Boolean = false,
val missingDerivations: List<BlockchainNetwork> = emptyList(),
val loadingUserTokens: Boolean = false,
val walletCardsCount: Int? = null,
) : StateType {
// if you do not delegate - the application crashes on startup,

View file

@ -53,7 +53,12 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS
is WalletAction.Warnings -> newState = handleCheckSignedHashesActions(action, newState)
is WalletAction.MultiWallet -> newState = multiWalletReducer.reduce(action, newState)
is WalletAction.ResetState -> newState = WalletState(cardId = action.newCardId)
is WalletAction.ResetState -> {
newState = WalletState(
cardId = action.newCard.cardId,
walletCardsCount = action.newCard.findCardsCount(),
)
}
is WalletAction.SetIfTestnetCard -> newState = newState.copy(isTestnet = action.isTestnet)
is WalletAction.EmptyWallet -> {
newState = newState.copy(
@ -333,6 +338,7 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS
showBackupWarning = card.isMultiwalletAllowed &&
card.settings.isBackupAllowed &&
card.backupStatus == CardDTO.BackupStatus.NoBackup,
walletCardsCount = card.findCardsCount(),
)
}
is WalletAction.WalletStoresChanged -> {
@ -366,6 +372,11 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS
return newState
}
private fun CardDTO.findCardsCount(): Int? {
return (this.backupStatus as? CardDTO.BackupStatus.Active)?.cardCount?.inc()
?.takeIf { this.isMultiwalletAllowed }
}
@JvmName("walletStoreModelToReduxModel")
private fun List<WalletStoreModel>.mapToReduxModel(
isMultiWalletAllowed: Boolean,

View file

@ -3,13 +3,16 @@ package com.tangem.tap.features.wallet.ui.wallet
import android.widget.Button
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import com.tangem.domain.common.CardDTO
import com.tangem.domain.common.TapWorkarounds.derivationStyle
import com.tangem.domain.common.TapWorkarounds.isTestCard
import com.tangem.tap.common.analytics.Analytics
import com.tangem.tap.common.analytics.events.MainScreen
import com.tangem.tap.common.analytics.events.Portfolio
import com.tangem.tap.common.extensions.*
import com.tangem.tap.common.extensions.animateVisibility
import com.tangem.tap.common.extensions.formatAmountAsSpannedString
import com.tangem.tap.common.extensions.getQuantityString
import com.tangem.tap.common.extensions.hide
import com.tangem.tap.common.extensions.show
import com.tangem.tap.common.redux.navigation.AppScreen
import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.domain.tokens.CurrenciesRepository
@ -45,19 +48,8 @@ class MultiWalletView : WalletView() {
lSingleWalletBalance.root.hide()
rvMultiwallet.show()
btnAddToken.show()
setupWalletCardNumber(binding)
}
private fun setupWalletCardNumber(binding: FragmentWalletBinding) = with(binding) {
val card = store.state.globalState.scanResponse?.card
if (card?.backupStatus is CardDTO.BackupStatus.Active) {
val cardCount = (card.backupStatus as CardDTO.BackupStatus.Active).cardCount + 1
tvTwinCardNumber.show()
tvTwinCardNumber.text = tvTwinCardNumber.getQuantityString(R.plurals.card_label_card_count, cardCount)
} else {
tvTwinCardNumber.hide()
}
}
override fun onViewCreated() {
setupWalletsRecyclerView()
@ -79,6 +71,7 @@ class MultiWalletView : WalletView() {
handleTotalBalance(binding, state.totalBalance, state.state)
handleBackupWarning(binding, state.showBackupWarning)
handleRescanWarning(binding, state.missingDerivations.isNotEmpty())
setupWalletCardNumber(binding, state.walletCardsCount)
walletsAdapter.submitList(state.walletsData)
binding.pbLoadingUserTokens.show(state.loadingUserTokens)
@ -107,6 +100,16 @@ class MultiWalletView : WalletView() {
handleErrorStates(state = state, binding = binding, fragment = fragment)
}
private fun setupWalletCardNumber(binding: FragmentWalletBinding, walletCardsCount: Int?) = with(binding) {
if (walletCardsCount != null) {
tvTwinCardNumber.show()
tvTwinCardNumber.text =
tvTwinCardNumber.getQuantityString(R.plurals.card_label_card_count, walletCardsCount)
} else {
tvTwinCardNumber.hide()
}
}
private fun handleBackupWarning(
binding: FragmentWalletBinding,
showBackupWarning: Boolean,

View file

@ -33,6 +33,7 @@ class SingleWalletView : WalletView() {
}
private fun showSingleWalletView(binding: FragmentWalletBinding) = with(binding) {
tvTwinCardNumber.hide()
rvMultiwallet.hide()
btnAddToken.hide()
rvPendingTransaction.hide()