Updated on 2026-08-14

This commit is contained in:
Tangem 2023-09-25 18:29:22 +08:00
parent 6c850776d5
commit cf308447a8
2 changed files with 23 additions and 15 deletions

View file

@ -6,6 +6,7 @@ import com.tangem.core.ui.components.marketprice.MarketPriceBlockState
import com.tangem.core.ui.components.transactions.state.TxHistoryState
import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.feature.wallet.presentation.wallet.domain.WalletAdditionalInfoFactory
import com.tangem.feature.wallet.presentation.wallet.domain.WalletImageResolver
import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState
@ -86,22 +87,22 @@ internal class WalletSkeletonStateConverter(
private fun createWalletsListConfig(value: SkeletonModel): WalletsListConfig {
return WalletsListConfig(
selectedWalletIndex = value.selectedWalletIndex,
wallets = value.wallets.mapIndexed(::createWalletCardState).toImmutableList(),
wallets = value.wallets.map(::createWalletCardState).toImmutableList(),
onWalletChange = clickIntents::onWalletChange,
)
}
/**
* Create wallet card state by [index] and [wallet].
* Create wallet card state by [wallet].
* If current wallet card state is initialized, then method returns it.
* Otherwise, returns loading wallet card state.
*/
private fun createWalletCardState(index: Int, wallet: UserWallet): WalletCardState {
return currentStateProvider().getInitializedWalletCardState(index) ?: wallet.mapToWalletCardState()
private fun createWalletCardState(wallet: UserWallet): WalletCardState {
return currentStateProvider().getInitializedWalletCardState(wallet.walletId) ?: wallet.mapToWalletCardState()
}
private fun WalletState.getInitializedWalletCardState(index: Int): WalletCardState? {
return (this as? WalletState.ContentState)?.walletsListConfig?.wallets?.getOrNull(index)
private fun WalletState.getInitializedWalletCardState(walledId: UserWalletId): WalletCardState? {
return (this as? WalletState.ContentState)?.walletsListConfig?.wallets?.firstOrNull { it.id == walledId }
}
private fun UserWallet.mapToWalletCardState(): WalletCardState {

View file

@ -51,10 +51,14 @@ internal class WalletsUpdateActionResolver(
wallets: List<UserWallet>,
selectedWallet: UserWallet,
): Action {
return if (isWalletsCountChanged(state, wallets)) {
getActionToChangeWallets(state = state, wallets = wallets, selectedWallet = selectedWallet)
} else {
getActionToUpdateCurrentWallet(state = state, wallets = wallets, selectedWallet = selectedWallet)
return when {
isWalletsCountChanged(state, wallets) -> {
getActionToChangeWallets(state = state, wallets = wallets, selectedWallet = selectedWallet)
}
isSelectedWalletChanged(state, selectedWallet) -> {
Action.Initialize(wallets.indexOfWallet(selectedWallet.walletId))
}
else -> getActionToUpdateCurrentWallet(state = state, wallets = wallets, selectedWallet = selectedWallet)
}
}
@ -96,6 +100,10 @@ internal class WalletsUpdateActionResolver(
?: error("Deleted wallet id is not found. Wallets contains all previous wallets ids")
}
private fun isSelectedWalletChanged(state: WalletState.ContentState, selectedWallet: UserWallet): Boolean {
return state.getPrevSelectedWallet().id != selectedWallet.walletId
}
private fun getActionToUpdateCurrentWallet(
state: WalletState.ContentState,
wallets: List<UserWallet>,
@ -103,7 +111,7 @@ internal class WalletsUpdateActionResolver(
): Action {
val selectedWalletName = selectedWallet.name
if (state.getPrevSelectedWalletName() != selectedWalletName) {
if (state.getPrevSelectedWallet().title != selectedWalletName) {
return Action.UpdateWalletName(selectedWalletName)
}
@ -118,12 +126,11 @@ internal class WalletsUpdateActionResolver(
return Action.Unknown
}
private fun WalletState.ContentState.getPrevSelectedWalletName(): String {
private fun WalletState.ContentState.getPrevSelectedWallet(): WalletCardState {
val prevSelectedWalletIndex = walletsListConfig.selectedWalletIndex
val prevSelectedWallet = walletsListConfig.wallets.getOrNull(prevSelectedWalletIndex)
?: error("Previous selected wallet is not found")
return prevSelectedWallet.title
return walletsListConfig.wallets.getOrNull(prevSelectedWalletIndex)
?: error("Previous selected wallet is not found")
}
private fun List<UserWallet>.indexOfWallet(id: UserWalletId): Int {