Updated on 2026-08-14
This commit is contained in:
parent
ebc4350919
commit
7e23a3a63b
18 changed files with 336 additions and 42 deletions
|
|
@ -74,7 +74,7 @@ fun WalletManagerFactory.makeWalletManagerForApp(
|
|||
}
|
||||
}
|
||||
|
||||
private fun makePublicKey(
|
||||
fun makePublicKey(
|
||||
seedKey: ByteArray,
|
||||
blockchain: Blockchain,
|
||||
derivationPath: DerivationPath,
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ import com.tangem.domain.walletmanager.utils.*
|
|||
import com.tangem.domain.walletmanager.utils.WalletManagerFactory
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.domain.wallets.models.requireColdWallet
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
|
|
@ -371,21 +370,31 @@ class DefaultWalletManagersFacade(
|
|||
initMutex.withLock {
|
||||
val userWallet = getUserWallet(userWalletId)
|
||||
|
||||
userWallet.requireColdWallet() // TODO [REDACTED_TASK_KEY]
|
||||
|
||||
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) },
|
||||
)
|
||||
walletManager ?: return null
|
||||
val path = derivationPath?.let { DerivationPath(rawPath = it) }
|
||||
|
||||
if (walletManager == null) {
|
||||
when (userWallet) {
|
||||
is UserWallet.Hot -> {
|
||||
walletManager = walletManagerFactory.createWalletManagerForHot(
|
||||
hotWallet = userWallet,
|
||||
blockchain = blockchain,
|
||||
derivationPath = path,
|
||||
)
|
||||
}
|
||||
is UserWallet.Cold -> {
|
||||
walletManager = walletManagerFactory.createWalletManager(
|
||||
scanResponse = userWallet.scanResponse,
|
||||
blockchain = blockchain,
|
||||
derivationPath = path,
|
||||
)
|
||||
}
|
||||
}
|
||||
walletManager ?: return null
|
||||
walletManagersStore.store(userWalletId, walletManager)
|
||||
}
|
||||
return walletManager
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ import com.tangem.blockchain.common.WalletManager
|
|||
import com.tangem.blockchainsdk.BlockchainSDKFactory
|
||||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import com.tangem.domain.common.DerivationStyleProvider
|
||||
import com.tangem.domain.common.extensions.makePublicKey
|
||||
import com.tangem.domain.common.extensions.makeWalletManagerForApp
|
||||
import com.tangem.domain.common.util.derivationStyleProvider
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import timber.log.Timber
|
||||
|
||||
internal class WalletManagerFactory(
|
||||
|
|
@ -34,6 +36,42 @@ internal class WalletManagerFactory(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun createWalletManagerForHot(
|
||||
hotWallet: UserWallet.Hot,
|
||||
blockchain: Blockchain,
|
||||
derivationPath: DerivationPath?,
|
||||
): WalletManager? {
|
||||
val curve = blockchain.getSupportedCurves().first()
|
||||
val selectedWallet = hotWallet.wallets.orEmpty().firstOrNull { it.curve == curve }
|
||||
?: return null
|
||||
return try {
|
||||
val factory = blockchainSDKFactory.getWalletManagerFactorySync() ?: return null
|
||||
|
||||
if (derivationPath == null) {
|
||||
factory.createLegacyWalletManager(
|
||||
blockchain = blockchain,
|
||||
walletPublicKey = selectedWallet.publicKey,
|
||||
curve = selectedWallet.curve,
|
||||
)
|
||||
} else {
|
||||
factory.createWalletManager(
|
||||
blockchain = blockchain,
|
||||
publicKey = makePublicKey(
|
||||
seedKey = selectedWallet.publicKey,
|
||||
blockchain = blockchain,
|
||||
derivationPath = derivationPath,
|
||||
derivedWalletKeys = selectedWallet.derivedKeys,
|
||||
isWallet2 = true,
|
||||
) ?: return null,
|
||||
curve = selectedWallet.curve,
|
||||
)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
Timber.w(e, "Failed to create wallet manager for $blockchain")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDerivationParams(
|
||||
derivationPath: DerivationPath?,
|
||||
derivationStyleProvider: DerivationStyleProvider,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue