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

Show Mcap as subtitle in TopCoins and Watchlist #7540

Merged
merged 2 commits into from
Jun 10, 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 @@ -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 @@ -34,6 +34,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
Expand All @@ -49,17 +50,16 @@ import io.horizontalsystems.bankwallet.core.stats.StatPage
import io.horizontalsystems.bankwallet.core.stats.stat
import io.horizontalsystems.bankwallet.core.stats.statSection
import io.horizontalsystems.bankwallet.modules.coin.CoinFragment
import io.horizontalsystems.bankwallet.modules.market.MarketDataValue
import io.horizontalsystems.bankwallet.modules.market.search.MarketSearchModule.CoinItem
import io.horizontalsystems.bankwallet.modules.walletconnect.list.ui.DraggableCardSimple
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.HeaderStick
import io.horizontalsystems.bankwallet.ui.compose.components.HsImage
import io.horizontalsystems.bankwallet.ui.compose.components.ListEmptyView
import io.horizontalsystems.bankwallet.ui.compose.components.MarketCoinFirstRow
import io.horizontalsystems.bankwallet.ui.compose.components.MarketCoinSecondRow
import io.horizontalsystems.bankwallet.ui.compose.components.SearchBar
import io.horizontalsystems.bankwallet.ui.compose.components.SectionItemBorderedRowUniversalClear
import io.horizontalsystems.bankwallet.ui.compose.components.body_leah
import io.horizontalsystems.bankwallet.ui.compose.components.subhead2_grey
import io.horizontalsystems.marketkit.models.Coin
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -255,8 +255,6 @@ private fun MarketCoin(
alternativeCoinIconUrl: String?,
coinIconPlaceholder: Int,
onClick: () -> Unit,
coinRate: String? = null,
marketDataValue: MarketDataValue? = null,
) {

SectionItemBorderedRowUniversalClear(
Expand All @@ -275,9 +273,17 @@ private fun MarketCoin(
Column(
modifier = Modifier.weight(1f)
) {
MarketCoinFirstRow(coinCode, coinRate)
body_leah(
text = coinCode,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Spacer(modifier = Modifier.height(3.dp))
MarketCoinSecondRow(coinName, marketDataValue, null)
subhead2_grey(
text = coinName,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
}
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
Loading