Updated on 2026-08-14

This commit is contained in:
Tangem 2021-05-24 12:54:58 +00:00
commit d6bee4ab41
5 changed files with 36 additions and 37 deletions

View file

@ -1,11 +1,8 @@
package com.tangem.tap.domain.configurable.warningMessage package com.tangem.tap.domain.configurable.warningMessage
import com.tangem.TangemSdkError
import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.Blockchain
import com.tangem.tangem_sdk_new.ui.animation.VoidCallback import com.tangem.tangem_sdk_new.ui.animation.VoidCallback
import com.tangem.tap.common.extensions.containsAny 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 import com.tangem.wallet.R
/** /**
@ -68,6 +65,10 @@ class WarningMessagesManager(
sortByPriority() sortByPriority()
} }
fun removeWarnings(messageRes: Int) {
warningsList.removeIf { it.messageResId == messageRes }
}
private fun sortByPriority() { private fun sortByPriority() {
warningsList.sortBy { it.priority.ordinal } warningsList.sortBy { it.priority.ordinal }
} }

View file

@ -29,14 +29,15 @@ fun Blockchain.minimalAmount(): BigDecimal {
return 1.toBigDecimal().movePointLeft(decimals()) return 1.toBigDecimal().movePointLeft(decimals())
} }
fun Blockchain.getCurve(): EllipticCurve? { fun Blockchain.getSupportedCurves(): List<EllipticCurve>? {
return when (this) { return when (this) {
Blockchain.Unknown -> null Blockchain.Unknown -> null
Blockchain.Bitcoin, Blockchain.BitcoinTestnet, Blockchain.BitcoinCash, Blockchain.Litecoin, Blockchain.Bitcoin, Blockchain.BitcoinTestnet, Blockchain.BitcoinCash, Blockchain.Litecoin,
Blockchain.Ducatus, Blockchain.Ethereum, Blockchain.EthereumTestnet, Blockchain.RSK, Blockchain.Ducatus, Blockchain.Ethereum, Blockchain.EthereumTestnet, Blockchain.RSK,
Blockchain.XRP, Blockchain.Binance, Blockchain.BinanceTestnet -> EllipticCurve.Secp256k1 Blockchain.XRP, Blockchain.Binance, Blockchain.BinanceTestnet -> listOf(EllipticCurve.Secp256k1)
Blockchain.Tezos, Blockchain.Cardano, Blockchain.CardanoShelley, Blockchain.Stellar -> Blockchain.Tezos -> listOf(EllipticCurve.Secp256k1, EllipticCurve.Ed25519)
EllipticCurve.Ed25519 Blockchain.Cardano, Blockchain.CardanoShelley, Blockchain.Stellar ->
listOf(EllipticCurve.Ed25519)
} }
} }

View file

@ -5,29 +5,30 @@ import com.tangem.blockchain.common.WalletManager
import com.tangem.blockchain.common.WalletManagerFactory import com.tangem.blockchain.common.WalletManagerFactory
import com.tangem.commands.common.card.Card import com.tangem.commands.common.card.Card
import com.tangem.commands.common.card.EllipticCurve import com.tangem.commands.common.card.EllipticCurve
import com.tangem.commands.wallet.CardWallet
fun WalletManagerFactory.makeWalletManagerForApp(card: Card, blockchain: Blockchain): WalletManager? { fun WalletManagerFactory.makeWalletManagerForApp(
val curve = blockchain.getCurve() ?: return null card: Card,
val publicKey = card.getWallets().firstOrNull { it.curve == curve }?.publicKey ?: return null blockchain: Blockchain,
return makeWalletManager(card.cardId, publicKey, blockchain, curve) ): 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( fun WalletManagerFactory.makeWalletManagersForApp(
card: Card, blockchains: List<Blockchain> card: Card, blockchains: List<Blockchain>,
): List<WalletManager> { ): List<WalletManager> {
return makeWalletManagersForCurve(card, blockchains, EllipticCurve.Secp256k1) + return blockchains.mapNotNull { blockchain -> makeWalletManagerForApp(card, blockchain) }
makeWalletManagersForCurve(card, blockchains, EllipticCurve.Ed25519)
}
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()
}
} }

View file

@ -54,6 +54,10 @@ class WarningsMiddleware {
if (action.remainingSignatures != null && if (action.remainingSignatures != null &&
action.remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING action.remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING
) { ) {
store.state.globalState.warningManager
?.removeWarnings(
messageRes = R.string.warning_low_signatures_format
)
addWarningMessage( addWarningMessage(
warning = warning =
WarningMessagesManager.remainingSignaturesNotEnough(action.remainingSignatures), WarningMessagesManager.remainingSignaturesNotEnough(action.remainingSignatures),
@ -102,10 +106,6 @@ class WarningsMiddleware {
if (remainingSignatures != null && if (remainingSignatures != null &&
remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING
) { ) {
getWarnings()
.find { it.messageResId == R.string.warning_low_signatures_format }
?.let { previousWarning -> hideWarning(previousWarning) }
addWarningMessage( addWarningMessage(
WarningMessagesManager.remainingSignaturesNotEnough( WarningMessagesManager.remainingSignaturesNotEnough(
remainingSignatures remainingSignatures
@ -115,7 +115,7 @@ class WarningsMiddleware {
} }
private fun checkIfWarningNeeded( private fun checkIfWarningNeeded(
card: Card card: Card,
): WarningMessage? { ): WarningMessage? {
if (card.isTwinCard()) return null if (card.isTwinCard()) return null
@ -196,8 +196,4 @@ class WarningsMiddleware {
store.state.walletState.blockchains store.state.walletState.blockchains
) )
} }
private fun hideWarning(warning: WarningMessage) {
store.state.globalState.warningManager?.hideWarning(warning)
}
} }

View file

@ -113,7 +113,7 @@ class OnWalletLoadedReducer {
val tokenFiatAmount = tokenFiatRate?.let { tokenAmount.value?.toFiatString(it, fiatCurrencySymbol) } val tokenFiatAmount = tokenFiatRate?.let { tokenAmount.value?.toFiatString(it, fiatCurrencySymbol) }
TokenData( TokenData(
tokenAmount.value?.toFormattedCurrencyString( tokenAmount.value?.toFormattedCurrencyString(
tokenAmount.decimals, token.symbol token.decimals, token.symbol
) ?: "", ) ?: "",
tokenAmount.currencySymbol, tokenFiatAmount tokenAmount.currencySymbol, tokenFiatAmount
) )