Updated on 2026-08-14

This commit is contained in:
Tangem 2022-04-17 16:03:51 +03:00
parent 845b08091e
commit 4fa8ad0f9b
4 changed files with 86 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import com.tangem.blockchain.common.address.AddressType
import com.tangem.blockchain.extensions.isAboveZero
import com.tangem.common.extensions.isZero
import com.tangem.domain.common.TapWorkarounds.derivationStyle
import com.tangem.domain.features.addCustomToken.CustomCurrency
import com.tangem.tap.common.entities.Button
import com.tangem.tap.common.extensions.toQrCode
import com.tangem.tap.common.redux.StateDialog
@ -17,6 +18,7 @@ import com.tangem.tap.domain.extensions.sellIsAllowed
import com.tangem.tap.domain.extensions.toSendableAmounts
import com.tangem.tap.domain.tokens.BlockchainNetwork
import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsState
import com.tangem.tap.features.tokens.redux.TokenWithBlockchain
import com.tangem.tap.features.wallet.models.PendingTransaction
import com.tangem.tap.features.wallet.models.toPendingTransactions
import com.tangem.tap.features.wallet.models.toPendingTransactionsForToken
@ -439,6 +441,28 @@ sealed interface Currency {
)
}
}
fun fromCustomCurrency(customCurrency: CustomCurrency): Currency {
return when (customCurrency) {
is CustomCurrency.CustomBlockchain -> Blockchain(
blockchain = customCurrency.network,
derivationPath = customCurrency.derivationPath?.rawPath
)
is CustomCurrency.CustomToken -> Token(
token = customCurrency.token,
blockchain = customCurrency.network,
derivationPath = customCurrency.derivationPath?.rawPath,
)
}
}
fun fromTokenWithBlockchain(tokenWithBlockchain: TokenWithBlockchain): Token {
return Currency.Token(
token = tokenWithBlockchain.token,
blockchain = tokenWithBlockchain.blockchain,
derivationPath = null
)
}
}
}

View file

@ -1,7 +1,6 @@
package com.tangem.domain
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.Token
import com.tangem.blockchain.common.DerivationStyle
/**
[REDACTED_AUTHOR]
@ -11,8 +10,30 @@ import com.tangem.blockchain.common.Token
// to appropriate parts of module
sealed interface DomainWrapped {
data class TokenWithBlockchain(
val token: Token,
val blockchain: Blockchain
)
// Mirror reflection ot the com.tangem.tap.features.wallet.redux.Currency
sealed interface Currency {
val blockchain: com.tangem.blockchain.common.Blockchain
val currencySymbol: String
val derivationPath: String?
data class Token(
val token: com.tangem.blockchain.common.Token,
override val blockchain: com.tangem.blockchain.common.Blockchain,
override val derivationPath: String?
) : Currency {
override val currencySymbol = token.symbol
}
data class Blockchain(
override val blockchain: com.tangem.blockchain.common.Blockchain,
override val derivationPath: String?
) : Currency {
override val currencySymbol: String = blockchain.currency
}
fun isCustomCurrency(derivationStyle: DerivationStyle?): Boolean {
if (derivationPath == null || derivationStyle == null) return false
return derivationPath != blockchain.derivationPath(derivationStyle)?.rawPath
}
}
}

View file

@ -3,9 +3,13 @@ package com.tangem.domain.common
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.Token
import com.tangem.common.card.Card
import com.tangem.common.card.EllipticCurve
import com.tangem.common.card.WalletData
import com.tangem.common.extensions.ByteArrayKey
import com.tangem.common.extensions.toMapKey
import com.tangem.common.hdWallet.DerivationPath
import com.tangem.domain.common.TapWorkarounds.getTangemNoteBlockchain
import com.tangem.domain.common.TapWorkarounds.isTestCard
import com.tangem.operations.CommandResponse
import com.tangem.operations.backup.PrimaryCard
import com.tangem.operations.derivation.ExtendedPublicKeysMap
@ -48,6 +52,33 @@ data class ScanResponse(
fun twinsIsTwinned(): Boolean =
card.isTangemTwins() && walletData != null && secondTwinPublicKey != null
fun hasDerivation(blockchain: Blockchain, rawDerivationPath: String): Boolean {
return hasDerivation(blockchain, DerivationPath(rawDerivationPath))
}
fun hasDerivation(blockchain: Blockchain, derivationPath: DerivationPath): Boolean {
val isTestnet = card.isTestCard || blockchain.isTestnet()
return when {
Blockchain.secp256k1Blockchains(isTestnet).contains(blockchain) -> {
hasDerivation(EllipticCurve.Secp256k1, derivationPath)
}
Blockchain.ed25519OnlyBlockchains(isTestnet).contains(blockchain) -> {
hasDerivation(EllipticCurve.Ed25519, derivationPath)
}
else -> false
}
}
fun hasDerivation(curve: EllipticCurve, derivationPath: DerivationPath): Boolean {
val foundWallet = card.wallets.firstOrNull { it.curve == curve }
?: return false
val extendedPublicKeysMap = derivedKeys[foundWallet.publicKey.toMapKey()] ?: return false
val extendedPublicKey = extendedPublicKeysMap[derivationPath]
return extendedPublicKey != null
}
}
enum class ProductType {

View file

@ -97,6 +97,10 @@ internal abstract class BaseStoreHub<State>(
}
}
protected fun cancelAll() {
actionsAndJobs.forEach { (_, job) -> job.cancel() }
}
protected abstract suspend fun handleAction(action: Action, storeState: DomainState, cancel: ValueCallback<Action>)
protected abstract fun reduceAction(action: Action, state: State): State