Updated on 2026-08-14
This commit is contained in:
parent
4e28463b8a
commit
546bcc908f
24 changed files with 624 additions and 131 deletions
|
|
@ -1,9 +1,11 @@
|
|||
package com.tangem.data.markets.converters
|
||||
|
||||
import android.net.Uri
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchainsdk.utils.fromNetworkId
|
||||
import com.tangem.blockchainsdk.utils.isSupportedInApp
|
||||
import com.tangem.datasource.api.markets.models.response.TokenMarketInfoResponse
|
||||
import com.tangem.domain.markets.BuildConfig
|
||||
import com.tangem.domain.markets.TokenMarketInfo
|
||||
import com.tangem.domain.markets.TokenQuotes
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
|
@ -11,6 +13,9 @@ import java.math.BigDecimal
|
|||
|
||||
internal object TokenMarketInfoConverter : Converter<TokenMarketInfoResponse, TokenMarketInfo> {
|
||||
|
||||
private const val PROD_IMAGE_HOST = "https://s3.eu-central-1.amazonaws.com/tangem.api/security_provider/"
|
||||
private const val DEV_IMAGE_HOST = "https://s3.eu-central-1.amazonaws.com/tangem.api.dev/security_provider/"
|
||||
|
||||
override fun convert(value: TokenMarketInfoResponse): TokenMarketInfo {
|
||||
return with(value) {
|
||||
TokenMarketInfo(
|
||||
|
|
@ -23,6 +28,7 @@ internal object TokenMarketInfoConverter : Converter<TokenMarketInfoResponse, To
|
|||
fullDescription = fullDescription,
|
||||
insights = insights?.convert(),
|
||||
metrics = metrics?.convert(),
|
||||
securityData = securityData?.convert(),
|
||||
links = links?.convert(),
|
||||
pricePerformance = pricePerformance?.convert(),
|
||||
exchangesAmount = exchangesAmount,
|
||||
|
|
@ -105,6 +111,31 @@ internal object TokenMarketInfoConverter : Converter<TokenMarketInfoResponse, To
|
|||
)
|
||||
}
|
||||
|
||||
private fun TokenMarketInfoResponse.SecurityData.convert(): TokenMarketInfo.SecurityData {
|
||||
return TokenMarketInfo.SecurityData(
|
||||
totalSecurityScore = totalSecurityScore,
|
||||
providerData = providerData.map { it.convert() },
|
||||
)
|
||||
}
|
||||
|
||||
private fun TokenMarketInfoResponse.ProviderData.convert(): TokenMarketInfo.ProviderData {
|
||||
return TokenMarketInfo.ProviderData(
|
||||
providerId = providerId,
|
||||
providerName = providerName,
|
||||
urlData = link?.convertToUrlData(),
|
||||
securityScore = securityScore,
|
||||
lastAuditDate = lastAuditDate,
|
||||
iconUrl = "${getImageHost()}large/$providerId.png",
|
||||
)
|
||||
}
|
||||
|
||||
private fun String.convertToUrlData(): TokenMarketInfo.ProviderUrlData {
|
||||
return TokenMarketInfo.ProviderUrlData(
|
||||
fullUrl = this,
|
||||
rootHost = this.extractMainDomainOrNull(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun TokenMarketInfoResponse.Links.convert(): TokenMarketInfo.Links {
|
||||
return TokenMarketInfo.Links(
|
||||
officialLinks = officialLinks?.convert(),
|
||||
|
|
@ -139,4 +170,27 @@ internal object TokenMarketInfoConverter : Converter<TokenMarketInfoResponse, To
|
|||
high = high,
|
||||
)
|
||||
}
|
||||
|
||||
private fun String.extractMainDomainOrNull(): String? {
|
||||
return runCatching {
|
||||
val uri = Uri.parse(this)
|
||||
val host = uri.host ?: return null
|
||||
|
||||
val parts = host.split(".")
|
||||
|
||||
if (parts.size >= 2) {
|
||||
parts.takeLast(2).joinToString(".")
|
||||
} else {
|
||||
host
|
||||
}
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
private fun getImageHost(): String {
|
||||
return if (BuildConfig.TESTER_MENU_ENABLED) {
|
||||
DEV_IMAGE_HOST
|
||||
} else {
|
||||
PROD_IMAGE_HOST
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue