Updated on 2026-08-14
This commit is contained in:
parent
dfa6798f07
commit
5883823eb3
71 changed files with 221 additions and 285 deletions
|
|
@ -18,7 +18,7 @@ class CryptoCurrencyFactory(
|
|||
@Suppress("LongParameterList") // Yep, it's long
|
||||
fun createToken(
|
||||
network: Network,
|
||||
rawId: String?,
|
||||
rawId: CryptoCurrency.RawID?,
|
||||
name: String,
|
||||
symbol: String,
|
||||
decimals: Int,
|
||||
|
|
@ -125,7 +125,7 @@ class CryptoCurrencyFactory(
|
|||
symbol = cryptoCurrency.symbol,
|
||||
contractAddress = cryptoCurrency.contractAddress,
|
||||
decimals = cryptoCurrency.decimals,
|
||||
id = cryptoCurrency.id.rawCurrencyId,
|
||||
id = cryptoCurrency.id.rawCurrencyId?.value,
|
||||
)
|
||||
val blockchain = Blockchain.fromNetworkId(cryptoCurrency.network.backendId) ?: Blockchain.Unknown
|
||||
val id = getTokenId(network, sdkToken)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.tangem.blockchain.common.Blockchain
|
|||
import com.tangem.blockchain.common.IconsUtil
|
||||
import com.tangem.blockchainsdk.utils.toCoinId
|
||||
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency.ID
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
import com.tangem.blockchain.common.Token as SdkToken
|
||||
|
|
@ -31,15 +32,16 @@ fun getCoinId(network: Network, coinId: String): ID {
|
|||
|
||||
fun getTokenId(network: Network, sdkToken: SdkToken): ID {
|
||||
val sdkTokenId = sdkToken.id
|
||||
val tokenId = sdkTokenId?.let { CryptoCurrency.RawID(it) }
|
||||
|
||||
return getTokenId(network, sdkTokenId, sdkToken.contractAddress)
|
||||
return getTokenId(network, tokenId, sdkToken.contractAddress)
|
||||
}
|
||||
|
||||
fun getTokenId(network: Network, rawTokenId: String?, contractAddress: String): ID {
|
||||
fun getTokenId(network: Network, rawTokenId: CryptoCurrency.RawID?, contractAddress: String): ID {
|
||||
val suffix = if (rawTokenId == null) {
|
||||
CustomCurrencyIdSuffix(contractAddress)
|
||||
} else {
|
||||
CurrencyIdSuffix(rawTokenId, contractAddress)
|
||||
CurrencyIdSuffix(rawTokenId.value, contractAddress)
|
||||
}
|
||||
|
||||
return ID(TOKEN_ID_PREFIX, getCurrencyIdBody(network), suffix)
|
||||
|
|
@ -47,11 +49,12 @@ fun getTokenId(network: Network, rawTokenId: String?, contractAddress: String):
|
|||
|
||||
fun getTokenIconUrl(blockchain: Blockchain, token: SdkToken): String? {
|
||||
val tokenId = token.id
|
||||
val rawID = tokenId?.let { CryptoCurrency.RawID(it) }
|
||||
|
||||
return if (tokenId == null) {
|
||||
return if (rawID == null) {
|
||||
IconsUtil.getTokenIconUri(blockchain, token)?.toString()
|
||||
} else {
|
||||
getTokenIconUrlFromDefaultHost(tokenId)
|
||||
getTokenIconUrlFromDefaultHost(rawID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +62,7 @@ fun getCoinIconUrl(blockchain: Blockchain): String? {
|
|||
val coinId = when (blockchain) {
|
||||
Blockchain.Unknown -> null
|
||||
else -> blockchain.toCoinId()
|
||||
}
|
||||
}?.let { CryptoCurrency.RawID(it) }
|
||||
|
||||
return coinId?.let(::getTokenIconUrlFromDefaultHost)
|
||||
}
|
||||
|
|
@ -84,13 +87,13 @@ private fun getCurrencyIdBody(network: Network): CurrencyIdBody {
|
|||
}
|
||||
}
|
||||
|
||||
fun getTokenIconUrlFromDefaultHost(tokenId: String): String {
|
||||
fun getTokenIconUrlFromDefaultHost(tokenId: CryptoCurrency.RawID): String {
|
||||
return buildString {
|
||||
append(DEFAULT_TOKENS_ICONS_HOST)
|
||||
append('/')
|
||||
append(TOKEN_ICON_SIZE)
|
||||
append('/')
|
||||
append(tokenId)
|
||||
append(tokenId.value)
|
||||
append('.')
|
||||
append(TOKEN_ICON_EXT)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class UserTokensResponseFactory {
|
|||
val blockchain = getBlockchain(currency.network.id)
|
||||
|
||||
return UserTokensResponse.Token(
|
||||
id = currency.id.rawCurrencyId,
|
||||
id = currency.id.rawCurrencyId?.value,
|
||||
networkId = blockchain.toNetworkId(),
|
||||
derivationPath = currency.network.derivationPath.value,
|
||||
name = currency.name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue