Updated on 2026-08-14
This commit is contained in:
parent
d2d9669097
commit
207da4af08
5 changed files with 62 additions and 0 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.tangem.blockchainsdk.utils
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.core.configtoggle.blockchain.ExcludedBlockchainsManager
|
||||
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
|
||||
|
||||
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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue