diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt index f403ba6e73..3f8672679f 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt @@ -8,8 +8,14 @@ import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState -import androidx.compose.material3.* -import androidx.compose.runtime.* +import androidx.compose.material3.FabPosition +import androidx.compose.material3.Scaffold +import androidx.compose.material3.SnackbarHost +import androidx.compose.material3.SnackbarHostState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.State +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource @@ -52,7 +58,9 @@ internal fun WalletScreen(state: WalletState) { when (state) { is WalletState.ContentState -> { - val walletsListState = rememberLazyListState() + val walletsListState = rememberLazyListState( + initialFirstVisibleItemIndex = state.walletsListConfig.selectedWalletIndex, + ) val snackbarHostState = remember { SnackbarHostState() } val isAutoScroll = remember { mutableStateOf(value = false) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index 17ee898f80..407c74998e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -62,6 +62,7 @@ import kotlin.properties.Delegates @Suppress("LargeClass", "LongParameterList", "TooManyFunctions") @HiltViewModel internal class WalletViewModel @Inject constructor( + // region Parameters private val getWalletsUseCase: GetWalletsUseCase, private val saveWalletUseCase: SaveWalletUseCase, getSelectedWalletUseCase: GetSelectedWalletUseCase, @@ -92,6 +93,7 @@ internal class WalletViewModel @Inject constructor( private val walletManagersFacade: WalletManagersFacade, private val reduxStateHolder: ReduxStateHolder, private val dispatchers: CoroutineDispatcherProvider, + // endregion Parameters ) : ViewModel(), DefaultLifecycleObserver, WalletClickIntents { /** Feature router */ @@ -161,8 +163,8 @@ internal class WalletViewModel @Inject constructor( if (sourceList.isEmpty()) return when (val action = walletsUpdateActionResolver.resolve(sourceList)) { - is WalletsUpdateActionResolver.Action.InitialWallets -> { - loadAndUpdateState(index = action.selectedWalletIndex) + is WalletsUpdateActionResolver.Action.Initialize -> { + loadAndUpdateState(action.selectedWalletIndex) } is WalletsUpdateActionResolver.Action.UpdateWalletName -> { uiState = stateFactory.getStateWithUpdatedWalletName(name = action.name) @@ -176,7 +178,7 @@ internal class WalletViewModel @Inject constructor( deleteWalletAndUpdateState(action = action) } is WalletsUpdateActionResolver.Action.AddWallet -> { - loadAndUpdateState(index = action.selectedWalletIndex) + loadAndUpdateState(action.selectedWalletIndex) } is WalletsUpdateActionResolver.Action.Unknown -> Unit } @@ -196,20 +198,14 @@ internal class WalletViewModel @Inject constructor( getContentItemsUpdates(action.selectedWalletIndex) } } else { - loadAndUpdateState(index = action.selectedWalletIndex) + loadAndUpdateState(selectedWalletIndex = action.selectedWalletIndex) } } - private fun loadAndUpdateState(index: Int) { - uiState = stateFactory.getSkeletonState(wallets = wallets, selectedWalletIndex = index) + private fun loadAndUpdateState(selectedWalletIndex: Int) { + uiState = stateFactory.getSkeletonState(wallets = wallets, selectedWalletIndex = selectedWalletIndex) - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = WalletEvent.ChangeWallet(index = index), - setUiState = { uiState = it }, - ) - - getContentItemsUpdates(index = index) + getContentItemsUpdates(index = selectedWalletIndex) } override fun onBackClick() { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolver.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolver.kt index dbcfee3f06..34c5eea823 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolver.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletsUpdateActionResolver.kt @@ -24,7 +24,7 @@ internal class WalletsUpdateActionResolver( return when (val state = currentStateProvider()) { is WalletState.Initial -> { - Action.InitialWallets( + Action.Initialize( selectedWalletIndex = wallets.indexOfWallet(id = selectedWallet.walletId), ) } @@ -138,7 +138,7 @@ internal class WalletsUpdateActionResolver( sealed class Action { - data class InitialWallets(val selectedWalletIndex: Int) : Action() + data class Initialize(val selectedWalletIndex: Int) : Action() data class UpdateWalletName(val name: String) : Action()