Skip to content

Commit

Permalink
Add sectors to Market Filters
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Jan 2, 2025
1 parent 63c2855 commit 18b2304
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ dependencies {
implementation 'com.github.horizontalsystems:ethereum-kit-android:0c770e3'
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:00b9f76'
implementation 'com.github.horizontalsystems:market-kit-android:ef4a068'
implementation 'com.github.horizontalsystems:solana-kit-android:ce738d8'
implementation 'com.github.horizontalsystems:tron-kit-android:dc3dca7'
// Zcash SDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class MarketKitWrapper(

fun marketInfosSingle(top: Int, currencyCode: String, defi: Boolean) = marketKit.marketInfosSingle(top, currencyCode, defi)

fun advancedMarketInfosSingle(top: Int = 250, currencyCode: String) = marketKit.advancedMarketInfosSingle(top, currencyCode)
fun categoriesSingle() = marketKit.getCategories()

fun advancedMarketInfosSingle(top: Int = 250, currencyCode: String, sectorId: Int?) = marketKit.advancedMarketInfosSingle(top, currencyCode, sectorId)

fun marketInfosSingle(coinUids: List<String>, currencyCode: String): Single<List<MarketInfo>> =
marketKit.marketInfosSingle(coinUids.removeCustomCoins(), currencyCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import io.horizontalsystems.bankwallet.modules.market.filters.MarketFiltersModul
import io.horizontalsystems.bankwallet.modules.market.filters.MarketFiltersModule.FilterDropdown.PriceChange
import io.horizontalsystems.bankwallet.modules.market.filters.MarketFiltersModule.FilterDropdown.PriceCloseTo
import io.horizontalsystems.bankwallet.modules.market.filters.MarketFiltersModule.FilterDropdown.PricePeriod
import io.horizontalsystems.bankwallet.modules.market.filters.MarketFiltersModule.FilterDropdown.SectorSet
import io.horizontalsystems.bankwallet.modules.market.filters.MarketFiltersModule.FilterDropdown.TradingSignals
import io.horizontalsystems.bankwallet.modules.market.filters.MarketFiltersModule.FilterDropdown.TradingVolume
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
Expand Down Expand Up @@ -273,6 +274,19 @@ private fun BottomSheetContent(
onClose = onClose
)
}

SectorSet -> {
SingleSelectBottomSheetContent(
title = R.string.Market_Filter_Sectors,
headerIcon = R.drawable.ic_ring_24,
items = viewModel.sectorsViewItemOptions,
selectedItem = uiState.sector,
onSelect = {
viewModel.setSector(it)
},
onClose = onClose
)
}
}
}

Expand Down Expand Up @@ -310,6 +324,20 @@ fun AdvancedSearchContent(

PremiumHeader()

SectionPremiumUniversalLawrence {
AdvancedSearchDropdown(
title = R.string.Market_Filter_Sectors,
value = uiState.sector.title,
onDropdownClick = {
navController.paidAction(AdvancedSearch) {
showBottomSheet(SectorSet)
}
}
)
}

VSpacer(24.dp)

SectionPremiumUniversalLawrence {
AdvancedSearchDropdown(
title = R.string.Market_Filter_PriceChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object MarketFiltersModule {
PricePeriod(R.string.Market_Filter_PricePeriod),
TradingSignals(R.string.Market_Filter_TradingSignals),
PriceCloseTo(R.string.Market_Filter_PriceCloseTo),
SectorSet(R.string.Market_Filter_Sectors),
}

data class BlockchainViewItem(val blockchain: Blockchain, val checked: Boolean)
Expand Down Expand Up @@ -228,6 +229,8 @@ enum class TextColor{
Remus, Lucian, Grey, Leah
}

data class SectorItem(val id: Int, val title: String)

class FilterViewItemWrapper<T>(val title: String?, val item: T) {
override fun equals(other: Any?) = when {
other !is FilterViewItemWrapper<*> -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MarketFiltersService(
val currencyCode = baseCurrency.code

var coinCount = CoinList.Top200.itemsCount
var sectorId: Int? = null
var filterMarketCap: Pair<Long?, Long?>? = null
var filterVolume: Pair<Long?, Long?>? = null
var filterPeriod = TimePeriod.TimePeriod_1D
Expand Down Expand Up @@ -80,11 +81,17 @@ class MarketFiltersService(
return getTopMarketList().await().size
}

suspend fun getSectors(): List<SectorItem> {
return marketKit.categoriesSingle().blockingGet().map { coinCategory ->
SectorItem(coinCategory.id, coinCategory.name)
}
}

private fun getTopMarketList(): Single<Map<Int, MarketInfo>> {
val topMarketListAsync = if (cache != null) {
Single.just(cache)
} else {
marketKit.advancedMarketInfosSingle(coinCount, baseCurrency.code)
marketKit.advancedMarketInfosSingle(coinCount, baseCurrency.code, sectorId)
.doOnSuccess {
cache = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.net.UnknownHostException

class MarketFiltersViewModel(val service: MarketFiltersService)
: ViewModelUiState<MarketFiltersUiState>() {
class MarketFiltersViewModel(val service: MarketFiltersService) :
ViewModelUiState<MarketFiltersUiState>() {

private var coinListSet: CoinList = CoinList.Top200
private var period = FilterViewItemWrapper(
Expand All @@ -26,7 +27,8 @@ class MarketFiltersViewModel(val service: MarketFiltersService)
private var marketCap = rangeEmpty
private var volume = rangeEmpty
private var priceChange = FilterViewItemWrapper.getAny<PriceChange>()
private var priceCloseTo:PriceCloseTo? = null
private var selectedSector = FilterViewItemWrapper.getAny<SectorItem>()
private var priceCloseTo: PriceCloseTo? = null
private var outperformedBtcOn = false
private var outperformedEthOn = false
private var outperformedBnbOn = false
Expand All @@ -41,9 +43,13 @@ class MarketFiltersViewModel(val service: MarketFiltersService)
private var buttonEnabled = false
private var buttonTitle = Translator.getString(R.string.Market_Filter_ShowResults)
private var errorMessage: TranslatableString? = null
private var sectors: List<SectorItem> = listOf()

private var reloadDataJob: Job? = null

val sectorsViewItemOptions: List<FilterViewItemWrapper<SectorItem?>>
get() = listOf(FilterViewItemWrapper.getAny<SectorItem>()) + sectors.map { FilterViewItemWrapper(it.title, it) }

val coinListsViewItemOptions = CoinList.entries
val marketCapViewItemOptions = getRanges(service.currencyCode)
val volumeViewItemOptions = getRanges(service.currencyCode)
Expand All @@ -60,10 +66,17 @@ class MarketFiltersViewModel(val service: MarketFiltersService)
}

init {
showSpinner = true
updateSelectedBlockchains()
emitState()
reloadData()
reloadDataWithSpinner()
loadSectors()
}

private fun loadSectors() {
viewModelScope.launch(Dispatchers.IO) {
withContext(Dispatchers.Default) {
sectors = service.getSectors()
}
}
}

override fun createState() = MarketFiltersUiState(
Expand All @@ -72,6 +85,7 @@ class MarketFiltersViewModel(val service: MarketFiltersService)
marketCap = marketCap,
volume = volume,
priceChange = priceChange,
sector = selectedSector,
priceCloseTo = priceCloseTo,
outperformedBtcOn = outperformedBtcOn,
outperformedEthOn = outperformedEthOn,
Expand All @@ -91,7 +105,6 @@ class MarketFiltersViewModel(val service: MarketFiltersService)
)

fun reset() {
updateCoinList(CoinList.Top200)
marketCap = rangeEmpty
volume = rangeEmpty
period = FilterViewItemWrapper(
Expand All @@ -109,13 +122,27 @@ class MarketFiltersViewModel(val service: MarketFiltersService)
selectedBlockchains = emptyList()
filterTradingSignal = FilterViewItemWrapper.getAny()
updateSelectedBlockchains()
emitState()
reloadData()

selectedSector = FilterViewItemWrapper.getAny()
service.sectorId = null
coinListSet = CoinList.Top200
service.coinCount = CoinList.Top200.itemsCount
reloadDataWithSpinner()
}

fun updateCoinList(value: CoinList) {
coinListSet = value
service.coinCount = value.itemsCount
reloadDataWithSpinner()
}

fun setSector(sectorItem: FilterViewItemWrapper<SectorItem?>) {
selectedSector = sectorItem
service.sectorId = sectorItem.item?.id
reloadDataWithSpinner()
}

private fun reloadDataWithSpinner() {
service.clearCache()
showSpinner = true
emitState()
Expand Down Expand Up @@ -288,6 +315,7 @@ data class MarketFiltersUiState(
val marketCap: FilterViewItemWrapper<Range?>,
val volume: FilterViewItemWrapper<Range?>,
val priceChange: FilterViewItemWrapper<PriceChange?>,
val sector: FilterViewItemWrapper<SectorItem?>,
val priceCloseTo: PriceCloseTo?,
val outperformedBtcOn: Boolean,
val outperformedEthOn: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.horizontalsystems.subscriptions.core.AddressVerification
import io.horizontalsystems.subscriptions.core.AdvancedSearch
import io.horizontalsystems.subscriptions.core.BasePlan
import io.horizontalsystems.subscriptions.core.DuressMode
import io.horizontalsystems.subscriptions.core.FavorableSwaps
import io.horizontalsystems.subscriptions.core.IPaidAction
import io.horizontalsystems.subscriptions.core.PricingPhase
import io.horizontalsystems.subscriptions.core.PrivacyMode
Expand All @@ -24,7 +23,6 @@ object BuySubscriptionModel {
TokenInsights -> R.string.Premium_UpgradeFeature_TokenInsights
AdvancedSearch -> R.string.Premium_UpgradeFeature_AdvancedSearch
TradeSignals -> R.string.Premium_UpgradeFeature_TradeSignals
FavorableSwaps -> R.string.Premium_UpgradeFeature_FavorableSwaps
TransactionSpeedTools -> R.string.Premium_UpgradeFeature_TxSpeedTools
DuressMode -> R.string.Premium_UpgradeFeature_DuressMode
AddressVerification -> R.string.Premium_UpgradeFeature_AddressVerification
Expand All @@ -40,7 +38,6 @@ object BuySubscriptionModel {
TokenInsights -> R.string.Premium_UpgradeFeature_TokenInsights_Description
AdvancedSearch -> R.string.Premium_UpgradeFeature_AdvancedSearch_Description
TradeSignals -> R.string.Premium_UpgradeFeature_TradeSignals_Description
FavorableSwaps -> R.string.Premium_UpgradeFeature_FavorableSwaps_Description
TransactionSpeedTools -> R.string.Premium_UpgradeFeature_TxSpeedTools_Description
DuressMode -> R.string.Premium_UpgradeFeature_DuressMode_Description
AddressVerification -> R.string.Premium_UpgradeFeature_AddressVerification_Description
Expand All @@ -56,7 +53,6 @@ object BuySubscriptionModel {
TokenInsights -> R.string.Premium_UpgradeFeature_TokenInsights_BigDescription
AdvancedSearch -> R.string.Premium_UpgradeFeature_AdvancedSearch_BigDescription
TradeSignals -> R.string.Premium_UpgradeFeature_TradeSignals_BigDescription
FavorableSwaps -> R.string.Premium_UpgradeFeature_FavorableSwaps_BigDescription
TransactionSpeedTools -> R.string.Premium_UpgradeFeature_TxSpeedTools_BigDescription
DuressMode -> R.string.Premium_UpgradeFeature_DuressMode_BigDescription
AddressVerification -> R.string.Premium_UpgradeFeature_AddressVerification_BigDescription
Expand All @@ -72,7 +68,6 @@ object BuySubscriptionModel {
TokenInsights -> R.drawable.prem_portfolio_24
AdvancedSearch -> R.drawable.prem_search_discovery_24
TradeSignals -> R.drawable.prem_ring_24
FavorableSwaps -> R.drawable.prem_percent_24
TransactionSpeedTools -> R.drawable.prem_outgoingraw_24
DuressMode -> R.drawable.prem_duress_24
AddressVerification -> R.drawable.prem_shield_24
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
<string name="Market_Filter_PricePeriod">Price Period</string>
<string name="Market_Filter_TradingSignals">Trading Signals</string>
<string name="Market_Filter_PriceChange">Price Change</string>
<string name="Market_Filter_Sectors">Sectors</string>
<string name="Market_PriceChange_24H">24 Hours</string>
<string name="Market_PriceChange_Utc">Midnight UTC</string>
<string name="Market_Filter_Blockchains">Blockchains</string>
Expand Down Expand Up @@ -907,7 +908,6 @@
<string name="Premium_UpgradeFeature_TokenInsights">Token Insights</string>
<string name="Premium_UpgradeFeature_AdvancedSearch">Advanced Search</string>
<string name="Premium_UpgradeFeature_TradeSignals">Trade Signals</string>
<string name="Premium_UpgradeFeature_FavorableSwaps">Favorable Swaps</string>
<string name="Premium_UpgradeFeature_TxSpeedTools">Transaction Speed Tools</string>
<string name="Premium_UpgradeFeature_DuressMode">Duress Mode</string>
<string name="Premium_UpgradeFeature_AddressVerification">Address Verification</string>
Expand All @@ -919,7 +919,6 @@
<string name="Premium_UpgradeFeature_TokenInsights_Description">Full analytics and data about tokens.</string>
<string name="Premium_UpgradeFeature_AdvancedSearch_Description">Custom filters for token searches.</string>
<string name="Premium_UpgradeFeature_TradeSignals_Description">Signals for confident trading.</string>
<string name="Premium_UpgradeFeature_FavorableSwaps_Description">Swaps with no extra fees.</string>
<string name="Premium_UpgradeFeature_TxSpeedTools_Description">Speed up and cancel transactions.</string>
<string name="Premium_UpgradeFeature_DuressMode_Description">Hides main wallets in case of coercion.</string>
<string name="Premium_UpgradeFeature_AddressVerification_Description">Additional address check for fraud prevention.</string>
Expand All @@ -931,7 +930,6 @@
<string name="Premium_UpgradeFeature_TokenInsights_BigDescription">Token Insights provides a comprehensive view of a token’s activity and performance metrics. This includes trading volume, liquidity levels, holder behavior, total value locked (TVL), and transaction activity. By offering detailed analytics, the feature enables users to evaluate token potential, monitor market trends, and make data-driven investment decisions. It’s a powerful tool for those who seek to understand token ecosystems and market dynamics in-depth.</string>
<string name="Premium_UpgradeFeature_AdvancedSearch_BigDescription">Custom filters for token searches.</string>
<string name="Premium_UpgradeFeature_TradeSignals_BigDescription">Signals for confident trading.</string>
<string name="Premium_UpgradeFeature_FavorableSwaps_BigDescription">Swaps with no extra fees.</string>
<string name="Premium_UpgradeFeature_TxSpeedTools_BigDescription">Speed up and cancel transactions.</string>
<string name="Premium_UpgradeFeature_DuressMode_BigDescription">Hides main wallets in case of coercion.</string>
<string name="Premium_UpgradeFeature_AddressVerification_BigDescription">Additional address check for fraud prevention.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ object AdvancedSearch : IPaidAction
@Parcelize
object TradeSignals : IPaidAction

@Parcelize
object FavorableSwaps : IPaidAction

@Parcelize
object TransactionSpeedTools : IPaidAction

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ object UserSubscriptionManager {
TokenInsights,
AdvancedSearch,
TradeSignals,
FavorableSwaps,
TransactionSpeedTools,
DuressMode,
AddressVerification,
Expand All @@ -30,7 +29,6 @@ object UserSubscriptionManager {
TokenInsights,
AdvancedSearch,
TradeSignals,
FavorableSwaps,
TransactionSpeedTools,
DuressMode,
AddressVerification,
Expand Down

0 comments on commit 18b2304

Please sign in to comment.