Updated on 2026-08-14
This commit is contained in:
commit
d6bee4ab41
5 changed files with 36 additions and 37 deletions
|
|
@ -1,11 +1,8 @@
|
|||
package com.tangem.tap.domain.configurable.warningMessage
|
||||
|
||||
import com.tangem.TangemSdkError
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.tangem_sdk_new.ui.animation.VoidCallback
|
||||
import com.tangem.tap.common.extensions.containsAny
|
||||
import com.tangem.tap.features.wallet.redux.WalletAction
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.wallet.R
|
||||
|
||||
/**
|
||||
|
|
@ -68,6 +65,10 @@ class WarningMessagesManager(
|
|||
sortByPriority()
|
||||
}
|
||||
|
||||
fun removeWarnings(messageRes: Int) {
|
||||
warningsList.removeIf { it.messageResId == messageRes }
|
||||
}
|
||||
|
||||
private fun sortByPriority() {
|
||||
warningsList.sortBy { it.priority.ordinal }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
@ -54,6 +54,10 @@ class WarningsMiddleware {
|
|||
if (action.remainingSignatures != null &&
|
||||
action.remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING
|
||||
) {
|
||||
store.state.globalState.warningManager
|
||||
?.removeWarnings(
|
||||
messageRes = R.string.warning_low_signatures_format
|
||||
)
|
||||
addWarningMessage(
|
||||
warning =
|
||||
WarningMessagesManager.remainingSignaturesNotEnough(action.remainingSignatures),
|
||||
|
|
@ -102,10 +106,6 @@ class WarningsMiddleware {
|
|||
if (remainingSignatures != null &&
|
||||
remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING
|
||||
) {
|
||||
getWarnings()
|
||||
.find { it.messageResId == R.string.warning_low_signatures_format }
|
||||
?.let { previousWarning -> hideWarning(previousWarning) }
|
||||
|
||||
addWarningMessage(
|
||||
WarningMessagesManager.remainingSignaturesNotEnough(
|
||||
remainingSignatures
|
||||
|
|
@ -115,7 +115,7 @@ class WarningsMiddleware {
|
|||
}
|
||||
|
||||
private fun checkIfWarningNeeded(
|
||||
card: Card
|
||||
card: Card,
|
||||
): WarningMessage? {
|
||||
if (card.isTwinCard()) return null
|
||||
|
||||
|
|
@ -196,8 +196,4 @@ class WarningsMiddleware {
|
|||
store.state.walletState.blockchains
|
||||
)
|
||||
}
|
||||
|
||||
private fun hideWarning(warning: WarningMessage) {
|
||||
store.state.globalState.warningManager?.hideWarning(warning)
|
||||
}
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ class OnWalletLoadedReducer {
|
|||
val tokenFiatAmount = tokenFiatRate?.let { tokenAmount.value?.toFiatString(it, fiatCurrencySymbol) }
|
||||
TokenData(
|
||||
tokenAmount.value?.toFormattedCurrencyString(
|
||||
tokenAmount.decimals, token.symbol
|
||||
token.decimals, token.symbol
|
||||
) ?: "",
|
||||
tokenAmount.currencySymbol, tokenFiatAmount
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue