Skip to content

Commit

Permalink
Make fixes in Markets
Browse files Browse the repository at this point in the history
- Fix scroll to top
- Remove extra divider in Pairs
  • Loading branch information
rafaelekol committed Jun 7, 2024
1 parent 2ac7af8 commit 41e1b4a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ fun EtfPage(
ViewState.Success -> {
val listState = rememberSaveable(
uiState.sortBy,
uiState.timeDuration,
saver = LazyListState.Saver
) {
LazyListState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.horizontalsystems.bankwallet.modules.market.etf.EtfModule.EtfViewItem
import io.horizontalsystems.marketkit.models.Etf
import io.horizontalsystems.marketkit.models.EtfPoint
import io.horizontalsystems.marketkit.models.HsTimePeriod
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -90,6 +91,8 @@ class EtfViewModel(
updateViewItems()

viewState = ViewState.Success
} catch (e: CancellationException) {
// no-op
} catch (e: Throwable) {
viewState = ViewState.Error(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ fun MarketFavoritesScreen(
onSelect = { selected ->
manualOrderEnabled = false
openSortingSelector = false
scrollToTopAfterUpdate = true
viewModel.onSelectSortingField(selected)

stat(page = StatPage.Markets, section = StatSection.Watchlist, event = StatEvent.SwitchSortType(selected.statSortType))
Expand All @@ -183,8 +184,9 @@ fun MarketFavoritesScreen(
title = R.string.CoinPage_Period,
select = Select(uiState.period, viewModel.periods),
onSelect = { selected ->
viewModel.onSelectPeriod(selected)
openPeriodSelector = false
scrollToTopAfterUpdate = true
viewModel.onSelectPeriod(selected)

stat(page = StatPage.Markets, section = StatSection.Watchlist, event = StatEvent.SwitchPeriod(selected.statPeriod))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.horizontalsystems.core.BackgroundManager
import io.horizontalsystems.marketkit.models.Analytics
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -73,6 +74,8 @@ class MarketFavoritesService(
if (menuService.showSignals) {
syncSignals()
}
} catch (e: CancellationException) {
// no-op
} catch (e: Throwable) {
marketItemsSubject.onNext(DataState.Error(e))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class MarketFiltersViewModel(val service: MarketFiltersService)
solidDexOn = false
goodDistributionOn = false
selectedBlockchains = emptyList()
filterTradingSignal = FilterViewItemWrapper.getAny()
updateSelectedBlockchains()
emitState()
reloadData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.horizontalsystems.bankwallet.modules.market.TimeDuration
import io.horizontalsystems.bankwallet.modules.market.TopMarket
import io.horizontalsystems.bankwallet.modules.market.category.MarketItemWrapper
import io.reactivex.subjects.BehaviorSubject
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -26,7 +27,7 @@ class MarketTopCoinsService(
topMarket: TopMarket = TopMarket.Top100,
sortingField: SortingField = SortingField.HighestCap,
) {
private val coroutineScope = CoroutineScope(Dispatchers.Default)
private val coroutineScope = CoroutineScope(Dispatchers.IO)
private var syncJob: Job? = null

private var marketItems: List<MarketItem> = listOf()
Expand Down Expand Up @@ -84,6 +85,8 @@ class MarketTopCoinsService(
).await()

syncItems()
} catch (e: CancellationException) {
//do nothing
} catch (e: Throwable) {
stateObservable.onNext(DataState.Error(e))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ fun TopCoins(
onSelect = { selected ->
viewModel.onSelectPeriod(selected)
openPeriodSelector = false
scrollToTopAfterUpdate = true

stat(page = StatPage.Markets, section = StatSection.Coins, event = StatEvent.SwitchPeriod(selected.statPeriod))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -56,6 +58,10 @@ fun TopPairsScreen() {
val uiState = viewModel.uiState
val context = LocalContext.current

val state = rememberSaveable(uiState.sortDescending, saver = LazyListState.Saver) {
LazyListState(0, 0)
}

Scaffold(
backgroundColor = ComposeAppTheme.colors.tyler,
) {
Expand All @@ -79,6 +85,7 @@ fun TopPairsScreen() {

ViewState.Success -> {
LazyColumn(
state = state,
modifier = Modifier.fillMaxSize()
) {
stickyHeader {
Expand All @@ -98,7 +105,7 @@ fun TopPairsScreen() {
}
}
itemsIndexed(uiState.items) { i, item ->
TopPairItem(item, borderTop = i == 0, borderBottom = true) {
TopPairItem(item, borderBottom = true) {
it.tradeUrl?.let {
LinkHelper.openLinkInAppBrowser(context, it)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.horizontalsystems.bankwallet.core.stats.StatSortType
import io.horizontalsystems.bankwallet.core.stats.stat
import io.horizontalsystems.bankwallet.entities.ViewState
import io.horizontalsystems.bankwallet.modules.market.overview.TopPairViewItem
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -63,6 +64,8 @@ class TopPairsViewModel(
}
items = sortItems(pairs)
viewState = ViewState.Success
} catch (e: CancellationException) {
// no-op
} catch (e: Throwable) {
viewState = ViewState.Error(e)
}
Expand Down

0 comments on commit 41e1b4a

Please sign in to comment.