Updated on 2026-08-14

This commit is contained in:
Tangem 2025-05-22 17:41:04 +04:00
parent db6157cae4
commit 99f62f79ee
35 changed files with 128 additions and 109 deletions

View file

@ -3,6 +3,7 @@ package com.tangem.data.common.currency
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.blockchainsdk.utils.fromNetworkId
import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.blockchainsdk.utils.toCoinId
import com.tangem.data.common.network.NetworkFactory
import com.tangem.domain.models.currency.CryptoCurrency
@ -97,7 +98,7 @@ class CryptoCurrencyFactory(
}
fun createCoin(network: Network): CryptoCurrency.Coin {
val blockchain = Blockchain.fromId(network.rawId)
val blockchain = network.toBlockchain()
return CryptoCurrency.Coin(
id = getCoinId(network, blockchain.toCoinId()),

View file

@ -1,8 +0,0 @@
package com.tangem.data.common.currency
import com.tangem.blockchain.common.Blockchain
import com.tangem.domain.models.network.Network
fun getBlockchain(networkId: Network.ID): Blockchain {
return Blockchain.fromId(networkId.rawId.value)
}

View file

@ -2,6 +2,7 @@ package com.tangem.data.common.currency
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.IconsUtil
import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.blockchainsdk.utils.toCoinId
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
import com.tangem.domain.models.currency.CryptoCurrency
@ -68,11 +69,10 @@ fun getCoinIconUrl(blockchain: Blockchain): String? {
}
fun List<UserTokensResponse.Token>.hasCoinForToken(network: Network): Boolean {
return any {
val blockchain = getBlockchain(networkId = network.id)
val tokenDerivation = network.derivationPath.value
it.id == blockchain.toCoinId() && it.derivationPath == tokenDerivation
}
val coinId = network.toBlockchain().toCoinId()
val tokenDerivation = network.derivationPath.value
return any { it.id == coinId && it.derivationPath == tokenDerivation }
}
private fun getCurrencyIdBody(network: Network): CurrencyIdBody {

View file

@ -1,6 +1,5 @@
package com.tangem.data.common.currency
import com.tangem.blockchainsdk.utils.toNetworkId
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
import com.tangem.domain.models.currency.CryptoCurrency
@ -27,16 +26,16 @@ class UserTokensResponseFactory {
}
fun createResponseToken(currency: CryptoCurrency): UserTokensResponse.Token {
val blockchain = getBlockchain(currency.network.id)
return UserTokensResponse.Token(
id = currency.id.rawCurrencyId?.value,
networkId = blockchain.toNetworkId(),
derivationPath = currency.network.derivationPath.value,
name = currency.name,
symbol = currency.symbol,
decimals = currency.decimals,
contractAddress = (currency as? CryptoCurrency.Token)?.contractAddress,
)
return with(currency) {
UserTokensResponse.Token(
id = id.rawCurrencyId?.value,
networkId = network.backendId,
derivationPath = network.derivationPath.value,
name = name,
symbol = symbol,
decimals = decimals,
contractAddress = (this as? CryptoCurrency.Token)?.contractAddress,
)
}
}
}

View file

@ -4,8 +4,8 @@ import androidx.annotation.VisibleForTesting
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.FeePaidCurrency
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.blockchainsdk.utils.toNetworkId
import com.tangem.data.common.currency.getBlockchain
import com.tangem.domain.common.DerivationStyleProvider
import com.tangem.domain.common.extensions.canHandleToken
import com.tangem.domain.common.util.cardTypesResolver
@ -57,7 +57,7 @@ class NetworkFactory @Inject constructor(
* @param scanResponse scan response
*/
fun create(networkId: Network.ID, derivationPath: Network.DerivationPath, scanResponse: ScanResponse): Network? {
val blockchain = getBlockchain(networkId)
val blockchain = networkId.toBlockchain()
return create(
blockchain = blockchain,