Updated on 2026-08-14
This commit is contained in:
parent
8541957ee3
commit
189ffd9927
73 changed files with 547 additions and 409 deletions
|
|
@ -2,7 +2,6 @@ package com.tangem.data.common.currency
|
|||
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
||||
|
|
@ -57,23 +56,23 @@ interface CardCryptoCurrencyFactory {
|
|||
/**
|
||||
* Create default coins for multi currency card
|
||||
*
|
||||
* @param scanResponse scan response
|
||||
* @param userWallet user wallet
|
||||
*/
|
||||
fun createDefaultCoinsForMultiCurrencyCard(scanResponse: ScanResponse): List<CryptoCurrency.Coin>
|
||||
fun createDefaultCoinsForMultiCurrencyWallet(userWallet: UserWallet): List<CryptoCurrency.Coin>
|
||||
|
||||
/**
|
||||
* Create primary currency for single currency card
|
||||
*
|
||||
* @param scanResponse scan response
|
||||
* @param userWallet user wallet
|
||||
*/
|
||||
@Throws
|
||||
fun createPrimaryCurrencyForSingleCurrencyCard(scanResponse: ScanResponse): CryptoCurrency
|
||||
fun createPrimaryCurrencyForSingleCurrencyCard(userWallet: UserWallet.Cold): CryptoCurrency
|
||||
|
||||
/**
|
||||
* Create currencies for single currency card with token (like, NODL)
|
||||
*
|
||||
* @param scanResponse scan response
|
||||
* @param userWallet user wallet
|
||||
*/
|
||||
@Throws
|
||||
fun createCurrenciesForSingleCurrencyCardWithToken(scanResponse: ScanResponse): List<CryptoCurrency>
|
||||
fun createCurrenciesForSingleCurrencyCardWithToken(userWallet: UserWallet.Cold): List<CryptoCurrency>
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import com.tangem.blockchainsdk.utils.toCoinId
|
|||
import com.tangem.data.common.network.NetworkFactory
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import timber.log.Timber
|
||||
import com.tangem.blockchain.common.Token as SdkToken
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ class CryptoCurrencyFactory(
|
|||
sdkToken: SdkToken,
|
||||
blockchain: Blockchain,
|
||||
extraDerivationPath: String?,
|
||||
scanResponse: ScanResponse,
|
||||
userWallet: UserWallet,
|
||||
): CryptoCurrency.Token? {
|
||||
if (blockchain == Blockchain.Unknown) {
|
||||
Timber.e("Unable to map the SDK token to the domain token with Unknown blockchain")
|
||||
|
|
@ -56,7 +56,7 @@ class CryptoCurrencyFactory(
|
|||
val network = networkFactory.create(
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = extraDerivationPath,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
) ?: return null
|
||||
|
||||
val id = getTokenId(network, sdkToken)
|
||||
|
|
@ -76,7 +76,7 @@ class CryptoCurrencyFactory(
|
|||
fun createCoin(
|
||||
blockchain: Blockchain,
|
||||
extraDerivationPath: String?,
|
||||
scanResponse: ScanResponse,
|
||||
userWallet: UserWallet,
|
||||
): CryptoCurrency.Coin? {
|
||||
if (blockchain == Blockchain.Unknown) {
|
||||
Timber.e("Unable to map the SDK token to the domain token with Unknown blockchain")
|
||||
|
|
@ -86,15 +86,15 @@ class CryptoCurrencyFactory(
|
|||
val network = networkFactory.create(
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = extraDerivationPath,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
) ?: return null
|
||||
|
||||
return createCoin(network)
|
||||
}
|
||||
|
||||
fun createCoin(networkId: String, extraDerivationPath: String?, scanResponse: ScanResponse): CryptoCurrency.Coin? {
|
||||
fun createCoin(networkId: String, extraDerivationPath: String?, userWallet: UserWallet): CryptoCurrency.Coin? {
|
||||
val blockchain = Blockchain.fromNetworkId(networkId) ?: Blockchain.Unknown
|
||||
return createCoin(blockchain, extraDerivationPath, scanResponse)
|
||||
return createCoin(blockchain, extraDerivationPath, userWallet)
|
||||
}
|
||||
|
||||
fun createCoin(network: Network): CryptoCurrency.Coin {
|
||||
|
|
@ -115,7 +115,7 @@ class CryptoCurrencyFactory(
|
|||
token: Token,
|
||||
networkId: String,
|
||||
extraDerivationPath: String?,
|
||||
scanResponse: ScanResponse,
|
||||
userWallet: UserWallet,
|
||||
): CryptoCurrency.Token? {
|
||||
val sdkToken = SdkToken(
|
||||
name = token.name,
|
||||
|
|
@ -129,7 +129,7 @@ class CryptoCurrencyFactory(
|
|||
sdkToken = sdkToken,
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = extraDerivationPath,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +141,8 @@ class CryptoCurrencyFactory(
|
|||
decimals = cryptoCurrency.decimals,
|
||||
id = cryptoCurrency.id.rawCurrencyId?.value,
|
||||
)
|
||||
val blockchain = Blockchain.fromNetworkId(cryptoCurrency.network.backendId) ?: Blockchain.Unknown
|
||||
val blockchain =
|
||||
Blockchain.fromNetworkId(cryptoCurrency.network.backendId) ?: Blockchain.Unknown
|
||||
val id = getTokenId(network, sdkToken)
|
||||
return CryptoCurrency.Token(
|
||||
id = id,
|
||||
|
|
|
|||
|
|
@ -11,11 +11,9 @@ import com.tangem.domain.common.util.cardTypesResolver
|
|||
import com.tangem.domain.demo.DemoConfig
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.domain.wallets.models.isMultiCurrency
|
||||
import com.tangem.domain.wallets.models.requireColdWallet
|
||||
|
||||
/**
|
||||
* Default implementation of factory for creating list of [CryptoCurrency] for selected card
|
||||
|
|
@ -54,12 +52,12 @@ internal class DefaultCardCryptoCurrencyFactory(
|
|||
|
||||
// single-currency wallet with token (NODL)
|
||||
if (userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) {
|
||||
val currencies = createCurrenciesForSingleCurrencyCardWithToken(userWallet.scanResponse)
|
||||
val currencies = createCurrenciesForSingleCurrencyCardWithToken(userWallet)
|
||||
return mapOf(cardNetwork to currencies)
|
||||
}
|
||||
|
||||
// single-currency wallet
|
||||
val primaryCurrency = createPrimaryCurrencyForSingleCurrencyCard(userWallet.scanResponse)
|
||||
val primaryCurrency = createPrimaryCurrencyForSingleCurrencyCard(userWallet)
|
||||
return mapOf(cardNetwork to listOf(primaryCurrency))
|
||||
}
|
||||
|
||||
|
|
@ -82,11 +80,11 @@ internal class DefaultCardCryptoCurrencyFactory(
|
|||
|
||||
// single-currency wallet with token (NODL)
|
||||
if (userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) {
|
||||
return createCurrenciesForSingleCurrencyCardWithToken(userWallet.scanResponse)
|
||||
return createCurrenciesForSingleCurrencyCardWithToken(userWallet)
|
||||
}
|
||||
|
||||
// single-currency wallet
|
||||
return createPrimaryCurrencyForSingleCurrencyCard(userWallet.scanResponse).let(::listOf)
|
||||
return createPrimaryCurrencyForSingleCurrencyCard(userWallet).let(::listOf)
|
||||
}
|
||||
|
||||
override suspend fun createCurrenciesForMultiCurrencyCard(
|
||||
|
|
@ -98,44 +96,54 @@ internal class DefaultCardCryptoCurrencyFactory(
|
|||
return getMultiWalletCurrencies(userWallet = userWallet, networks = networks)
|
||||
}
|
||||
|
||||
override fun createDefaultCoinsForMultiCurrencyCard(scanResponse: ScanResponse): List<CryptoCurrency.Coin> {
|
||||
require(scanResponse.cardTypesResolver.isMultiwalletAllowed()) { "It isn't multi-currency wallet" }
|
||||
override fun createDefaultCoinsForMultiCurrencyWallet(userWallet: UserWallet): List<CryptoCurrency.Coin> {
|
||||
require(userWallet.isMultiCurrency) { "It isn't multi-currency wallet" }
|
||||
|
||||
val card = scanResponse.card
|
||||
val blockchains = when (userWallet) {
|
||||
is UserWallet.Cold -> {
|
||||
val card = userWallet.scanResponse.card
|
||||
|
||||
var blockchains = if (demoConfig.isDemoCardId(card.cardId)) {
|
||||
demoConfig.demoBlockchains
|
||||
} else {
|
||||
listOf(Blockchain.Bitcoin, Blockchain.Ethereum)
|
||||
}
|
||||
var blockchainsInternal = if (demoConfig.isDemoCardId(card.cardId)) {
|
||||
demoConfig.demoBlockchains
|
||||
} else {
|
||||
listOf(Blockchain.Bitcoin, Blockchain.Ethereum)
|
||||
}
|
||||
|
||||
if (card.isTestCard) {
|
||||
blockchains = blockchains.mapNotNull { it.getTestnetVersion() }
|
||||
if (card.isTestCard) {
|
||||
blockchainsInternal = blockchainsInternal.mapNotNull { it.getTestnetVersion() }
|
||||
}
|
||||
|
||||
blockchainsInternal
|
||||
}
|
||||
|
||||
is UserWallet.Hot -> listOf(Blockchain.Bitcoin, Blockchain.Ethereum)
|
||||
}
|
||||
|
||||
return blockchains.mapNotNull {
|
||||
cryptoCurrencyFactory.createCoin(
|
||||
blockchain = it,
|
||||
extraDerivationPath = null,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun createPrimaryCurrencyForSingleCurrencyCard(scanResponse: ScanResponse): CryptoCurrency {
|
||||
require(scanResponse.cardTypesResolver.isSingleWallet()) { "It isn't single-currency wallet" }
|
||||
override fun createPrimaryCurrencyForSingleCurrencyCard(userWallet: UserWallet.Cold): CryptoCurrency {
|
||||
require(userWallet.scanResponse.cardTypesResolver.isSingleWallet()) {
|
||||
"It isn't single-currency wallet"
|
||||
}
|
||||
|
||||
return with(getSingleWalletCurrencies(scanResponse)) {
|
||||
return with(getSingleWalletCurrencies(userWallet)) {
|
||||
primaryToken ?: coin
|
||||
}
|
||||
}
|
||||
|
||||
override fun createCurrenciesForSingleCurrencyCardWithToken(scanResponse: ScanResponse): List<CryptoCurrency> {
|
||||
require(scanResponse.cardTypesResolver.isSingleWalletWithToken()) {
|
||||
override fun createCurrenciesForSingleCurrencyCardWithToken(userWallet: UserWallet.Cold): List<CryptoCurrency> {
|
||||
require(userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) {
|
||||
"It isn't single-currency wallet with token"
|
||||
}
|
||||
|
||||
return with(getSingleWalletCurrencies(scanResponse)) {
|
||||
return with(getSingleWalletCurrencies(userWallet)) {
|
||||
listOfNotNull(coin, primaryToken)
|
||||
}
|
||||
}
|
||||
|
|
@ -151,7 +159,7 @@ internal class DefaultCardCryptoCurrencyFactory(
|
|||
tokens = response.tokens.filter { token ->
|
||||
networks.any { it.backendId == token.networkId && it.derivationPath.value == token.derivationPath }
|
||||
},
|
||||
scanResponse = userWallet.requireColdWallet().scanResponse, // TODO [REDACTED_TASK_KEY]
|
||||
userWallet = userWallet,
|
||||
)
|
||||
.groupBy(CryptoCurrency::network)
|
||||
|
||||
|
|
@ -169,19 +177,19 @@ internal class DefaultCardCryptoCurrencyFactory(
|
|||
|
||||
return responseCryptoCurrenciesFactory.createCurrencies(
|
||||
tokens = response.tokens.filter { token -> token.networkId in networkIds },
|
||||
scanResponse = userWallet.requireColdWallet().scanResponse, // TODO [REDACTED_TASK_KEY]
|
||||
userWallet = userWallet,
|
||||
)
|
||||
.groupBy { it.network.id.rawId }
|
||||
}
|
||||
|
||||
private fun getSingleWalletCurrencies(scanResponse: ScanResponse): SingleWalletCurrencies {
|
||||
val resolver = scanResponse.cardTypesResolver
|
||||
private fun getSingleWalletCurrencies(userWallet: UserWallet.Cold): SingleWalletCurrencies {
|
||||
val resolver = userWallet.cardTypesResolver
|
||||
val blockchain = resolver.getBlockchain()
|
||||
|
||||
val coin = cryptoCurrencyFactory.createCoin(
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = null,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
)
|
||||
|
||||
requireNotNull(coin) { "Coin for the single currency card cannot be null" }
|
||||
|
|
@ -191,12 +199,15 @@ internal class DefaultCardCryptoCurrencyFactory(
|
|||
sdkToken = token,
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = null,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
)
|
||||
}
|
||||
|
||||
return SingleWalletCurrencies(coin = coin, primaryToken = primaryToken)
|
||||
}
|
||||
|
||||
private data class SingleWalletCurrencies(val coin: CryptoCurrency, val primaryToken: CryptoCurrency?)
|
||||
private data class SingleWalletCurrencies(
|
||||
val coin: CryptoCurrency,
|
||||
val primaryToken: CryptoCurrency?,
|
||||
)
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import com.tangem.data.common.network.NetworkFactory
|
|||
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
|
||||
import com.tangem.domain.common.util.cardTypesResolver
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import com.tangem.blockchain.common.Token as SdkToken
|
||||
|
|
@ -17,41 +17,41 @@ class ResponseCryptoCurrenciesFactory @Inject constructor(
|
|||
private val networkFactory: NetworkFactory,
|
||||
) {
|
||||
|
||||
fun createCurrency(currencyId: String, response: UserTokensResponse, scanResponse: ScanResponse): CryptoCurrency {
|
||||
fun createCurrency(currencyId: String, response: UserTokensResponse, userWallet: UserWallet): CryptoCurrency {
|
||||
return response.tokens
|
||||
.asSequence()
|
||||
.mapNotNull { createCurrency(it, scanResponse) }
|
||||
.mapNotNull { createCurrency(it, userWallet) }
|
||||
.first { it.id.value == currencyId }
|
||||
}
|
||||
|
||||
fun createCurrencies(response: UserTokensResponse, scanResponse: ScanResponse): List<CryptoCurrency> {
|
||||
return createCurrencies(tokens = response.tokens, scanResponse = scanResponse)
|
||||
fun createCurrencies(response: UserTokensResponse, userWallet: UserWallet): List<CryptoCurrency> {
|
||||
return createCurrencies(tokens = response.tokens, userWallet = userWallet)
|
||||
}
|
||||
|
||||
fun createCurrencies(tokens: List<UserTokensResponse.Token>, scanResponse: ScanResponse): List<CryptoCurrency> {
|
||||
fun createCurrencies(tokens: List<UserTokensResponse.Token>, userWallet: UserWallet): List<CryptoCurrency> {
|
||||
return tokens
|
||||
.asSequence()
|
||||
.mapNotNull { createCurrency(it, scanResponse) }
|
||||
.mapNotNull { createCurrency(it, userWallet) }
|
||||
.distinctBy(CryptoCurrency::id)
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun createCurrency(responseToken: UserTokensResponse.Token, scanResponse: ScanResponse): CryptoCurrency? {
|
||||
fun createCurrency(responseToken: UserTokensResponse.Token, userWallet: UserWallet): CryptoCurrency? {
|
||||
var blockchain = Blockchain.fromNetworkId(responseToken.networkId)
|
||||
if (blockchain == null || blockchain == Blockchain.Unknown) {
|
||||
Timber.e("Unable to find a blockchain with the network ID: ${responseToken.networkId}")
|
||||
return null
|
||||
}
|
||||
|
||||
if (scanResponse.cardTypesResolver.isTestCard()) {
|
||||
if (userWallet is UserWallet.Cold && userWallet.scanResponse.cardTypesResolver.isTestCard()) {
|
||||
blockchain = blockchain.getTestnetVersion() ?: blockchain
|
||||
}
|
||||
|
||||
val sdkToken = createSdkToken(responseToken)
|
||||
return if (sdkToken == null) {
|
||||
createCoin(blockchain, responseToken, scanResponse)
|
||||
createCoin(blockchain, responseToken, userWallet)
|
||||
} else {
|
||||
createToken(blockchain, sdkToken, responseToken.derivationPath, scanResponse)
|
||||
createToken(blockchain, sdkToken, responseToken.derivationPath, userWallet)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,12 +70,12 @@ class ResponseCryptoCurrenciesFactory @Inject constructor(
|
|||
private fun createCoin(
|
||||
blockchain: Blockchain,
|
||||
responseToken: UserTokensResponse.Token,
|
||||
scanResponse: ScanResponse,
|
||||
userWallet: UserWallet,
|
||||
): CryptoCurrency.Coin? {
|
||||
val network = networkFactory.create(
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = responseToken.derivationPath,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
) ?: return null
|
||||
|
||||
return CryptoCurrency.Coin(
|
||||
|
|
@ -105,12 +105,12 @@ class ResponseCryptoCurrenciesFactory @Inject constructor(
|
|||
blockchain: Blockchain,
|
||||
sdkToken: Token,
|
||||
responseDerivationPath: String?,
|
||||
scanResponse: ScanResponse,
|
||||
userWallet: UserWallet,
|
||||
): CryptoCurrency.Token? {
|
||||
val network = networkFactory.create(
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = responseDerivationPath,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
) ?: return null
|
||||
|
||||
val id = getTokenId(network, sdkToken)
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ import com.tangem.blockchainsdk.utils.toBlockchain
|
|||
import com.tangem.blockchainsdk.utils.toNetworkId
|
||||
import com.tangem.domain.common.DerivationStyleProvider
|
||||
import com.tangem.domain.common.extensions.canHandleToken
|
||||
import com.tangem.domain.common.util.cardTypesResolver
|
||||
import com.tangem.domain.common.util.derivationStyleProvider
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -31,19 +30,18 @@ class NetworkFactory @Inject constructor(
|
|||
*
|
||||
* @param blockchain blockchain
|
||||
* @param extraDerivationPath extra derivation path
|
||||
* @param scanResponse scan response
|
||||
* @param userWallet user wallet
|
||||
*/
|
||||
fun create(blockchain: Blockchain, extraDerivationPath: String?, scanResponse: ScanResponse): Network? {
|
||||
fun create(blockchain: Blockchain, extraDerivationPath: String?, userWallet: UserWallet): Network? {
|
||||
return create(
|
||||
blockchain = blockchain,
|
||||
derivationPath = createDerivationPath(
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = extraDerivationPath,
|
||||
cardDerivationStyleProvider = scanResponse.derivationStyleProvider,
|
||||
cardDerivationStyleProvider = userWallet.derivationStyleProvider,
|
||||
),
|
||||
canHandleTokens = scanResponse.card.canHandleToken(
|
||||
canHandleTokens = userWallet.canHandleToken(
|
||||
blockchain = blockchain,
|
||||
cardTypesResolver = scanResponse.cardTypesResolver,
|
||||
excludedBlockchains = excludedBlockchains,
|
||||
),
|
||||
)
|
||||
|
|
@ -54,17 +52,16 @@ class NetworkFactory @Inject constructor(
|
|||
*
|
||||
* @param networkId network id
|
||||
* @param derivationPath derivation path
|
||||
* @param scanResponse scan response
|
||||
* @param userWallet user wallet
|
||||
*/
|
||||
fun create(networkId: Network.ID, derivationPath: Network.DerivationPath, scanResponse: ScanResponse): Network? {
|
||||
fun create(networkId: Network.ID, derivationPath: Network.DerivationPath, userWallet: UserWallet): Network? {
|
||||
val blockchain = networkId.toBlockchain()
|
||||
|
||||
return create(
|
||||
blockchain = blockchain,
|
||||
derivationPath = derivationPath,
|
||||
canHandleTokens = scanResponse.card.canHandleToken(
|
||||
canHandleTokens = userWallet.canHandleToken(
|
||||
blockchain = blockchain,
|
||||
cardTypesResolver = scanResponse.cardTypesResolver,
|
||||
excludedBlockchains = excludedBlockchains,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
|
|||
val multiWallet = model.multiWallet
|
||||
|
||||
// Act
|
||||
val actual = factory.createDefaultCoinsForMultiCurrencyCard(scanResponse = multiWallet.scanResponse)
|
||||
val actual = factory.createDefaultCoinsForMultiCurrencyWallet(multiWallet)
|
||||
|
||||
// Assert
|
||||
val expected = model.expected
|
||||
|
|
@ -355,7 +355,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
|
|||
|
||||
// Act
|
||||
val actual = runCatching {
|
||||
factory.createPrimaryCurrencyForSingleCurrencyCard(scanResponse = singleWallet.scanResponse)
|
||||
factory.createPrimaryCurrencyForSingleCurrencyCard(singleWallet)
|
||||
}
|
||||
|
||||
// Assert
|
||||
|
|
@ -405,7 +405,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
|
|||
|
||||
// Act
|
||||
val actual = runCatching {
|
||||
factory.createCurrenciesForSingleCurrencyCardWithToken(scanResponse = userWallet.scanResponse)
|
||||
factory.createCurrenciesForSingleCurrencyCardWithToken(userWallet)
|
||||
}
|
||||
|
||||
// Assert
|
||||
|
|
@ -554,7 +554,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
|
|||
sdkToken = userWallet.scanResponse.cardTypesResolver.getPrimaryToken()!!,
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = null,
|
||||
scanResponse = userWallet.scanResponse,
|
||||
userWallet = userWallet,
|
||||
)!!
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.tangem.blockchain.common.Blockchain
|
|||
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
|
||||
import com.tangem.common.test.domain.card.MockScanResponseFactory
|
||||
import com.tangem.common.test.domain.token.MockCryptoCurrencyFactory
|
||||
import com.tangem.common.test.domain.wallet.MockUserWalletFactory
|
||||
import com.tangem.common.test.utils.ProvideTestModels
|
||||
import com.tangem.domain.common.DerivationStyleProvider
|
||||
import com.tangem.domain.common.configs.GenericCardConfig
|
||||
|
|
@ -12,6 +13,7 @@ import com.tangem.domain.common.configs.MultiWalletCardConfig
|
|||
import com.tangem.domain.common.util.derivationStyleProvider
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.junit.jupiter.api.Nested
|
||||
|
|
@ -43,7 +45,7 @@ class NetworkFactoryTest {
|
|||
val actual = networkFactory.create(
|
||||
blockchain = Blockchain.Ethereum,
|
||||
extraDerivationPath = null,
|
||||
scanResponse = createMultiWalletScanResponse(),
|
||||
userWallet = createUserWallet(),
|
||||
)
|
||||
|
||||
// Assert
|
||||
|
|
@ -59,14 +61,14 @@ class NetworkFactoryTest {
|
|||
networkFactory.create(
|
||||
blockchain = model.blockchain,
|
||||
extraDerivationPath = model.extraDerivationPath,
|
||||
scanResponse = model.scanResponse,
|
||||
userWallet = model.userWallet,
|
||||
)
|
||||
}
|
||||
is CreateTestModel.Second -> {
|
||||
networkFactory.create(
|
||||
networkId = model.networkId,
|
||||
derivationPath = model.derivationPath,
|
||||
scanResponse = model.scanResponse,
|
||||
userWallet = model.userWallet,
|
||||
)
|
||||
}
|
||||
is CreateTestModel.Third -> {
|
||||
|
|
@ -89,27 +91,27 @@ class NetworkFactoryTest {
|
|||
CreateTestModel.First(
|
||||
blockchain = Blockchain.Unknown,
|
||||
extraDerivationPath = null, // never-mind
|
||||
scanResponse = createMultiWalletScanResponse(), // never-mind
|
||||
userWallet = createUserWallet(),
|
||||
expected = null,
|
||||
),
|
||||
createFirst(
|
||||
extraDerivationPath = null,
|
||||
scanResponse = createGenericScanResponse(), // default derivation path is null
|
||||
userWallet = createUserWallet(createGenericScanResponse()), // default derivation path is null
|
||||
expectedDerivationPath = Network.DerivationPath.None,
|
||||
),
|
||||
createFirst(
|
||||
extraDerivationPath = null,
|
||||
scanResponse = createMultiWalletScanResponse(),
|
||||
userWallet = createUserWallet(),
|
||||
expectedDerivationPath = Network.DerivationPath.Card(value = "m/44'/60'/0'/0/0"), // use default
|
||||
),
|
||||
createFirst(
|
||||
extraDerivationPath = "m/44'/60'/0'/0/0", // as default
|
||||
scanResponse = createMultiWalletScanResponse(),
|
||||
userWallet = createUserWallet(),
|
||||
expectedDerivationPath = Network.DerivationPath.Card(value = "m/44'/60'/0'/0/0"),
|
||||
),
|
||||
createFirst(
|
||||
extraDerivationPath = "m/84'/0'/0'/0/0",
|
||||
scanResponse = createMultiWalletScanResponse(),
|
||||
userWallet = createUserWallet(),
|
||||
expectedDerivationPath = Network.DerivationPath.Custom(value = "m/84'/0'/0'/0/0"),
|
||||
),
|
||||
// endregion
|
||||
|
|
@ -118,23 +120,23 @@ class NetworkFactoryTest {
|
|||
CreateTestModel.Second(
|
||||
networkId = Network.ID(value = "1", derivationPath = Network.DerivationPath.None),
|
||||
derivationPath = Network.DerivationPath.None, // never-mind
|
||||
scanResponse = createMultiWalletScanResponse(), // never-mind
|
||||
userWallet = createUserWallet(), // never-mind
|
||||
expected = null,
|
||||
),
|
||||
createSecond(
|
||||
scanResponse = createGenericScanResponse(), // default derivation path is null
|
||||
userWallet = createUserWallet(createGenericScanResponse()), // default derivation path is null
|
||||
derivationPath = Network.DerivationPath.None,
|
||||
),
|
||||
createSecond(
|
||||
scanResponse = createMultiWalletScanResponse(),
|
||||
userWallet = createUserWallet(),
|
||||
derivationPath = Network.DerivationPath.None,
|
||||
),
|
||||
createSecond(
|
||||
scanResponse = createMultiWalletScanResponse(),
|
||||
userWallet = createUserWallet(),
|
||||
derivationPath = Network.DerivationPath.Card(value = "m/44'/60'/0'/0/0"),
|
||||
),
|
||||
createSecond(
|
||||
scanResponse = createMultiWalletScanResponse(),
|
||||
userWallet = createUserWallet(),
|
||||
derivationPath = Network.DerivationPath.Custom(value = "m/84'/0'/0'/0/0"),
|
||||
),
|
||||
// endregion
|
||||
|
|
@ -176,13 +178,13 @@ class NetworkFactoryTest {
|
|||
|
||||
private fun createFirst(
|
||||
extraDerivationPath: String?,
|
||||
scanResponse: ScanResponse,
|
||||
userWallet: UserWallet,
|
||||
expectedDerivationPath: Network.DerivationPath,
|
||||
): CreateTestModel.First {
|
||||
return CreateTestModel.First(
|
||||
blockchain = Blockchain.Ethereum,
|
||||
extraDerivationPath = extraDerivationPath,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
expected = MockCryptoCurrencyFactory().ethereum.network.copy(
|
||||
id = Network.ID(
|
||||
value = Blockchain.Ethereum.id,
|
||||
|
|
@ -195,13 +197,13 @@ class NetworkFactoryTest {
|
|||
}
|
||||
|
||||
private fun createSecond(
|
||||
scanResponse: ScanResponse,
|
||||
userWallet: UserWallet,
|
||||
derivationPath: Network.DerivationPath,
|
||||
): CreateTestModel.Second {
|
||||
return CreateTestModel.Second(
|
||||
networkId = Network.ID(value = Blockchain.Ethereum.id, derivationPath = derivationPath),
|
||||
derivationPath = derivationPath,
|
||||
scanResponse = scanResponse,
|
||||
userWallet = userWallet,
|
||||
expected = MockCryptoCurrencyFactory().ethereum.network.copy(
|
||||
id = Network.ID(
|
||||
value = Blockchain.Ethereum.id,
|
||||
|
|
@ -232,6 +234,10 @@ class NetworkFactoryTest {
|
|||
)
|
||||
}
|
||||
|
||||
private fun createUserWallet(scanResponse: ScanResponse = createMultiWalletScanResponse()): UserWallet.Cold {
|
||||
return MockUserWalletFactory.create(scanResponse)
|
||||
}
|
||||
|
||||
private fun createMultiWalletScanResponse(): ScanResponse {
|
||||
return MockScanResponseFactory.create(
|
||||
cardConfig = MultiWalletCardConfig,
|
||||
|
|
@ -254,14 +260,14 @@ class NetworkFactoryTest {
|
|||
data class First(
|
||||
val blockchain: Blockchain,
|
||||
val extraDerivationPath: String?,
|
||||
val scanResponse: ScanResponse,
|
||||
val userWallet: UserWallet,
|
||||
override val expected: Network?,
|
||||
) : CreateTestModel
|
||||
|
||||
data class Second(
|
||||
val networkId: Network.ID,
|
||||
val derivationPath: Network.DerivationPath,
|
||||
val scanResponse: ScanResponse,
|
||||
val userWallet: UserWallet,
|
||||
override val expected: Network?,
|
||||
) : CreateTestModel
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue