Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-30 15:08:00 +01:00
parent 682349e353
commit 0e370ae05f
2 changed files with 22 additions and 17 deletions

View file

@ -37,6 +37,8 @@ import com.tangem.domain.walletmanager.utils.WalletManagerFactory
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import timber.log.Timber
import java.math.BigDecimal
import java.util.EnumSet
@ -61,6 +63,8 @@ class DefaultWalletManagersFacade(
private val requirementsConditionConverter by lazy { SdkRequirementsConditionConverter() }
private val estimationFeeAddressFactory by lazy { EstimationFeeAddressFactory() }
private val initMutex = Mutex()
override suspend fun update(
userWalletId: UserWalletId,
network: Network,
@ -329,25 +333,26 @@ class DefaultWalletManagersFacade(
blockchain: Blockchain,
derivationPath: String?,
): WalletManager? {
initMutex.withLock {
val userWallet = getUserWallet(userWalletId)
var walletManager = walletManagersStore.getSyncOrNull(
userWalletId = userWalletId,
blockchain = blockchain,
derivationPath = derivationPath,
)
if (walletManager == null) {
walletManager = walletManagerFactory.createWalletManager(
scanResponse = userWallet.scanResponse,
blockchain = blockchain,
derivationPath = derivationPath?.let { DerivationPath(rawPath = it) },
) ?: return null
)
walletManager ?: return null
walletManagersStore.store(userWalletId, walletManager)
}
return walletManager
}
}
@Deprecated("Will be removed in future")
override suspend fun getOrCreateWalletManager(userWalletId: UserWalletId, network: Network): WalletManager? {

View file

@ -42,10 +42,10 @@ internal class DefaultBlockchainSDKFactory(
dispatchers: CoroutineDispatcherProvider,
) : BlockchainSDKFactory {
private val walletManagerFactory: Flow<WalletManagerFactory?> by lazy(::createWalletManagerFactory)
private val mainScope = CoroutineScope(dispatchers.main)
private val walletManagerFactory: Flow<WalletManagerFactory?> = createWalletManagerFactory()
override suspend fun init() {
coroutineScope {
updateBlockchainSDKConfig()