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 apiTag to required HsProvider requests #6856

Merged
merged 1 commit into from
Nov 29, 2023
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 @@ -277,7 +277,7 @@ dependencies {
implementation 'com.github.horizontalsystems:ethereum-kit-android:3a02f3a'
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:7f27adb'
implementation 'com.github.horizontalsystems:market-kit-android:193f1f6'
implementation 'com.github.horizontalsystems:solana-kit-android:34ef394'
implementation 'com.github.horizontalsystems:tron-kit-android:5eb6395'
// Zcash SDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {
MarketFavoritesMenuService(localStorage, marketWidgetManager),
TopNftCollectionsRepository(marketKit),
TopNftCollectionsViewItemFactory(numberFormatter),
TopPlatformsRepository(marketKit, currencyManager),
TopPlatformsRepository(marketKit, currencyManager, "widget"),
currencyManager
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,30 @@ class MarketKitWrapper(

fun blockchain(uid: String) = marketKit.blockchain(uid)

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

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

fun marketInfosSingle(coinUids: List<String>, currencyCode: String): Single<List<MarketInfo>> =
marketKit.marketInfosSingle(coinUids.removeCustomCoins(), currencyCode)
fun marketInfosSingle(coinUids: List<String>, currencyCode: String, apiTag: String): Single<List<MarketInfo>> =
marketKit.marketInfosSingle(coinUids.removeCustomCoins(), currencyCode, apiTag)

fun marketInfosSingle(categoryUid: String, currencyCode: String) = marketKit.marketInfosSingle(categoryUid, currencyCode)
fun marketInfosSingle(categoryUid: String, currencyCode: String, apiTag: String) = marketKit.marketInfosSingle(categoryUid, currencyCode, apiTag)

fun marketInfoOverviewSingle(coinUid: String, currencyCode: String, language: String) =
marketKit.marketInfoOverviewSingle(coinUid, currencyCode, language)
fun marketInfoOverviewSingle(coinUid: String, currencyCode: String, language: String, apiTag: String) =
marketKit.marketInfoOverviewSingle(coinUid, currencyCode, language, apiTag)

fun marketInfoDetailsSingle(coinUid: String, currencyCode: String) = marketKit.marketInfoDetailsSingle(coinUid, currencyCode)
fun analyticsSingle(coinUid: String, currencyCode: String, apiTag: String) =
requestWithAuthToken { marketKit.analyticsSingle(it, coinUid, currencyCode, apiTag) }

fun analyticsSingle(coinUid: String, currencyCode: String) =
requestWithAuthToken { marketKit.analyticsSingle(it, coinUid, currencyCode) }

fun analyticsPreviewSingle(coinUid: String, addresses: List<String>) = marketKit.analyticsPreviewSingle(coinUid, addresses)
fun analyticsPreviewSingle(coinUid: String, addresses: List<String>, apiTag: String) = marketKit.analyticsPreviewSingle(coinUid, addresses, apiTag)

fun marketInfoTvlSingle(coinUid: String, currencyCode: String, timePeriod: HsTimePeriod) =
marketKit.marketInfoTvlSingle(coinUid, currencyCode, timePeriod)

fun marketInfoGlobalTvlSingle(chain: String, currencyCode: String, timePeriod: HsTimePeriod) =
marketKit.marketInfoGlobalTvlSingle(chain, currencyCode, timePeriod)

fun defiMarketInfosSingle(currencyCode: String) = marketKit.defiMarketInfosSingle(currencyCode)
fun defiMarketInfosSingle(currencyCode: String, apiTag: String) = marketKit.defiMarketInfosSingle(currencyCode, apiTag)

// Categories

Expand Down Expand Up @@ -238,14 +236,14 @@ class MarketKitWrapper(
fun globalMarketPointsSingle(currencyCode: String, timePeriod: HsTimePeriod) =
marketKit.globalMarketPointsSingle(currencyCode, timePeriod)

fun topPlatformsSingle(currencyCode: String) =
marketKit.topPlatformsSingle(currencyCode)
fun topPlatformsSingle(currencyCode: String, apiTag: String) =
marketKit.topPlatformsSingle(currencyCode, apiTag)

fun topPlatformMarketCapPointsSingle(chain: String, timePeriod: HsTimePeriod, currencyCode: String) =
marketKit.topPlatformMarketCapPointsSingle(chain, timePeriod, currencyCode)

fun topPlatformCoinListSingle(chain: String, currencyCode: String) =
marketKit.topPlatformCoinListSingle(chain, currencyCode)
fun topPlatformCoinListSingle(chain: String, currencyCode: String, apiTag: String) =
marketKit.topPlatformMarketInfosSingle(chain, currencyCode, apiTag)

// NFT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private fun ButtonsRow(viewItem: BalanceCexViewItem, navController: NavControlle
viewItem.coinUid?.let { coinUid ->
navController.slideFromRight(
R.id.coinFragment,
CoinFragment.prepareParams(coinUid)
CoinFragment.prepareParams(coinUid, "cex_asset")
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private fun ButtonsRow(viewItem: BalanceViewItem, navController: NavController,
enabled = !viewItem.wallet.token.isCustom,
onClick = {
val coinUid = viewItem.wallet.coin.uid
val arguments = CoinFragment.prepareParams(coinUid)
val arguments = CoinFragment.prepareParams(coinUid, "wallet_token_balance")

navController.slideFromRight(R.id.coinFragment, arguments)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class CoinFragment : BaseComposeFragment() {
@Composable
override fun GetContent(navController: NavController) {
val coinUid = requireArguments().getString(COIN_UID_KEY, "")
val apiTag = requireArguments().getString(API_TAG_KEY, "")

CoinScreen(
coinUid,
apiTag,
coinViewModel(coinUid),
navController,
childFragmentManager
Expand All @@ -52,20 +54,22 @@ class CoinFragment : BaseComposeFragment() {

companion object {
private const val COIN_UID_KEY = "coin_uid_key"
private const val API_TAG_KEY = "api_tag_key"

fun prepareParams(coinUid: String) = bundleOf(COIN_UID_KEY to coinUid)
fun prepareParams(coinUid: String, apiTag: String) = bundleOf(COIN_UID_KEY to coinUid, API_TAG_KEY to apiTag)
}
}

@Composable
fun CoinScreen(
coinUid: String,
apiTag: String,
coinViewModel: CoinViewModel?,
navController: NavController,
fragmentManager: FragmentManager
) {
if (coinViewModel != null) {
CoinTabs(coinViewModel, navController, fragmentManager)
CoinTabs(apiTag, coinViewModel, navController, fragmentManager)
} else {
CoinNotFound(coinUid, navController)
}
Expand All @@ -74,6 +78,7 @@ fun CoinScreen(
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun CoinTabs(
apiTag: String,
viewModel: CoinViewModel,
navController: NavController,
fragmentManager: FragmentManager
Expand Down Expand Up @@ -137,6 +142,7 @@ fun CoinTabs(
when (tabs[page]) {
CoinModule.Tab.Overview -> {
CoinOverviewScreen(
apiTag = apiTag,
fullCoin = viewModel.fullCoin,
navController = navController
)
Expand All @@ -148,6 +154,7 @@ fun CoinTabs(

CoinModule.Tab.Details -> {
CoinAnalyticsScreen(
apiTag = apiTag,
fullCoin = viewModel.fullCoin,
navController = navController,
fragmentManager = fragmentManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import kotlinx.parcelize.Parcelize

object CoinAnalyticsModule {

class Factory(private val fullCoin: FullCoin) : ViewModelProvider.Factory {
class Factory(private val fullCoin: FullCoin, private val apiTag: String) : ViewModelProvider.Factory {

@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val service = CoinAnalyticsService(
fullCoin,
apiTag,
App.marketKit,
App.currencyManager,
App.subscriptionManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ import io.horizontalsystems.marketkit.models.HsPointTimePeriod

@Composable
fun CoinAnalyticsScreen(
apiTag: String,
fullCoin: FullCoin,
navController: NavController,
fragmentManager: FragmentManager
) {
val viewModel = viewModel<CoinAnalyticsViewModel>(factory = CoinAnalyticsModule.Factory(fullCoin))
val viewModel = viewModel<CoinAnalyticsViewModel>(factory = CoinAnalyticsModule.Factory(fullCoin, apiTag))
val uiState = viewModel.uiState

HSSwipeRefresh(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.reactivex.subjects.BehaviorSubject

class CoinAnalyticsService(
val fullCoin: FullCoin,
private val apiTag: String,
private val marketKit: MarketKitWrapper,
private val currencyManager: CurrencyManager,
private val subscriptionManager: SubscriptionManager,
Expand Down Expand Up @@ -74,7 +75,7 @@ class CoinAnalyticsService(
} else {
stateSubject.onNext(DataState.Loading)

marketKit.analyticsSingle(fullCoin.coin.uid, currency.code)
marketKit.analyticsSingle(fullCoin.coin.uid, currency.code, apiTag)
.subscribeIO({ item ->
stateSubject.onNext(DataState.Success(AnalyticData(analytics = item)))
}, {
Expand Down Expand Up @@ -103,7 +104,7 @@ class CoinAnalyticsService(
it.type.evmAddress(App.evmBlockchainManager.getChain(BlockchainType.Ethereum))?.hex
}

marketKit.analyticsPreviewSingle(fullCoin.coin.uid, addresses)
marketKit.analyticsPreviewSingle(fullCoin.coin.uid, addresses, apiTag)
.subscribeIO({ item ->
stateSubject.onNext(DataState.Success(AnalyticData(analyticsPreview = item)))
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import io.horizontalsystems.marketkit.models.Token

object CoinOverviewModule {

class Factory(private val fullCoin: FullCoin) : ViewModelProvider.Factory {
class Factory(private val fullCoin: FullCoin, private val apiTag: String) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {

Expand All @@ -22,6 +22,7 @@ object CoinOverviewModule {
val currency = App.currencyManager.baseCurrency
val service = CoinOverviewService(
fullCoin,
apiTag,
App.marketKit,
App.currencyManager,
App.appConfigProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.net.URL

class CoinOverviewService(
val fullCoin: FullCoin,
private val apiTag: String,
private val marketKit: MarketKitWrapper,
private val currencyManager: CurrencyManager,
private val appConfigProvider: AppConfigProvider,
Expand Down Expand Up @@ -51,7 +52,7 @@ class CoinOverviewService(
}

private fun fetchCoinOverview() {
marketKit.marketInfoOverviewSingle(fullCoin.coin.uid, currencyManager.baseCurrency.code, languageManager.currentLanguage)
marketKit.marketInfoOverviewSingle(fullCoin.coin.uid, currencyManager.baseCurrency.code, languageManager.currentLanguage, apiTag)
.subscribeIO({ marketInfoOverview ->
coinOverviewSubject.onNext(DataState.Success(CoinOverviewItem(fullCoin.coin.code, marketInfoOverview, guideUrl)))
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ import io.horizontalsystems.marketkit.models.LinkType

@Composable
fun CoinOverviewScreen(
apiTag: String,
fullCoin: FullCoin,
navController: NavController
) {
val vmFactory by lazy { CoinOverviewModule.Factory(fullCoin) }
val vmFactory by lazy { CoinOverviewModule.Factory(fullCoin, apiTag) }
val viewModel = viewModel<CoinOverviewViewModel>(factory = vmFactory)
val chartViewModel = viewModel<ChartViewModel>(factory = vmFactory)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CoinTweetsService(
Single.just(tmpUser)
} else {
marketKit
.marketInfoOverviewSingle(coinUid, "USD", "en")
.marketInfoOverviewSingle(coinUid, "USD", "en", "market_tweets")
.flatMap {
val username = it.links[LinkType.Twitter]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class MainViewModel(
when {
deeplinkString.contains("coin-page") -> {
uid?.let {
deeplinkPage = DeeplinkPage(R.id.coinFragment, CoinFragment.prepareParams(it))
deeplinkPage = DeeplinkPage(R.id.coinFragment, CoinFragment.prepareParams(it, "widget_click"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MarketCategoryFragment : BaseComposeFragment() {
}

private fun onCoinClick(coinUid: String, navController: NavController) {
val arguments = CoinFragment.prepareParams(coinUid)
val arguments = CoinFragment.prepareParams(coinUid, "market_category")

navController.slideFromRight(R.id.coinFragment, arguments)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.horizontalsystems.bankwallet.modules.market.category

import io.horizontalsystems.bankwallet.core.managers.MarketKitWrapper
import io.horizontalsystems.bankwallet.entities.Currency
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.entities.Currency
import io.reactivex.Single
import kotlin.math.min

Expand All @@ -21,7 +21,7 @@ class MarketCategoryRepository(
@Synchronized
private fun getMarketItems(coinCategoryUid: String, forceRefresh: Boolean, baseCurrency: Currency): List<MarketItem> =
if (forceRefresh && (cacheTimestamp + cacheValidPeriodInMillis < System.currentTimeMillis()) || cache.isEmpty()) {
val marketInfoList = marketKit.marketInfosSingle(coinCategoryUid, baseCurrency.code).blockingGet()
val marketInfoList = marketKit.marketInfosSingle(coinCategoryUid, baseCurrency.code, "market_category").blockingGet()

val marketItems = marketInfoList.map { marketInfo ->
MarketItem.createFromCoinMarket(marketInfo, baseCurrency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package io.horizontalsystems.bankwallet.modules.market.favorites

import io.horizontalsystems.bankwallet.core.managers.MarketFavoritesManager
import io.horizontalsystems.bankwallet.core.managers.MarketKitWrapper
import io.horizontalsystems.bankwallet.entities.Currency
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.entities.Currency
import io.reactivex.Single

class MarketFavoritesRepository(
Expand All @@ -25,7 +25,7 @@ class MarketFavoritesRepository(
var marketItems = listOf<MarketItem>()
if (favoriteCoins.isNotEmpty()) {
val favoriteCoinUids = favoriteCoins.map { it.coinUid }
marketItems = marketKit.marketInfosSingle(favoriteCoinUids, currency.code).blockingGet()
marketItems = marketKit.marketInfosSingle(favoriteCoinUids, currency.code, "watchlist").blockingGet()
.map { marketInfo ->
MarketItem.createFromCoinMarket(marketInfo, currency)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fun MarketFavoritesScreen(
onAddFavorite = { /*not used */ },
onRemoveFavorite = { uid -> viewModel.removeFromFavorites(uid) },
onCoinClick = { coinUid ->
val arguments = CoinFragment.prepareParams(coinUid)
val arguments = CoinFragment.prepareParams(coinUid, "market_watchlist")
navController.slideFromRight(R.id.coinFragment, arguments)
},
preItems = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class MarketFiltersService(
val topMarketListAsync = if (cache != null) {
Single.just(cache)
} else {
marketKit.advancedMarketInfosSingle(coinCount, baseCurrency.code)
marketKit.advancedMarketInfosSingle(coinCount, baseCurrency.code, "market_advanced_search_results")
.doOnSuccess {
cache = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private fun SearchResultsScreen(
viewModel.onRemoveFavorite(uid)
},
onCoinClick = { coinUid ->
val arguments = CoinFragment.prepareParams(coinUid)
val arguments = CoinFragment.prepareParams(coinUid, "market_advanced_search")
navController.slideFromRight(R.id.coinFragment, arguments)
},
preItems = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MetricsPageFragment : BaseComposeFragment() {
}

private fun onCoinClick(coinUid: String, navController: NavController) {
val arguments = CoinFragment.prepareParams(coinUid)
val arguments = CoinFragment.prepareParams(coinUid, "market_metrics")

navController.slideFromRight(R.id.coinFragment, arguments)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object MetricsPageModule {
@Suppress("UNCHECKED_CAST")
class Factory(private val metricsType: MetricsType) : ViewModelProvider.Factory {
private val globalMarketRepository by lazy {
GlobalMarketRepository(App.marketKit)
GlobalMarketRepository(App.marketKit, "market_metrics")
}

override fun <T : ViewModel> create(modelClass: Class<T>): T {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.horizontalsystems.bankwallet.ui.compose.components.RowUniversal
import io.horizontalsystems.bankwallet.ui.compose.components.body_leah

fun onItemClick(marketViewItem: MarketViewItem, navController: NavController) {
val arguments = CoinFragment.prepareParams(marketViewItem.coinUid)
val arguments = CoinFragment.prepareParams(marketViewItem.coinUid, "market_overview")
navController.slideFromRight(R.id.coinFragment, arguments)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MarketPlatformCoinsRepository(

val items = if (forceRefresh || currentCache == null) {
val marketInfoItems = marketKit
.topPlatformCoinListSingle(platform.uid, currencyManager.baseCurrency.code)
.topPlatformCoinListSingle(platform.uid, currencyManager.baseCurrency.code, "market_top_platforms")
.await()

marketInfoItems.map { marketInfo ->
Expand Down
Loading