Updated on 2026-08-14
This commit is contained in:
parent
097e9c1bce
commit
2437fa39d8
9 changed files with 120 additions and 22 deletions
|
|
@ -68,7 +68,7 @@ internal class WalletsUpdateActionResolver @Inject constructor(
|
|||
isAnyWalletUnlocked(state, wallets) -> {
|
||||
Action.UnlockWallet(
|
||||
selectedWallet = selectedWallet,
|
||||
unlockedWallets = wallets.filterNot(UserWallet::isLocked),
|
||||
unlockedWallets = getJustUnlockedWallets(state = state, wallets = wallets),
|
||||
)
|
||||
}
|
||||
isAnyWalletNameChanged(state, wallets) -> {
|
||||
|
|
@ -232,11 +232,28 @@ internal class WalletsUpdateActionResolver @Inject constructor(
|
|||
private fun isAnyWalletUnlocked(state: WalletScreenState, wallets: List<UserWallet>): Boolean {
|
||||
return state.wallets.any { walletState ->
|
||||
val wallet = wallets.firstOrNull { it.walletId == walletState.walletCardState.id } ?: return@any false
|
||||
!wallet.isLocked &&
|
||||
(walletState is WalletState.MultiCurrency.Locked || walletState is WalletState.SingleCurrency.Locked)
|
||||
wallet.isJustUnlockedFrom(walletState)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wallets that transitioned from a locked UI state to unlocked data state in this update cycle.
|
||||
* Does not include wallets that were already unlocked before — otherwise downstream handlers
|
||||
* (e.g. [com.tangem.feature.wallet.child.wallet.model.WalletModel.unlockWallet]) would re-fetch
|
||||
* already-loaded wallets and emit redundant transformer state changes.
|
||||
*/
|
||||
private fun getJustUnlockedWallets(state: WalletScreenState, wallets: List<UserWallet>): List<UserWallet> {
|
||||
return state.wallets.mapNotNull { walletState ->
|
||||
val wallet = wallets.firstOrNull { it.walletId == walletState.walletCardState.id }
|
||||
wallet?.takeIf { it.isJustUnlockedFrom(walletState) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun UserWallet.isJustUnlockedFrom(walletState: WalletState): Boolean {
|
||||
return !isLocked &&
|
||||
(walletState is WalletState.MultiCurrency.Locked || walletState is WalletState.SingleCurrency.Locked)
|
||||
}
|
||||
|
||||
private fun isSelectedWalletCardsCountChanged(state: WalletScreenState, selectedWallet: UserWallet): Boolean {
|
||||
if (selectedWallet !is UserWallet.Cold) return false
|
||||
val prevSelectedWallet = state.getPrevSelectedWallet()
|
||||
|
|
|
|||
|
|
@ -8,12 +8,13 @@ import com.tangem.feature.wallet.presentation.wallet.state.model.*
|
|||
import com.tangem.feature.wallet.presentation.wallet.state.transformers.CloseBottomSheetTransformer
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.transformers.OpenBottomSheetTransformer
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.transformers.WalletScreenStateTransformer
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.transformers.WalletStateTransformer
|
||||
import com.tangem.utils.extensions.indexOfFirstOrNull
|
||||
import com.tangem.utils.logging.TangemLogger
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import com.tangem.utils.logging.TangemLogger
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
|
@ -41,7 +42,14 @@ internal class WalletStateController @Inject constructor(
|
|||
}
|
||||
|
||||
fun update(transformer: WalletScreenStateTransformer) {
|
||||
TangemLogger.d("Applying: ${transformer::class.simpleName}")
|
||||
val walletStateTransformer = transformer as? WalletStateTransformer
|
||||
val maybeWalletId = if (walletStateTransformer != null) {
|
||||
" for ${walletStateTransformer.userWalletId}"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
TangemLogger.d("Applying: ${transformer::class.simpleName}$maybeWalletId")
|
||||
mutableUiState.update(function = transformer::transform)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ internal class UnlockWalletTransformer(
|
|||
is WalletState.MultiCurrency.Content,
|
||||
is WalletState.SingleCurrency.Content,
|
||||
-> {
|
||||
TangemLogger.e("Impossible to unlock wallet with not locked state")
|
||||
TangemLogger.e("createLoadingState: Impossible to unlock wallet with not locked state")
|
||||
prevState
|
||||
}
|
||||
}
|
||||
|
|
@ -79,7 +79,7 @@ internal class UnlockWalletTransformer(
|
|||
userWallet = unlockedWallet,
|
||||
)
|
||||
is WalletUM.Content -> {
|
||||
TangemLogger.e("Impossible to unlock wallet with not locked state")
|
||||
TangemLogger.e("createLoadingState2: Impossible to unlock wallet with not locked state")
|
||||
walletUM
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.tangem.feature.wallet.presentation.wallet.state.model.WalletUM
|
|||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
internal abstract class WalletStateTransformer(
|
||||
protected val userWalletId: UserWalletId,
|
||||
internal val userWalletId: UserWalletId,
|
||||
) : WalletScreenStateTransformer {
|
||||
|
||||
abstract fun transform(prevState: WalletState): WalletState
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue