Skip to content

Commit

Permalink
Show MCap as subtitle instead of coin name
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Jun 10, 2024
1 parent 78092d7 commit 1801117
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ 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
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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T : ViewModel> create(modelClass: Class<T>): T {
Expand All @@ -29,10 +28,7 @@ object MarketTopCoinsModule {
topMarket ?: defaultTopMarket,
sortingField ?: defaultSortingField,
)
return MarketTopCoinsViewModel(
service,
marketField ?: defaultMarketField
) as T
return MarketTopCoinsViewModel(service) as T
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +15,6 @@ import kotlinx.coroutines.rx2.asFlow

class MarketTopCoinsViewModel(
private val service: MarketTopCoinsService,
private var marketField: MarketField,
) : ViewModelUiState<MarketTopCoinsModule.UiState>() {

private var marketItems: List<MarketItemWrapper> = listOf()
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +42,6 @@ fun TopCoins(
factory = MarketTopCoinsModule.Factory(
TopMarket.Top100,
SortingField.TopGainers,
MarketField.PriceDiff
)
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1801117

Please sign in to comment.