Updated on 2026-08-14
This commit is contained in:
parent
297a006e3d
commit
ce9335e3bd
5 changed files with 160 additions and 21 deletions
|
|
@ -12,6 +12,29 @@ import com.tangem.blockchain.common.Token as SdkToken
|
|||
// FIXME: Make internal
|
||||
class CryptoCurrencyFactory {
|
||||
|
||||
@Suppress("LongParameterList") // Yep, it's long
|
||||
fun createToken(
|
||||
network: Network,
|
||||
rawId: String?,
|
||||
name: String,
|
||||
symbol: String,
|
||||
decimals: Int,
|
||||
contractAddress: String,
|
||||
): CryptoCurrency.Token {
|
||||
val id = getTokenId(network, rawId, contractAddress)
|
||||
|
||||
return CryptoCurrency.Token(
|
||||
id = id,
|
||||
network = network,
|
||||
name = name,
|
||||
symbol = symbol,
|
||||
decimals = decimals,
|
||||
iconUrl = rawId?.let(::getTokenIconUrlFromDefaultHost),
|
||||
isCustom = isCustomToken(id, network),
|
||||
contractAddress = contractAddress,
|
||||
)
|
||||
}
|
||||
|
||||
fun createToken(
|
||||
sdkToken: SdkToken,
|
||||
blockchain: Blockchain,
|
||||
|
|
@ -49,15 +72,7 @@ class CryptoCurrencyFactory {
|
|||
}
|
||||
val network = getNetwork(blockchain, extraDerivationPath, derivationStyleProvider) ?: return null
|
||||
|
||||
return CryptoCurrency.Coin(
|
||||
id = getCoinId(network, blockchain.toCoinId()),
|
||||
network = network,
|
||||
name = blockchain.fullName,
|
||||
symbol = blockchain.currency,
|
||||
iconUrl = getCoinIconUrl(blockchain),
|
||||
decimals = blockchain.decimals(),
|
||||
isCustom = isCustomCoin(network),
|
||||
)
|
||||
return createCoin(network)
|
||||
}
|
||||
|
||||
fun createCoin(
|
||||
|
|
@ -69,6 +84,20 @@ class CryptoCurrencyFactory {
|
|||
return createCoin(blockchain, extraDerivationPath, derivationStyleProvider)
|
||||
}
|
||||
|
||||
fun createCoin(network: Network): CryptoCurrency.Coin {
|
||||
val blockchain = Blockchain.fromId(network.id.value)
|
||||
|
||||
return CryptoCurrency.Coin(
|
||||
id = getCoinId(network, blockchain.toCoinId()),
|
||||
network = network,
|
||||
name = blockchain.fullName,
|
||||
symbol = blockchain.currency,
|
||||
iconUrl = getCoinIconUrl(blockchain),
|
||||
decimals = blockchain.decimals(),
|
||||
isCustom = isCustomCoin(network),
|
||||
)
|
||||
}
|
||||
|
||||
fun createToken(
|
||||
token: Token,
|
||||
networkId: String,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,21 @@ fun getBlockchain(networkId: Network.ID): Blockchain {
|
|||
return Blockchain.fromId(networkId.value)
|
||||
}
|
||||
|
||||
fun getNetwork(networkId: Network.ID, derivationPath: Network.DerivationPath): Network {
|
||||
val blockchain = getBlockchain(networkId)
|
||||
|
||||
return Network(
|
||||
id = networkId,
|
||||
backendId = blockchain.toNetworkId(),
|
||||
name = blockchain.getNetworkName(),
|
||||
isTestnet = blockchain.isTestnet(),
|
||||
derivationPath = derivationPath,
|
||||
currencySymbol = blockchain.currency,
|
||||
standardType = getNetworkStandardType(blockchain),
|
||||
hasFiatFeeRate = blockchain.feePaidCurrency() !is FeePaidCurrency.FeeResource,
|
||||
)
|
||||
}
|
||||
|
||||
fun getNetwork(
|
||||
blockchain: Blockchain,
|
||||
extraDerivationPath: String?,
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ private fun getCurrencyIdBody(network: Network): CurrencyIdBody {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getTokenIconUrlFromDefaultHost(tokenId: String): String {
|
||||
fun getTokenIconUrlFromDefaultHost(tokenId: String): String {
|
||||
return buildString {
|
||||
append(DEFAULT_TOKENS_ICONS_HOST)
|
||||
append('/')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue