From 1801117fe02a661c8512c2b7b56196a91a2dcdfb Mon Sep 17 00:00:00 2001 From: Rafael Date: Mon, 10 Jun 2024 12:31:50 +0600 Subject: [PATCH] Show MCap as subtitle instead of coin name --- .../modules/market/MarketViewItem.kt | 47 ++----------------- .../category/MarketCategoryViewModel.kt | 2 +- .../MarketFiltersResultViewModel.kt | 19 +------- .../platform/MarketPlatformCoinsRepository.kt | 14 +++++- .../platform/MarketPlatformViewModel.kt | 25 ++-------- .../market/topcoins/MarketTopCoinsModule.kt | 6 +-- .../topcoins/MarketTopCoinsViewModel.kt | 4 +- .../modules/market/topcoins/TopCoins.kt | 2 - .../compose/components/CoinListOrderable.kt | 4 +- 9 files changed, 27 insertions(+), 96 deletions(-) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketViewItem.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketViewItem.kt index 5269d17f408..5415cd7bb49 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketViewItem.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketViewItem.kt @@ -53,7 +53,11 @@ data class MarketViewItem( ): MarketViewItem { return MarketViewItem( marketItem.fullCoin, - marketItem.fullCoin.coin.name, + App.numberFormatter.formatFiatShort( + marketItem.marketCap.value, + marketItem.marketCap.currency.symbol, + 2 + ), App.numberFormatter.formatFiatFull( marketItem.rate.value, marketItem.rate.currency.symbol @@ -64,46 +68,5 @@ data class MarketViewItem( advice ) } - - fun create( - marketItem: MarketItem, - marketField: MarketField, - favorited: Boolean = false, - ): MarketViewItem { - val marketDataValue = when (marketField) { - MarketField.MarketCap -> { - val marketCapFormatted = App.numberFormatter.formatFiatShort( - marketItem.marketCap.value, - marketItem.marketCap.currency.symbol, - 2 - ) - - MarketDataValue.MarketCap(marketCapFormatted) - } - MarketField.Volume -> { - val volumeFormatted = App.numberFormatter.formatFiatShort( - marketItem.volume.value, - marketItem.volume.currency.symbol, - 2 - ) - - MarketDataValue.Volume(volumeFormatted) - } - MarketField.PriceDiff -> { - MarketDataValue.Diff(marketItem.diff) - } - } - return MarketViewItem( - marketItem.fullCoin, - marketItem.fullCoin.coin.name, - App.numberFormatter.formatFiatFull( - marketItem.rate.value, - marketItem.rate.currency.symbol - ), - marketDataValue, - marketItem.rank?.toString(), - favorited - ) - } } } \ No newline at end of file diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/category/MarketCategoryViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/category/MarketCategoryViewModel.kt index 5ddbd00e9d7..76a03dbc5f8 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/category/MarketCategoryViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/category/MarketCategoryViewModel.kt @@ -83,7 +83,7 @@ class MarketCategoryViewModel( private fun syncMarketViewItems() { viewItemsLiveData.postValue( marketItems.map { - MarketViewItem.create(it.marketItem, marketField, it.favorited) + MarketViewItem.create(it.marketItem, it.favorited) } ) } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/filtersresult/MarketFiltersResultViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/filtersresult/MarketFiltersResultViewModel.kt index e27422aaf96..de3ecb135e7 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/filtersresult/MarketFiltersResultViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/filtersresult/MarketFiltersResultViewModel.kt @@ -1,10 +1,8 @@ package io.horizontalsystems.bankwallet.modules.market.filtersresult import androidx.lifecycle.viewModelScope -import io.horizontalsystems.bankwallet.core.App import io.horizontalsystems.bankwallet.core.ViewModelUiState import io.horizontalsystems.bankwallet.entities.ViewState -import io.horizontalsystems.bankwallet.modules.market.MarketDataValue import io.horizontalsystems.bankwallet.modules.market.MarketViewItem import io.horizontalsystems.bankwallet.modules.market.SortingField import io.horizontalsystems.bankwallet.modules.market.category.MarketItemWrapper @@ -69,22 +67,7 @@ class MarketFiltersResultViewModel( private fun syncMarketViewItems() { viewItemsState = marketItems.map { itemWrapper -> - val marketCap = App.numberFormatter.formatFiatShort( - itemWrapper.marketItem.marketCap.value, - itemWrapper.marketItem.marketCap.currency.symbol, - 2 - ) - MarketViewItem( - fullCoin = itemWrapper.marketItem.fullCoin, - subtitle = marketCap, - value = App.numberFormatter.formatFiatFull( - itemWrapper.marketItem.rate.value, - itemWrapper.marketItem.rate.currency.symbol - ), - marketDataValue = MarketDataValue.Diff(itemWrapper.marketItem.diff), - rank = itemWrapper.marketItem.rank?.toString(), - favorited = itemWrapper.favorited - ) + MarketViewItem.create(itemWrapper.marketItem, itemWrapper.favorited) }.toList() } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/platform/MarketPlatformCoinsRepository.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/platform/MarketPlatformCoinsRepository.kt index 22f34c94fee..bb397d8ab9f 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/platform/MarketPlatformCoinsRepository.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/platform/MarketPlatformCoinsRepository.kt @@ -2,6 +2,7 @@ package io.horizontalsystems.bankwallet.modules.market.platform import io.horizontalsystems.bankwallet.core.managers.CurrencyManager import io.horizontalsystems.bankwallet.core.managers.MarketKitWrapper +import io.horizontalsystems.bankwallet.entities.CurrencyValue import io.horizontalsystems.bankwallet.modules.market.MarketItem import io.horizontalsystems.bankwallet.modules.market.SortingField import io.horizontalsystems.bankwallet.modules.market.sort @@ -9,6 +10,7 @@ import io.horizontalsystems.bankwallet.modules.market.topplatforms.Platform import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.rx2.await import kotlinx.coroutines.withContext +import java.math.BigDecimal class MarketPlatformCoinsRepository( private val platform: Platform, @@ -25,12 +27,20 @@ class MarketPlatformCoinsRepository( val currentCache = itemsCache val items = if (forceRefresh || currentCache == null) { + val currency = currencyManager.baseCurrency val marketInfoItems = marketKit - .topPlatformCoinListSingle(platform.uid, currencyManager.baseCurrency.code) + .topPlatformCoinListSingle(platform.uid, currency.code) .await() marketInfoItems.map { marketInfo -> - MarketItem.createFromCoinMarket(marketInfo, currencyManager.baseCurrency) + MarketItem( + fullCoin = marketInfo.fullCoin, + volume = CurrencyValue(currency, marketInfo.totalVolume ?: BigDecimal.ZERO), + rate = CurrencyValue(currency, marketInfo.price ?: BigDecimal.ZERO), + diff = marketInfo.priceChange24h, + marketCap = CurrencyValue(currency, marketInfo.marketCap ?: BigDecimal.ZERO), + rank = marketInfo.marketCapRank + ) } } else { currentCache diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/platform/MarketPlatformViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/platform/MarketPlatformViewModel.kt index 98a6c59ad46..26eae92e833 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/platform/MarketPlatformViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/platform/MarketPlatformViewModel.kt @@ -2,14 +2,12 @@ package io.horizontalsystems.bankwallet.modules.market.platform import androidx.lifecycle.viewModelScope import io.horizontalsystems.bankwallet.R -import io.horizontalsystems.bankwallet.core.App import io.horizontalsystems.bankwallet.core.ViewModelUiState import io.horizontalsystems.bankwallet.core.iconUrl import io.horizontalsystems.bankwallet.core.managers.MarketFavoritesManager import io.horizontalsystems.bankwallet.core.providers.Translator import io.horizontalsystems.bankwallet.entities.ViewState import io.horizontalsystems.bankwallet.modules.market.ImageSource -import io.horizontalsystems.bankwallet.modules.market.MarketDataValue import io.horizontalsystems.bankwallet.modules.market.MarketItem import io.horizontalsystems.bankwallet.modules.market.MarketModule import io.horizontalsystems.bankwallet.modules.market.MarketViewItem @@ -111,25 +109,10 @@ class MarketPlatformViewModel( emitState() } - private fun marketViewItem(item: MarketItem): MarketViewItem { - val marketCap = App.numberFormatter.formatFiatShort( - item.marketCap.value, - item.marketCap.currency.symbol, - 2 - ) - return MarketViewItem( - fullCoin = item.fullCoin, - subtitle = marketCap, - value = App.numberFormatter.formatFiatFull( - item.rate.value, - item.rate.currency.symbol - ), - marketDataValue = MarketDataValue.Diff(item.diff), - rank = item.rank?.toString(), - favorited = favoritesManager.getAll().map { it.coinUid } - .contains(item.fullCoin.coin.uid) - ) - } + private fun marketViewItem(item: MarketItem): MarketViewItem = MarketViewItem.create( + marketItem = item, + favorited = favoritesManager.getAll().map { it.coinUid }.contains(item.fullCoin.coin.uid) + ) private fun refreshWithMinLoadingSpinnerPeriod() { viewModelScope.launch { diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsModule.kt index ae6c8ef6e42..3fc441d7cd3 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsModule.kt @@ -16,7 +16,6 @@ object MarketTopCoinsModule { class Factory( private val topMarket: TopMarket? = null, private val sortingField: SortingField? = null, - private val marketField: MarketField? = null ) : ViewModelProvider.Factory { @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T { @@ -29,10 +28,7 @@ object MarketTopCoinsModule { topMarket ?: defaultTopMarket, sortingField ?: defaultSortingField, ) - return MarketTopCoinsViewModel( - service, - marketField ?: defaultMarketField - ) as T + return MarketTopCoinsViewModel(service) as T } companion object { diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsViewModel.kt index 6743d491a2f..fae56c879fc 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsViewModel.kt @@ -4,7 +4,6 @@ import androidx.lifecycle.viewModelScope import io.horizontalsystems.bankwallet.core.ViewModelUiState import io.horizontalsystems.bankwallet.entities.DataState import io.horizontalsystems.bankwallet.entities.ViewState -import io.horizontalsystems.bankwallet.modules.market.MarketField import io.horizontalsystems.bankwallet.modules.market.MarketViewItem import io.horizontalsystems.bankwallet.modules.market.SortingField import io.horizontalsystems.bankwallet.modules.market.TimeDuration @@ -16,7 +15,6 @@ import kotlinx.coroutines.rx2.asFlow class MarketTopCoinsViewModel( private val service: MarketTopCoinsService, - private var marketField: MarketField, ) : ViewModelUiState() { private var marketItems: List = listOf() @@ -63,7 +61,7 @@ class MarketTopCoinsViewModel( private fun syncMarketViewItems() { viewItems = marketItems.map { - MarketViewItem.create(it.marketItem, marketField, it.favorited) + MarketViewItem.create(it.marketItem, it.favorited) } emitState() } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/TopCoins.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/TopCoins.kt index 63f7f0fb6a5..a0ff6eef149 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/TopCoins.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/TopCoins.kt @@ -23,7 +23,6 @@ import io.horizontalsystems.bankwallet.core.stats.statPeriod import io.horizontalsystems.bankwallet.core.stats.statSortType import io.horizontalsystems.bankwallet.entities.ViewState import io.horizontalsystems.bankwallet.modules.coin.overview.ui.Loading -import io.horizontalsystems.bankwallet.modules.market.MarketField import io.horizontalsystems.bankwallet.modules.market.SortingField import io.horizontalsystems.bankwallet.modules.market.TopMarket import io.horizontalsystems.bankwallet.ui.compose.HSSwipeRefresh @@ -43,7 +42,6 @@ fun TopCoins( factory = MarketTopCoinsModule.Factory( TopMarket.Top100, SortingField.TopGainers, - MarketField.PriceDiff ) ) ) { diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/ui/compose/components/CoinListOrderable.kt b/app/src/main/java/io/horizontalsystems/bankwallet/ui/compose/components/CoinListOrderable.kt index 53b2e59c747..d329200909a 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/ui/compose/components/CoinListOrderable.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/ui/compose/components/CoinListOrderable.kt @@ -85,7 +85,7 @@ fun CoinListOrderable( MarketCoin( title = item.fullCoin.coin.code, - subtitle = item.fullCoin.coin.name, + subtitle = item.subtitle, coinIconUrl = item.fullCoin.coin.imageUrl, alternativeCoinIconUrl = item.fullCoin.coin.alternativeImageUrl, coinIconPlaceholder = item.fullCoin.iconPlaceholder, @@ -141,7 +141,7 @@ fun CoinListOrderable( content = { MarketCoin( title = item.fullCoin.coin.code, - subtitle = item.fullCoin.coin.name, + subtitle = item.subtitle, coinIconUrl = item.fullCoin.coin.imageUrl, alternativeCoinIconUrl = item.fullCoin.coin.alternativeImageUrl, coinIconPlaceholder = item.fullCoin.iconPlaceholder,