Updated on 2026-08-14

This commit is contained in:
Tangem 2023-02-21 19:12:36 +03:00
parent 9395c20868
commit 0dffb81f89

View file

@ -1,8 +1,10 @@
package com.tangem.tap.features.wallet.ui.wallet
import android.widget.Button
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import com.badoo.mvicore.DiffStrategy
import com.badoo.mvicore.modelWatcher
import com.tangem.core.analytics.Analytics
import com.tangem.domain.common.TapWorkarounds.derivationStyle
@ -18,6 +20,7 @@ import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.domain.tokens.CurrenciesRepository
import com.tangem.tap.features.tokens.redux.TokensAction
import com.tangem.tap.features.wallet.models.TotalBalance
import com.tangem.tap.features.wallet.redux.ProgressState
import com.tangem.tap.features.wallet.redux.WalletAction
import com.tangem.tap.features.wallet.redux.WalletState
import com.tangem.tap.features.wallet.ui.BalanceStatus
@ -32,7 +35,14 @@ class MultiWalletView : WalletView() {
private lateinit var walletsAdapter: WalletAdapter
private val watcher = modelWatcher {
private val watcher = modelWatcher<WalletState> {
val totalBalanceStrategy: DiffStrategy<WalletState> = { old, new ->
old.cardId != new.cardId ||
old.totalBalance != new.totalBalance ||
old.state != new.state ||
old.walletsStores.size != new.walletsStores.size
}
// !!! Workaround !!!
// Checking state properties instead of state params can reduce application performance,
// but here it is necessary because the WalletStore has an unsuitable equals method
@ -57,11 +67,13 @@ class MultiWalletView : WalletView() {
handleBackupWarning(it, showBackupWarnings)
}
}
WalletState::totalBalance { totalBalance ->
watch({ it }, totalBalanceStrategy) { walletState ->
binding?.let {
handleTotalBalance(
binding = it,
totalBalance = totalBalance,
totalBalance = walletState.totalBalance,
progressState = walletState.state,
walletsCount = walletState.walletsDataFromStores.size,
)
}
}
@ -167,7 +179,11 @@ class MultiWalletView : WalletView() {
private fun handleTotalBalance(
binding: FragmentWalletBinding,
totalBalance: TotalBalance?,
progressState: ProgressState,
walletsCount: Int,
) = with(binding.lCardTotalBalance) {
isGone = progressState == ProgressState.Done && walletsCount == 0
onChangeFiatCurrencyClick = {
store.dispatch(WalletAction.AppCurrencyAction.ChooseAppCurrency)
}