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

Add option to customize price change display on coins #7517

Merged
merged 4 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
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ dependencies {
implementation 'com.github.horizontalsystems:ethereum-kit-android:3d83900'
implementation 'com.github.horizontalsystems:blockchain-fee-rate-kit-android:1d3bd49'
implementation 'com.github.horizontalsystems:binance-chain-kit-android:c1509a2'
implementation 'com.github.horizontalsystems:market-kit-android:872cb04'
implementation 'com.github.horizontalsystems:market-kit-android:de765ab'
implementation 'com.github.horizontalsystems:solana-kit-android:ec238b4'
implementation 'com.github.horizontalsystems:tron-kit-android:dc3dca7'
// Zcash SDK
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/io/horizontalsystems/bankwallet/core/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import io.horizontalsystems.bankwallet.core.managers.NftAdapterManager
import io.horizontalsystems.bankwallet.core.managers.NftMetadataManager
import io.horizontalsystems.bankwallet.core.managers.NftMetadataSyncer
import io.horizontalsystems.bankwallet.core.managers.NumberFormatter
import io.horizontalsystems.bankwallet.core.managers.PriceManager
import io.horizontalsystems.bankwallet.core.managers.RateAppManager
import io.horizontalsystems.bankwallet.core.managers.ReleaseNotesManager
import io.horizontalsystems.bankwallet.core.managers.RestoreSettingsManager
Expand Down Expand Up @@ -171,6 +172,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {
lateinit var termsManager: ITermsManager
lateinit var marketFavoritesManager: MarketFavoritesManager
lateinit var marketKit: MarketKitWrapper
lateinit var priceManager: PriceManager
lateinit var releaseNotesManager: ReleaseNotesManager
lateinit var restoreSettingsManager: RestoreSettingsManager
lateinit var evmSyncSourceManager: EvmSyncSourceManager
Expand Down Expand Up @@ -233,6 +235,8 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {
subscriptionManager = subscriptionManager
)

priceManager = PriceManager(localStorage)

feeRateProvider = FeeRateProvider(appConfigProvider)
backgroundManager = BackgroundManager(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.horizontalsystems.bankwallet.modules.market.TimeDuration
import io.horizontalsystems.bankwallet.modules.market.Value
import io.horizontalsystems.bankwallet.modules.market.favorites.WatchlistSorting
import io.horizontalsystems.bankwallet.modules.settings.appearance.AppIcon
import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval
import io.horizontalsystems.bankwallet.modules.settings.security.autolock.AutoLockInterval
import io.horizontalsystems.bankwallet.modules.settings.security.tor.TorStatus
import io.horizontalsystems.bankwallet.modules.settings.terms.TermsModule
Expand Down Expand Up @@ -127,6 +128,9 @@ interface ILocalStorage {

val utxoExpertModeEnabledFlow: StateFlow<Boolean>

var priceChangeInterval: PriceChangeInterval
val priceChangeIntervalFlow: StateFlow<PriceChangeInterval>

fun clear()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import io.horizontalsystems.bankwallet.core.providers.Translator
import io.horizontalsystems.bankwallet.entities.AccountType
import io.horizontalsystems.bankwallet.entities.BitcoinCashCoinType
import io.horizontalsystems.bankwallet.entities.FeePriceScale
import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval
import io.horizontalsystems.bitcoincash.MainNetBitcoinCash
import io.horizontalsystems.hdwalletkit.ExtendedKeyCoinType
import io.horizontalsystems.hdwalletkit.HDWallet
import io.horizontalsystems.marketkit.models.Blockchain
import io.horizontalsystems.marketkit.models.BlockchainType
import io.horizontalsystems.marketkit.models.Coin
import io.horizontalsystems.marketkit.models.CoinPrice
import io.horizontalsystems.marketkit.models.FullCoin
import io.horizontalsystems.marketkit.models.HsPointTimePeriod
import io.horizontalsystems.marketkit.models.Token
import io.horizontalsystems.marketkit.models.TokenQuery
import io.horizontalsystems.marketkit.models.TokenType
import io.horizontalsystems.marketkit.models.TopPlatform
import io.horizontalsystems.nftkit.models.NftType
import java.math.BigDecimal

val Token.protocolType: String?
get() = tokenQuery.protocolType
Expand Down Expand Up @@ -574,4 +577,10 @@ val BlockchainType.Companion.supported: List<BlockchainType>
BlockchainType.ECash,
BlockchainType.Tron,
BlockchainType.Ton,
)
)

val CoinPrice.diff: BigDecimal?
get() = when (App.priceManager.priceChangeInterval) {
PriceChangeInterval.LAST_24H -> diff24h
PriceChangeInterval.FROM_UTC_MIDNIGHT -> diff1d
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.horizontalsystems.bankwallet.modules.market.MarketModule
import io.horizontalsystems.bankwallet.modules.market.TimeDuration
import io.horizontalsystems.bankwallet.modules.market.favorites.WatchlistSorting
import io.horizontalsystems.bankwallet.modules.settings.appearance.AppIcon
import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval
import io.horizontalsystems.bankwallet.modules.settings.security.autolock.AutoLockInterval
import io.horizontalsystems.bankwallet.modules.theme.ThemeType
import io.horizontalsystems.core.ILockoutStorage
Expand Down Expand Up @@ -83,6 +84,7 @@ class LocalStorageManager(
private val UTXO_EXPERT_MODE = "utxo_expert_mode"
private val RBF_ENABLED = "rbf_enabled"
private val STATS_SYNC_TIME = "stats_sync_time"
private val PRICE_CHANGE_INTERVAL = "price_change_interval"

private val _utxoExpertModeEnabledFlow = MutableStateFlow(false)
override val utxoExpertModeEnabledFlow = _utxoExpertModeEnabledFlow
Expand Down Expand Up @@ -531,4 +533,16 @@ class LocalStorageManager(
set(value) {
preferences.edit().putLong(STATS_SYNC_TIME, value).apply()
}

override var priceChangeInterval: PriceChangeInterval
get() = preferences.getString(PRICE_CHANGE_INTERVAL, null)?.let {
PriceChangeInterval.fromRaw(it)
} ?: PriceChangeInterval.LAST_24H
set(value) {
preferences.edit().putString(PRICE_CHANGE_INTERVAL, value.raw).apply()

priceChangeIntervalFlow.update { value }
}

override val priceChangeIntervalFlow = MutableStateFlow(priceChangeInterval)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.horizontalsystems.bankwallet.core.managers

import io.horizontalsystems.bankwallet.core.ILocalStorage
import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch

class PriceManager(
private val storage: ILocalStorage
) {
private val coroutineScope = CoroutineScope(Dispatchers.Default)

var priceChangeInterval: PriceChangeInterval = storage.priceChangeInterval
private set

val priceChangeIntervalFlow: StateFlow<PriceChangeInterval>
get() = storage.priceChangeIntervalFlow

init {
coroutineScope.launch {
storage.priceChangeIntervalFlow.collect {
priceChangeInterval = it
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ object BalanceModule {
App.localStorage,
App.wcManager,
AddressHandlerFactory(App.appConfigProvider.udnApiKey),
App.priceManager
) as T
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.horizontalsystems.bankwallet.modules.balance

import io.horizontalsystems.bankwallet.core.diff
import io.horizontalsystems.bankwallet.core.order
import java.math.BigDecimal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.Immutable
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.AdapterState
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.diff
import io.horizontalsystems.bankwallet.core.providers.CexAsset
import io.horizontalsystems.bankwallet.core.providers.Translator
import io.horizontalsystems.bankwallet.core.swappable
Expand Down Expand Up @@ -178,7 +179,6 @@ class BalanceViewItemFactory {
balanceViewType: BalanceViewType
): BalanceViewItem {
val wallet = item.wallet
val coin = wallet.coin
val state = item.state
val latestRate = item.coinPrice

Expand Down Expand Up @@ -261,7 +261,6 @@ class BalanceViewItemFactory {
networkAvailable: Boolean
): BalanceViewItem2 {
val wallet = item.wallet
val coin = wallet.coin
val state = item.state
val latestRate = item.coinPrice

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.horizontalsystems.bankwallet.core.AdapterState
import io.horizontalsystems.bankwallet.core.ILocalStorage
import io.horizontalsystems.bankwallet.core.ViewModelUiState
import io.horizontalsystems.bankwallet.core.factories.uriScheme
import io.horizontalsystems.bankwallet.core.managers.PriceManager
import io.horizontalsystems.bankwallet.core.providers.Translator
import io.horizontalsystems.bankwallet.core.stats.StatEvent
import io.horizontalsystems.bankwallet.core.stats.StatPage
Expand Down Expand Up @@ -44,6 +45,7 @@ class BalanceViewModel(
private val localStorage: ILocalStorage,
private val wCManager: WCManager,
private val addressHandlerFactory: AddressHandlerFactory,
private val priceManager: PriceManager
) : ViewModelUiState<BalanceUiState>(), ITotalBalance by totalBalance {

private var balanceViewType = balanceViewTypeManager.balanceViewTypeFlow.value
Expand Down Expand Up @@ -98,6 +100,12 @@ class BalanceViewModel(
}
}

viewModelScope.launch(Dispatchers.Default) {
priceManager.priceChangeIntervalFlow.collect {
refreshViewItems(service.balanceItemsFlow.value)
}
}

service.start()

totalBalance.start(viewModelScope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.lifecycle.viewModelScope
import io.horizontalsystems.bankwallet.core.AdapterState
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.managers.BalanceHiddenManager
import io.horizontalsystems.bankwallet.core.managers.ConnectivityManager
import io.horizontalsystems.bankwallet.core.managers.PriceManager
import io.horizontalsystems.bankwallet.core.providers.CexAsset
import io.horizontalsystems.bankwallet.modules.balance.BalanceViewItemFactory
import io.horizontalsystems.bankwallet.modules.balance.BalanceViewType
Expand All @@ -25,7 +25,7 @@ class CexAssetViewModel(
private val balanceHiddenManager: BalanceHiddenManager,
private val xRateRepository: BalanceXRateRepository,
private val balanceViewItemFactory: BalanceViewItemFactory,
private val connectivityManager: ConnectivityManager,
private val priceManager: PriceManager
) : ViewModel() {

private val title = cexAsset.id
Expand Down Expand Up @@ -53,6 +53,12 @@ class CexAssetViewModel(
updateBalanceViewItem()
}
}

viewModelScope.launch(Dispatchers.Default) {
priceManager.priceChangeIntervalFlow.collect {
updateBalanceViewItem()
}
}
}

fun toggleBalanceVisibility() {
Expand Down Expand Up @@ -102,8 +108,7 @@ class CexAssetViewModel(
App.balanceHiddenManager,
BalanceXRateRepository("cex-asset", App.currencyManager, App.marketKit),
BalanceViewItemFactory(),
App.connectivityManager,

App.priceManager
) as T
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.horizontalsystems.bankwallet.entities.Currency
import io.horizontalsystems.bankwallet.entities.CurrencyValue
import io.horizontalsystems.bankwallet.modules.market.filters.TimePeriod
import io.horizontalsystems.bankwallet.modules.metricchart.MetricsType
import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval
import io.horizontalsystems.bankwallet.ui.compose.TranslatableString
import io.horizontalsystems.bankwallet.ui.compose.WithTranslatableTitle
import io.horizontalsystems.marketkit.models.FullCoin
Expand Down Expand Up @@ -209,7 +210,12 @@ inline fun <T, R : Comparable<R>> Iterable<T>.sortedByNullLast(crossinline selec
}

fun MarketInfo.priceChangeValue(period: TimePeriod) = when (period) {
TimePeriod.TimePeriod_1D -> priceChange24h
TimePeriod.TimePeriod_1D -> {
when(App.priceManager.priceChangeInterval) {
PriceChangeInterval.LAST_24H -> priceChange24h
PriceChangeInterval.FROM_UTC_MIDNIGHT -> priceChange1d
}
}
TimePeriod.TimePeriod_1W -> priceChange7d
TimePeriod.TimePeriod_2W -> priceChange14d
TimePeriod.TimePeriod_1M -> priceChange30d
Expand All @@ -220,7 +226,7 @@ fun MarketInfo.priceChangeValue(period: TimePeriod) = when (period) {

@Parcelize
enum class TimeDuration(val titleResId: Int) : WithTranslatableTitle, Parcelable {
OneDay(R.string.Market_Filter_TimePeriod_24H),
OneDay(R.string.Market_Filter_TimePeriod_1D),
SevenDay(R.string.Market_Filter_TimePeriod_1W),
ThirtyDay(R.string.Market_Filter_TimePeriod_1M),
ThreeMonths(R.string.Market_Filter_TimePeriod_3M);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ object MarketFavoritesModule {
repository,
menuService,
App.currencyManager,
App.backgroundManager
App.backgroundManager,
App.priceManager
)
return MarketFavoritesViewModel(service) as T
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.horizontalsystems.bankwallet.modules.market.favorites

import io.horizontalsystems.bankwallet.core.managers.CurrencyManager
import io.horizontalsystems.bankwallet.core.managers.PriceManager
import io.horizontalsystems.bankwallet.entities.DataState
import io.horizontalsystems.bankwallet.modules.market.MarketItem
import io.horizontalsystems.bankwallet.modules.market.SortingField
Expand Down Expand Up @@ -34,7 +35,8 @@ class MarketFavoritesService(
private val repository: MarketFavoritesRepository,
private val menuService: MarketFavoritesMenuService,
private val currencyManager: CurrencyManager,
private val backgroundManager: BackgroundManager
private val backgroundManager: BackgroundManager,
private val priceManager: PriceManager
) : BackgroundManager.Listener {
private val coroutineScope = CoroutineScope(Dispatchers.Default)
private var favoritesJob: Job? = null
Expand Down Expand Up @@ -152,6 +154,12 @@ class MarketFavoritesService(
}
}

coroutineScope.launch {
priceManager.priceChangeIntervalFlow.collect {
fetch()
}
}

fetch()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object MarketTopCoinsModule {
topMarketsRepository,
App.currencyManager,
App.marketFavoritesManager,
App.priceManager,
topMarket ?: defaultTopMarket,
sortingField ?: defaultSortingField,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.horizontalsystems.bankwallet.modules.market.topcoins

import io.horizontalsystems.bankwallet.core.managers.CurrencyManager
import io.horizontalsystems.bankwallet.core.managers.MarketFavoritesManager
import io.horizontalsystems.bankwallet.core.managers.PriceManager
import io.horizontalsystems.bankwallet.entities.DataState
import io.horizontalsystems.bankwallet.modules.market.MarketItem
import io.horizontalsystems.bankwallet.modules.market.SortingField
Expand All @@ -21,6 +22,7 @@ class MarketTopCoinsService(
private val marketTopMoversRepository: MarketTopMoversRepository,
private val currencyManager: CurrencyManager,
private val favoritesManager: MarketFavoritesManager,
private val priceManager: PriceManager,
topMarket: TopMarket = TopMarket.Top100,
sortingField: SortingField = SortingField.HighestCap,
) {
Expand Down Expand Up @@ -108,6 +110,12 @@ class MarketTopCoinsService(
}
}

coroutineScope.launch {
priceManager.priceChangeIntervalFlow.collect {
sync()
}
}

sync()
}

Expand Down
Loading
Loading