diff --git a/app/src/main/assets/tangem-app-config b/app/src/main/assets/tangem-app-config index 5fc86d29bc..7697824250 160000 --- a/app/src/main/assets/tangem-app-config +++ b/app/src/main/assets/tangem-app-config @@ -1 +1 @@ -Subproject commit 5fc86d29bc2c0dc7c057ab0242b2cfa3e9f48daf +Subproject commit 76978242504ab90803b99e2b0575f7ebe8e69335 diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt index 4b707d963b..b136451f60 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletModel.kt @@ -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, ), diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletsUpdateActionResolver.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletsUpdateActionResolver.kt index 82846a7624..d498e480a0 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletsUpdateActionResolver.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/WalletsUpdateActionResolver.kt @@ -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() { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeNewWalletTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeNewWalletTransformer.kt new file mode 100644 index 0000000000..d6072f30f7 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeNewWalletTransformer.kt @@ -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(), + ) + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeWalletTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeWalletTransformer.kt index 4f4fa993ca..4459476877 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeWalletTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/ReinitializeWalletTransformer.kt @@ -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, ) } } \ No newline at end of file