Updated on 2026-08-14

This commit is contained in:
Tangem 2024-12-16 17:46:32 +03:00
commit 84f085a4e0
777 changed files with 24282 additions and 3464 deletions

View file

@ -13,7 +13,7 @@ dependencies {
// region Core modules
implementation(projects.core.datasource)
implementation(projects.core.featuretoggles)
implementation(projects.core.configToggles)
implementation(projects.core.utils)
// endregion

View file

@ -26,4 +26,10 @@ internal class DefaultBlockchainDataStorage(
it[stringPreferencesKey(key)] = value
}
}
override suspend fun remove(key: String) {
appPreferencesStore.edit {
it.remove(stringPreferencesKey(key))
}
}
}

View file

@ -9,7 +9,7 @@ import com.tangem.blockchainsdk.datastorage.DefaultBlockchainDataStorage
import com.tangem.blockchainsdk.featuretoggles.DefaultBlockchainSDKFeatureToggles
import com.tangem.blockchainsdk.loader.BlockchainProvidersResponseLoader
import com.tangem.blockchainsdk.store.DefaultRuntimeStore
import com.tangem.core.featuretoggle.manager.FeatureTogglesManager
import com.tangem.core.configtoggle.feature.FeatureTogglesManager
import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.local.config.environment.EnvironmentConfigStorage
import com.tangem.datasource.local.preferences.AppPreferencesStore

View file

@ -0,0 +1,20 @@
package com.tangem.blockchainsdk.di
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.core.configtoggle.blockchain.ExcludedBlockchainsManager
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
internal object ExcludedBlockchainsModule {
@Provides
@Singleton
fun bindExcludedBlockchains(excludedBlockchainsManager: ExcludedBlockchainsManager): ExcludedBlockchains {
return ExcludedBlockchains(excludedBlockchainsManager)
}
}

View file

@ -1,6 +1,6 @@
package com.tangem.blockchainsdk.featuretoggles
import com.tangem.core.featuretoggle.manager.FeatureTogglesManager
import com.tangem.core.configtoggle.feature.FeatureTogglesManager
internal class DefaultBlockchainSDKFeatureToggles(
private val featureTogglesManager: FeatureTogglesManager,

View file

@ -1,7 +1,9 @@
package com.tangem.blockchainsdk.utils
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.ReserveAmountProvider
import com.tangem.blockchain.common.Token
import com.tangem.blockchain.common.WalletManager
import java.math.BigDecimal
@Suppress("ComplexMethod", "LongMethod")
@ -138,8 +140,11 @@ fun Blockchain.Companion.fromNetworkId(networkId: String): Blockchain? {
"core/test" -> Blockchain.CoreTestnet
"casper-network" -> Blockchain.Casper
"casper-network/test" -> Blockchain.CasperTestnet
"chiliz" -> Blockchain.Chiliz
"chiliz/test" -> Blockchain.ChilizTestnet
"xodex" -> Blockchain.Xodex
"canxium" -> Blockchain.Canxium
"clore-ai" -> Blockchain.Clore
else -> null
}
}
@ -277,8 +282,11 @@ fun Blockchain.toNetworkId(): String {
Blockchain.CasperTestnet -> "casper-network/test"
Blockchain.Core -> "core"
Blockchain.CoreTestnet -> "core/test"
Blockchain.Chiliz -> "chiliz"
Blockchain.ChilizTestnet -> "chiliz/test"
Blockchain.Xodex -> "xodex"
Blockchain.Canxium -> "canxium"
Blockchain.Clore -> "clore-ai"
}
}
@ -295,7 +303,7 @@ fun Blockchain.toCoinId(): String {
Blockchain.EthereumClassic, Blockchain.EthereumClassicTestnet -> "ethereum-classic"
Blockchain.Stellar, Blockchain.StellarTestnet -> "stellar"
Blockchain.Cardano -> "cardano"
Blockchain.Polygon, Blockchain.PolygonTestnet -> "polygon-ecosystem-token"
Blockchain.Polygon, Blockchain.PolygonTestnet -> NEW_POLYGON_NAME
Blockchain.Arbitrum, Blockchain.ArbitrumTestnet -> "arbitrum-one"
Blockchain.Avalanche, Blockchain.AvalancheTestnet -> "avalanche-2"
Blockchain.Solana, Blockchain.SolanaTestnet -> "solana"
@ -368,8 +376,10 @@ fun Blockchain.toCoinId(): String {
Blockchain.EnergyWebX, Blockchain.EnergyWebXTestnet -> "energy-web-token"
Blockchain.Casper, Blockchain.CasperTestnet -> "casper-network"
Blockchain.Core, Blockchain.CoreTestnet -> "coredaoorg"
Blockchain.Chiliz, Blockchain.ChilizTestnet -> "chiliz"
Blockchain.Xodex -> "xodex"
Blockchain.Canxium -> "canxium"
Blockchain.Clore -> "clore-ai"
}
}
@ -377,19 +387,28 @@ fun Blockchain.toCoinId(): String {
* New CoinId to existing coin "id" field.
* To support both old and new coin id.
*/
fun Blockchain.toMigratedCointId(): String = when (this) {
Blockchain.Polygon, Blockchain.PolygonTestnet -> "polygon-ecosystem-token"
fun Blockchain.toMigratedCoinId(): String = when (this) {
Blockchain.Polygon, Blockchain.PolygonTestnet -> NEW_POLYGON_NAME
else -> toCoinId()
}
fun Blockchain.isSupportedInApp(): Boolean {
return !excludedBlockchains.contains(this)
}
fun Blockchain.amountToCreateAccount(token: Token? = null): BigDecimal? {
fun Blockchain.amountToCreateAccount(walletManager: WalletManager, token: Token? = null): BigDecimal? {
return when (this) {
Blockchain.Stellar -> if (token?.symbol == NODL) BigDecimal(NODL_AMOUNT_TO_CREATE_ACCOUNT) else BigDecimal.ONE
Blockchain.XRP -> BigDecimal.TEN
Blockchain.Stellar -> {
val reserve = if (walletManager is ReserveAmountProvider) {
walletManager.getReserveAmount()
} else {
BigDecimal.ONE
}
if (token?.symbol == NODL) BigDecimal(NODL_AMOUNT_TO_CREATE_ACCOUNT) else reserve
}
Blockchain.XRP -> {
if (walletManager is ReserveAmountProvider) {
walletManager.getReserveAmount()
} else {
BigDecimal.ONE
}
}
Blockchain.Near, Blockchain.NearTestnet -> 0.00182.toBigDecimal()
Blockchain.Aptos, Blockchain.AptosTestnet,
Blockchain.Filecoin,
@ -403,13 +422,8 @@ fun Blockchain.minimalAmount(): BigDecimal {
return BigDecimal.ONE.movePointLeft(decimals())
}
private const val NODL = "NODL"
private const val NODL_AMOUNT_TO_CREATE_ACCOUNT = 1.5
const val OLD_POLYGON_NAME = "matic-network"
const val NEW_POLYGON_NAME = "polygon-ecosystem-token"
// no need to add testnets
private val excludedBlockchains = listOf(
Blockchain.Unknown,
Blockchain.Nexa,
Blockchain.NexaTestnet,
Blockchain.Xodex,
)
private const val NODL = "NODL"
private const val NODL_AMOUNT_TO_CREATE_ACCOUNT = 1.5

View file

@ -0,0 +1,45 @@
package com.tangem.blockchainsdk.utils
import com.tangem.blockchain.common.Blockchain
import com.tangem.core.configtoggle.blockchain.ExcludedBlockchainsManager
import org.jetbrains.annotations.TestOnly
import javax.inject.Inject
class ExcludedBlockchains @Inject internal constructor(
private val excludedBlockchainsManager: ExcludedBlockchainsManager,
) : Set<Blockchain> {
private val excludedBlockchains: Set<Blockchain> by lazy(mode = LazyThreadSafetyMode.NONE) {
excludedBlockchainsManager.excludedBlockchainsIds.fold(mutableSetOf()) { acc, blockchainId ->
val blockchain = Blockchain.fromId(blockchainId)
acc.add(blockchain)
blockchain.getTestnetVersion()?.let { acc.add(it) }
acc
}
}
override val size: Int
get() = excludedBlockchains.size
@TestOnly
constructor() : this(
excludedBlockchainsManager = object : ExcludedBlockchainsManager {
override val excludedBlockchainsIds: Set<String> = emptySet()
override suspend fun init() {
/* no-op */
}
},
)
override fun contains(element: Blockchain): Boolean = excludedBlockchains.contains(element)
override fun containsAll(elements: Collection<Blockchain>): Boolean = excludedBlockchains.containsAll(elements)
override fun isEmpty(): Boolean = excludedBlockchains.isEmpty()
override fun iterator(): Iterator<Blockchain> = excludedBlockchains.iterator()
}

View file

@ -3,8 +3,8 @@ package com.tangem.lib.crypto
import com.tangem.blockchain.blockchains.xrp.XrpAddressService
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchainsdk.compatibility.l2BlockchainsList
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.blockchainsdk.utils.fromNetworkId
import com.tangem.blockchainsdk.utils.isSupportedInApp
import com.tangem.lib.crypto.converter.XrpTaggedAddressConverter
import com.tangem.lib.crypto.models.XrpTaggedAddress
@ -64,8 +64,10 @@ object BlockchainUtils {
return blockchain == Blockchain.Tron || blockchain == Blockchain.TronTestnet
}
fun isSupportedNetworkId(blockchainId: String): Boolean {
return Blockchain.fromNetworkId(blockchainId)?.isSupportedInApp() ?: false
fun isSupportedNetworkId(blockchainId: String, excludedBlockchains: ExcludedBlockchains): Boolean {
val blockchain = Blockchain.fromNetworkId(blockchainId)
return blockchain != null && blockchain !in excludedBlockchains
}
fun isArbitrum(blockchainId: String): Boolean {

View file

@ -0,0 +1,17 @@
package com.tangem.sdk.api
import androidx.activity.ComponentActivity
import com.tangem.TangemSdk
import com.tangem.operations.backup.BackupService
import com.tangem.sdk.extensions.init
import java.lang.ref.WeakReference
class BackupServiceHolder {
lateinit var backupService: WeakReference<BackupService>
private set
fun createAndSetService(tangemSdk: TangemSdk, activity: ComponentActivity) {
backupService = WeakReference(BackupService.init(tangemSdk, activity))
}
}