Updated on 2026-08-14
This commit is contained in:
parent
fcf404a2cf
commit
8b40cf4889
5 changed files with 63 additions and 32 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 5fc86d29bc2c0dc7c057ab0242b2cfa3e9f48daf
|
||||
Subproject commit 76978242504ab90803b99e2b0575f7ebe8e69335
|
||||
|
|
@ -453,7 +453,7 @@ internal class WalletModel @Inject constructor(
|
|||
private suspend fun updateWallets(action: WalletsUpdateActionResolver.Action) {
|
||||
when (action) {
|
||||
is WalletsUpdateActionResolver.Action.InitializeWallets -> initializeWallets(action)
|
||||
is WalletsUpdateActionResolver.Action.ReinitializeWallet -> reinitializeWallet(action)
|
||||
is WalletsUpdateActionResolver.Action.ReinitializeNewWallet -> reinitializeNewWallet(action)
|
||||
is WalletsUpdateActionResolver.Action.ReinitializeWallets -> reinitializeWallets(action)
|
||||
is WalletsUpdateActionResolver.Action.AddWallet -> addWallet(action)
|
||||
is WalletsUpdateActionResolver.Action.DeleteWallet -> deleteWallet(action)
|
||||
|
|
@ -537,7 +537,7 @@ internal class WalletModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun reinitializeWallet(action: WalletsUpdateActionResolver.Action.ReinitializeWallet) {
|
||||
private fun reinitializeNewWallet(action: WalletsUpdateActionResolver.Action.ReinitializeNewWallet) {
|
||||
walletScreenContentLoader.cancel(action.prevWalletId)
|
||||
tokenListStore.remove(action.prevWalletId)
|
||||
|
||||
|
|
@ -550,7 +550,7 @@ internal class WalletModel @Inject constructor(
|
|||
fetchWalletContent(userWallet = action.selectedWallet)
|
||||
|
||||
stateHolder.update(
|
||||
ReinitializeWalletTransformer(
|
||||
ReinitializeNewWalletTransformer(
|
||||
prevWalletId = action.prevWalletId,
|
||||
newUserWallet = action.selectedWallet,
|
||||
clickIntents = clickIntents,
|
||||
|
|
@ -570,14 +570,11 @@ internal class WalletModel @Inject constructor(
|
|||
coroutineScope = modelScope,
|
||||
)
|
||||
|
||||
modelScope.launch(dispatchers.main) {
|
||||
fetchWalletContent(userWallet = userWallet)
|
||||
}
|
||||
fetchWalletContent(userWallet = userWallet)
|
||||
|
||||
stateHolder.update(
|
||||
ReinitializeWalletTransformer(
|
||||
prevWalletId = userWallet.walletId,
|
||||
newUserWallet = userWallet,
|
||||
userWallet = userWallet,
|
||||
clickIntents = clickIntents,
|
||||
walletImageResolver = walletImageResolver,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ internal class WalletsUpdateActionResolver @Inject constructor(
|
|||
getChangeWalletsListAction(state, wallets, selectedWallet)
|
||||
}
|
||||
isAnotherWalletSelected(state, selectedWallet) -> {
|
||||
Action.ReinitializeWallet(
|
||||
Action.ReinitializeNewWallet(
|
||||
prevWalletId = state.getPrevSelectedWallet().id,
|
||||
selectedWallet = selectedWallet,
|
||||
)
|
||||
|
|
@ -291,7 +291,7 @@ internal class WalletsUpdateActionResolver @Inject constructor(
|
|||
* @property prevWalletId previous selected wallet id
|
||||
* @property selectedWallet selected wallet
|
||||
*/
|
||||
data class ReinitializeWallet(
|
||||
data class ReinitializeNewWallet(
|
||||
val prevWalletId: UserWalletId,
|
||||
val selectedWallet: UserWallet,
|
||||
) : Action() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.state.transformers
|
||||
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
|
||||
import com.tangem.feature.wallet.presentation.wallet.domain.WalletImageResolver
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
/**
|
||||
* Reinitialize and place new wallet at the end transformer
|
||||
*
|
||||
* @property prevWalletId reinitialized wallet id
|
||||
* @property newUserWallet new user wallet
|
||||
* @property clickIntents click intents
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal class ReinitializeNewWalletTransformer(
|
||||
private val prevWalletId: UserWalletId,
|
||||
private val newUserWallet: UserWallet,
|
||||
private val clickIntents: WalletClickIntents,
|
||||
private val walletImageResolver: WalletImageResolver,
|
||||
) : WalletScreenStateTransformer {
|
||||
|
||||
private val walletLoadingStateFactory by lazy {
|
||||
WalletLoadingStateFactory(
|
||||
clickIntents = clickIntents,
|
||||
walletImageResolver = walletImageResolver,
|
||||
)
|
||||
}
|
||||
|
||||
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
||||
return prevState.copy(
|
||||
wallets = prevState.wallets
|
||||
.filterNot { it.walletCardState.id == prevWalletId }
|
||||
.plus(
|
||||
element = walletLoadingStateFactory.create(
|
||||
userWallet = newUserWallet,
|
||||
),
|
||||
)
|
||||
.toImmutableList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +1,23 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.state.transformers
|
||||
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
|
||||
import com.tangem.feature.wallet.presentation.wallet.domain.WalletImageResolver
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
/**
|
||||
* Reinitialize wallet transformer
|
||||
*
|
||||
* @property prevWalletId reinitialized wallet id
|
||||
* @property newUserWallet new user wallet
|
||||
* @property clickIntents click intents
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
* @property userWallet user wallet to reinitialize
|
||||
* @property clickIntents click intents
|
||||
* @property walletImageResolver wallet image resolver
|
||||
*/
|
||||
internal class ReinitializeWalletTransformer(
|
||||
private val prevWalletId: UserWalletId,
|
||||
private val newUserWallet: UserWallet,
|
||||
private val userWallet: UserWallet,
|
||||
private val clickIntents: WalletClickIntents,
|
||||
private val walletImageResolver: WalletImageResolver,
|
||||
) : WalletScreenStateTransformer {
|
||||
) : WalletStateTransformer(userWalletId = userWallet.walletId) {
|
||||
|
||||
private val walletLoadingStateFactory by lazy {
|
||||
WalletLoadingStateFactory(
|
||||
|
|
@ -31,16 +26,9 @@ internal class ReinitializeWalletTransformer(
|
|||
)
|
||||
}
|
||||
|
||||
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
||||
return prevState.copy(
|
||||
wallets = prevState.wallets
|
||||
.filterNot { it.walletCardState.id == prevWalletId }
|
||||
.plus(
|
||||
element = walletLoadingStateFactory.create(
|
||||
userWallet = newUserWallet,
|
||||
),
|
||||
)
|
||||
.toImmutableList(),
|
||||
override fun transform(prevState: WalletState): WalletState {
|
||||
return walletLoadingStateFactory.create(
|
||||
userWallet = userWallet,
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue