Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sort menu icon on Balance page #7521

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.horizontalsystems.chartview.ChartViewType
import io.horizontalsystems.marketkit.models.HsTimePeriod
import io.reactivex.Single
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 @@ -86,6 +87,8 @@ abstract class AbstractChartService {
try {
val chartPointsWrapper = itemsSingle.await()
chartPointsWrapperObservable.onNext(Result.success(chartPointsWrapper))
} catch (e: CancellationException) {
// Do nothing
} catch (e: Throwable) {
chartPointsWrapperObservable.onNext(Result.failure(e))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ package io.horizontalsystems.bankwallet.modules.chart

import io.horizontalsystems.bankwallet.core.ILocalStorage
import io.horizontalsystems.chartview.models.ChartIndicator
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch
import kotlin.math.abs

class ChartIndicatorManager(
private val chartIndicatorSettingsDao: ChartIndicatorSettingsDao,
private val localStorage: ILocalStorage
) {
private val _isEnabledFlow = MutableStateFlow(localStorage.chartIndicatorsEnabled)
val isEnabledFlow: StateFlow<Boolean>
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
val isEnabled: Boolean
get() = localStorage.chartIndicatorsEnabled
private val _isEnabledFlow : MutableSharedFlow<Boolean> = MutableSharedFlow()
val isEnabledFlow: SharedFlow<Boolean>
get() = _isEnabledFlow

val allIndicatorsFlow = chartIndicatorSettingsDao.getAll()
Expand Down Expand Up @@ -71,12 +77,16 @@ class ChartIndicatorManager(

fun enable() {
localStorage.chartIndicatorsEnabled = true
_isEnabledFlow.update { true }
scope.launch {
_isEnabledFlow.emit(true)
}
}

fun disable() {
localStorage.chartIndicatorsEnabled = false
_isEnabledFlow.update { false }
scope.launch {
_isEnabledFlow.emit(false)
}
}

fun enableIndicator(indicatorId: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.horizontalsystems.bankwallet.modules.coin.overview

import android.util.Log
import io.horizontalsystems.bankwallet.core.diff
import io.horizontalsystems.bankwallet.core.managers.CurrencyManager
import io.horizontalsystems.bankwallet.core.managers.MarketKitWrapper
import io.horizontalsystems.bankwallet.core.stats.StatEvent
Expand Down Expand Up @@ -43,7 +42,7 @@ class CoinOverviewChartService(
private var chartStartTime: Long = 0
private val cache = mutableMapOf<String, Pair<Long, List<MarketKitChartPoint>>>()

private var indicatorsEnabled = chartIndicatorManager.isEnabledFlow.value
private var indicatorsEnabled = chartIndicatorManager.isEnabled

override suspend fun start() {
try {
Expand Down Expand Up @@ -169,7 +168,7 @@ class CoinOverviewChartService(

if (chartInterval == HsTimePeriod.Day1) {
startTimestampAdjusted = latestCoinPrice.timestamp - 24 * 60 * 60
val diff = latestCoinPrice.diff
val diff = latestCoinPrice.diff24h
if (diff != null) {
val startValue =
(latestCoinPrice.value * 100.toBigDecimal()) / (diff + 100.toBigDecimal())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.rx2.await
Expand All @@ -24,6 +25,7 @@ class CoinOverviewService(
) {
val currency get() = currencyManager.baseCurrency

private var job: Job? = null
private val coinOverviewSubject = BehaviorSubject.create<DataState<CoinOverviewItem>>()
val coinOverviewObservable: Observable<DataState<CoinOverviewItem>>
get() = coinOverviewSubject
Expand Down Expand Up @@ -54,10 +56,22 @@ class CoinOverviewService(
}

private fun fetchCoinOverview() {
coroutineScope.launch {
job = coroutineScope.launch {
try {
val marketInfoOverview = marketKit.marketInfoOverviewSingle(fullCoin.coin.uid, currencyManager.baseCurrency.code, languageManager.currentLanguage).await()
coinOverviewSubject.onNext(DataState.Success(CoinOverviewItem(fullCoin.coin.code, marketInfoOverview, guideUrl)))
val marketInfoOverview = marketKit.marketInfoOverviewSingle(
fullCoin.coin.uid,
currencyManager.baseCurrency.code,
languageManager.currentLanguage
).await()
coinOverviewSubject.onNext(
DataState.Success(
CoinOverviewItem(
fullCoin.coin.code,
marketInfoOverview,
guideUrl
)
)
)
} catch (e: Throwable) {
coinOverviewSubject.onNext(DataState.Error(e))
}
Expand All @@ -69,7 +83,7 @@ class CoinOverviewService(
}

fun refresh() {
stop()
job?.cancel()
start()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CoinOverviewViewModel(
var chartIndicatorsState by mutableStateOf(
ChartIndicatorsState(
hasActiveSubscription = true,
enabled = chartIndicatorManager.isEnabledFlow.value
enabled = chartIndicatorManager.isEnabled
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ fun ButtonSecondaryTransparent(
),
content = {
if (iconRight != null) {
Row {
Text(
title,
Row (
verticalAlignment = Alignment.CenterVertically
){
captionSB_leah(
text = title,
maxLines = 1,
style = ComposeAppTheme.typography.captionSB,
overflow = TextOverflow.Ellipsis,
overflow = TextOverflow.Ellipsis
)
Icon(
modifier = Modifier.padding(start = 4.dp),
Expand All @@ -158,7 +159,11 @@ fun ButtonSecondaryTransparent(
)
}
} else {
Text(title, maxLines = 1, overflow = TextOverflow.Ellipsis)
captionSB_leah(
text = title,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
},
enabled = enabled
Expand Down
Loading