Updated on 2026-08-14
This commit is contained in:
commit
a25b99f933
10 changed files with 74 additions and 8 deletions
|
|
@ -1,11 +1,15 @@
|
|||
package com.tangem.datasource.api.tangemTech.models
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class CurrenciesResponse(
|
||||
@Json(name = "currencies") val currencies: List<Currency>,
|
||||
@Json(name = "imageHost") val imageHost: String? = null,
|
||||
) {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Currency(
|
||||
@Json(name = "id") val id: String,
|
||||
@Json(name = "code") val code: String, // this is an uppercase id
|
||||
|
|
@ -13,5 +17,7 @@ data class CurrenciesResponse(
|
|||
@Json(name = "rateBTC") val rateBTC: String,
|
||||
@Json(name = "unit") val unit: String, // $, €, ₽
|
||||
@Json(name = "type") val type: String,
|
||||
val iconSmallUrl: String? = null,
|
||||
val iconMediumUrl: String? = null,
|
||||
)
|
||||
}
|
||||
|
|
@ -15,8 +15,20 @@ internal class DefaultAvailableAppCurrenciesStore(
|
|||
}
|
||||
|
||||
override suspend fun store(response: CurrenciesResponse) {
|
||||
val currencies = response.currencies.associateBy(CurrenciesResponse.Currency::code)
|
||||
val currencies = response.currencies
|
||||
.map {
|
||||
it.copy(
|
||||
iconSmallUrl = response.imageHost?.plus(IMAGE_SMALL)?.format(it.id),
|
||||
iconMediumUrl = response.imageHost?.plus(IMAGE_MEDIUM)?.format(it.id),
|
||||
)
|
||||
}
|
||||
.associateBy(CurrenciesResponse.Currency::code)
|
||||
|
||||
dataStore.store(currencies)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val IMAGE_MEDIUM = "medium/%s.png"
|
||||
const val IMAGE_SMALL = "small/%s.png"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue