Updated on 2026-08-14
This commit is contained in:
parent
518183728d
commit
2ee782528d
2 changed files with 26 additions and 24 deletions
|
|
@ -29,14 +29,15 @@ fun Blockchain.minimalAmount(): BigDecimal {
|
|||
return 1.toBigDecimal().movePointLeft(decimals())
|
||||
}
|
||||
|
||||
fun Blockchain.getCurve(): EllipticCurve? {
|
||||
fun Blockchain.getSupportedCurves(): List<EllipticCurve>? {
|
||||
return when (this) {
|
||||
Blockchain.Unknown -> null
|
||||
Blockchain.Bitcoin, Blockchain.BitcoinTestnet, Blockchain.BitcoinCash, Blockchain.Litecoin,
|
||||
Blockchain.Ducatus, Blockchain.Ethereum, Blockchain.EthereumTestnet, Blockchain.RSK,
|
||||
Blockchain.XRP, Blockchain.Binance, Blockchain.BinanceTestnet -> EllipticCurve.Secp256k1
|
||||
Blockchain.Tezos, Blockchain.Cardano, Blockchain.CardanoShelley, Blockchain.Stellar ->
|
||||
EllipticCurve.Ed25519
|
||||
Blockchain.XRP, Blockchain.Binance, Blockchain.BinanceTestnet -> listOf(EllipticCurve.Secp256k1)
|
||||
Blockchain.Tezos -> listOf(EllipticCurve.Secp256k1, EllipticCurve.Ed25519)
|
||||
Blockchain.Cardano, Blockchain.CardanoShelley, Blockchain.Stellar ->
|
||||
listOf(EllipticCurve.Ed25519)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,29 +5,30 @@ import com.tangem.blockchain.common.WalletManager
|
|||
import com.tangem.blockchain.common.WalletManagerFactory
|
||||
import com.tangem.commands.common.card.Card
|
||||
import com.tangem.commands.common.card.EllipticCurve
|
||||
import com.tangem.commands.wallet.CardWallet
|
||||
|
||||
fun WalletManagerFactory.makeWalletManagerForApp(card: Card, blockchain: Blockchain): WalletManager? {
|
||||
val curve = blockchain.getCurve() ?: return null
|
||||
val publicKey = card.getWallets().firstOrNull { it.curve == curve }?.publicKey ?: return null
|
||||
return makeWalletManager(card.cardId, publicKey, blockchain, curve)
|
||||
fun WalletManagerFactory.makeWalletManagerForApp(
|
||||
card: Card,
|
||||
blockchain: Blockchain,
|
||||
): WalletManager? {
|
||||
val supportedCurves = blockchain.getSupportedCurves() ?: return null
|
||||
val wallets = card.getWallets().filter { wallet -> supportedCurves.contains(wallet.curve) }
|
||||
val wallet = selectWallet(wallets)
|
||||
val publicKey = wallet?.publicKey ?: return null
|
||||
val curveToUse = wallet.curve ?: return null
|
||||
return makeWalletManager(card.cardId, publicKey, blockchain, curveToUse)
|
||||
}
|
||||
|
||||
private fun selectWallet(wallets: List<CardWallet>): CardWallet? {
|
||||
return when (wallets.size) {
|
||||
0 -> null
|
||||
1 -> wallets[0]
|
||||
else -> wallets.firstOrNull { it.curve == EllipticCurve.Secp256k1 } ?: wallets[0]
|
||||
}
|
||||
}
|
||||
|
||||
fun WalletManagerFactory.makeWalletManagersForApp(
|
||||
card: Card, blockchains: List<Blockchain>
|
||||
card: Card, blockchains: List<Blockchain>,
|
||||
): List<WalletManager> {
|
||||
return makeWalletManagersForCurve(card, blockchains, EllipticCurve.Secp256k1) +
|
||||
makeWalletManagersForCurve(card, blockchains, EllipticCurve.Ed25519)
|
||||
return blockchains.mapNotNull { blockchain -> makeWalletManagerForApp(card, blockchain) }
|
||||
}
|
||||
|
||||
fun WalletManagerFactory.makeWalletManagersForCurve(
|
||||
card: Card, blockchains: List<Blockchain>, curve: EllipticCurve
|
||||
): List<WalletManager> {
|
||||
val blockchainsForCurve = blockchains.filter { it.getCurve() == curve }
|
||||
val walletPublicKey = card.getWallets().firstOrNull { it.curve == curve }?.publicKey
|
||||
|
||||
return if (walletPublicKey != null) {
|
||||
makeWalletManagers(card.cardId, walletPublicKey, blockchainsForCurve, curve)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue