Skip to content

Commit

Permalink
Pass base currency when fetching top pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed Jan 4, 2024
1 parent 8947987 commit 82232ad
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions 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:c5c778a'
implementation 'com.github.horizontalsystems:market-kit-android:c1a875a'
implementation 'com.github.horizontalsystems:solana-kit-android:34ef394'
implementation 'com.github.horizontalsystems:tron-kit-android:5eb6395'
// Zcash SDK
Expand Down Expand Up @@ -321,7 +321,7 @@ dependencies {

implementation "androidx.compose.runtime:runtime-livedata:$compose_version"

def coil_version = "2.4.0"
def coil_version = "2.5.0"
implementation "io.coil-kt:coil-compose:$coil_version"
implementation "io.coil-kt:coil-svg:$coil_version"
implementation("io.coil-kt:coil-gif:$coil_version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class MarketKitWrapper(

fun marketOverviewSingle(currencyCode: String) = marketKit.marketOverviewSingle(currencyCode)

fun topPairsSingle(page: Int, limit: Int) = marketKit.topPairsSingle(page, limit)
fun topPairsSingle(currencyCode: String, page: Int, limit: Int) = marketKit.topPairsSingle(currencyCode, page, limit)

fun topMoversSingle(currencyCode: String) = marketKit.topMoversSingle(currencyCode)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,8 @@ data class TopPairViewItem(
val price: String?
) {
companion object {
fun createFromTopPair(topPair: TopPair): TopPairViewItem {
val volumeStr = App.numberFormatter.formatFiatShort(
topPair.volume,
App.currencyManager.baseCurrency.symbol,
2
)
fun createFromTopPair(topPair: TopPair, currencySymbol: String): TopPairViewItem {
val volumeStr = App.numberFormatter.formatFiatShort(topPair.volume, currencySymbol, 2)

val priceStr = topPair.price?.let {
App.numberFormatter.formatCoinShort(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class MarketOverviewViewModel(
topSectorsBoard = topSectorsBoard(coinCategoryItems),
topPlatformsBoard = topPlatformsBoard(topPlatformItems),
topMarketPairs = marketOverview.topPairs.map {
TopPairViewItem.createFromTopPair(it)
TopPairViewItem.createFromTopPair(it, baseCurrency.symbol)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.managers.CurrencyManager
import io.horizontalsystems.bankwallet.core.managers.MarketKitWrapper
import io.horizontalsystems.bankwallet.entities.ViewState
import io.horizontalsystems.bankwallet.modules.market.overview.TopPairViewItem
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.rx2.asFlow
import kotlinx.coroutines.rx2.await
import kotlinx.coroutines.withContext

class TopPairsViewModel(private val marketKit: MarketKitWrapper) : ViewModel() {
class TopPairsViewModel(
private val marketKit: MarketKitWrapper,
private val currencyManager: CurrencyManager,
) : ViewModel() {
private var isRefreshing = false
private var items = listOf<TopPairViewItem>()
private var viewState: ViewState = ViewState.Loading
Expand All @@ -31,8 +36,12 @@ class TopPairsViewModel(private val marketKit: MarketKitWrapper) : ViewModel() {
private set

init {
viewState = ViewState.Loading
emitState()
viewModelScope.launch {
currencyManager.baseCurrencyUpdatedSignal.asFlow().collect {
fetchItems()
emitState()
}
}

viewModelScope.launch {
fetchItems()
Expand All @@ -42,9 +51,9 @@ class TopPairsViewModel(private val marketKit: MarketKitWrapper) : ViewModel() {

private suspend fun fetchItems() = withContext(Dispatchers.Default) {
try {
val topPairs = marketKit.topPairsSingle(1, 100).await()
val topPairs = marketKit.topPairsSingle(currencyManager.baseCurrency.code, 1, 100).await()
items = topPairs.map {
TopPairViewItem.createFromTopPair(it)
TopPairViewItem.createFromTopPair(it, currencyManager.baseCurrency.symbol)
}
viewState = ViewState.Success
} catch (e: Throwable) {
Expand Down Expand Up @@ -81,7 +90,7 @@ class TopPairsViewModel(private val marketKit: MarketKitWrapper) : ViewModel() {
class Factory : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return TopPairsViewModel(App.marketKit) as T
return TopPairsViewModel(App.marketKit, App.currencyManager) as T
}
}

Expand Down

0 comments on commit 82232ad

Please sign in to comment.