Skip to content

Commit

Permalink
Fix updating sorting type in BalanceViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed Jun 4, 2024
1 parent 16afc95 commit 22ee681
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class BalanceViewModel(
private var errorMessage: String? = null
private var balanceTabButtonsEnabled = localStorage.balanceTabButtonsEnabled

val sortTypes =
private val sortTypes =
listOf(BalanceSortType.Value, BalanceSortType.Name, BalanceSortType.PercentGrowth)
var sortType by service::sortType
private var sortType = service.sortType

var connectionResult by mutableStateOf<WalletConnectListViewModel.ConnectionResult?>(null)
private set
Expand Down Expand Up @@ -118,7 +118,9 @@ class BalanceViewModel(
headerNote = headerNote(),
errorMessage = errorMessage,
openSend = openSendTokenSelect,
balanceTabButtonsEnabled = balanceTabButtonsEnabled
balanceTabButtonsEnabled = balanceTabButtonsEnabled,
sortType = sortType,
sortTypes = sortTypes,
)

private suspend fun handleUpdatedBalanceViewType(balanceViewType: BalanceViewType) {
Expand Down Expand Up @@ -192,6 +194,15 @@ class BalanceViewModel(
}
}

fun setSortType(sortType: BalanceSortType) {
this.sortType = sortType
emitState()

viewModelScope.launch(Dispatchers.Default) {
service.sortType = sortType
}
}

fun onCloseHeaderNote(headerNote: HeaderNote) {
when (headerNote) {
HeaderNote.NonRecommendedAccount -> {
Expand Down Expand Up @@ -347,6 +358,8 @@ data class BalanceUiState(
val errorMessage: String?,
val openSend: OpenSendTokenSelect? = null,
val balanceTabButtonsEnabled: Boolean,
val sortType: BalanceSortType,
val sortTypes: List<BalanceSortType>,
)

data class OpenSendTokenSelect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fun BalanceItems(
modifier = Modifier.fillMaxSize(),
state = rememberSaveable(
accountViewItem.id,
viewModel.sortType,
uiState.sortType,
saver = LazyListState.Saver
) {
LazyListState()
Expand Down Expand Up @@ -331,10 +331,10 @@ fun BalanceItems(
stickyHeader {
HeaderSorting {
BalanceSortingSelector(
sortType = viewModel.sortType,
sortTypes = viewModel.sortTypes
sortType = uiState.sortType,
sortTypes = uiState.sortTypes
) {
viewModel.sortType = it
viewModel.setSortType(it)
}

Spacer(modifier = Modifier.weight(1f))
Expand Down

0 comments on commit 22ee681

Please sign in to comment.