Updated on 2026-08-14

This commit is contained in:
Tangem 2026-03-30 14:35:20 +07:00
parent 514eca0b00
commit 203b1c52cc
17 changed files with 152 additions and 29 deletions

View file

@ -1,6 +1,7 @@
package com.tangem.blockchainsdk
import com.tangem.blockchain.common.WalletManagerFactory
import com.tangem.blockchain.common.memo.MemoValidatorFactory
/**
* Blockchain SDK components factory
@ -14,4 +15,7 @@ interface BlockchainSDKFactory {
/** Get [WalletManagerFactory] synchronously */
suspend fun getWalletManagerFactorySync(): WalletManagerFactory?
/** Get [MemoValidatorFactory] synchronously */
suspend fun getMemoValidatorFactorySync(): MemoValidatorFactory?
}

View file

@ -2,6 +2,7 @@ package com.tangem.blockchainsdk
import com.tangem.blockchain.common.BlockchainSdkConfig
import com.tangem.blockchain.common.WalletManagerFactory
import com.tangem.blockchain.common.memo.MemoValidatorFactory
import com.tangem.blockchainsdk.providers.BlockchainProvidersTypesManager
import com.tangem.datasource.local.config.providers.models.ProviderModel
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
@ -32,6 +33,7 @@ internal class DefaultBlockchainSDKFactory(
private val mainScope = CoroutineScope(dispatchers.main)
private val walletManagerFactory: Flow<WalletManagerFactory?> = createWalletManagerFactory()
private val memoValidatorFactory: Flow<MemoValidatorFactory?> = createMemoValidatorFactory()
override suspend fun init() {
coroutineScope {
@ -41,6 +43,8 @@ internal class DefaultBlockchainSDKFactory(
override suspend fun getWalletManagerFactorySync(): WalletManagerFactory? = walletManagerFactory.firstOrNull()
override suspend fun getMemoValidatorFactorySync(): MemoValidatorFactory? = memoValidatorFactory.firstOrNull()
private fun createWalletManagerFactory(): Flow<WalletManagerFactory?> {
return combine(
flow = flowOf(blockchainSdkConfig),
@ -51,4 +55,14 @@ internal class DefaultBlockchainSDKFactory(
// don't use Lazily because some features (WC) require initialized factory on app started
.stateIn(scope = mainScope, started = SharingStarted.Eagerly, initialValue = null)
}
private fun createMemoValidatorFactory(): Flow<MemoValidatorFactory?> {
return combine(
flow = flowOf(blockchainSdkConfig),
flow2 = blockchainProvidersTypesManager.get(),
) { config, providerTypes ->
MemoValidatorFactory(config = config, blockchainProviderTypes = providerTypes)
}
.stateIn(scope = mainScope, started = SharingStarted.Eagerly, initialValue = null)
}
}