Updated on 2026-08-14
This commit is contained in:
parent
6aab25427d
commit
e04ac1fb2c
19 changed files with 273 additions and 8 deletions
|
|
@ -1,5 +1,8 @@
|
|||
package com.tangem.data.account.utils
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.core.configtoggle.FeatureToggles
|
||||
import com.tangem.core.configtoggle.feature.FeatureTogglesManager
|
||||
import com.tangem.data.account.converter.CryptoPortfolioConverter
|
||||
import com.tangem.data.common.currency.UserTokensResponseFactory
|
||||
import com.tangem.data.common.network.NetworkFactory
|
||||
|
|
@ -31,6 +34,7 @@ internal class DefaultWalletAccountsResponseFactory @Inject constructor(
|
|||
private val cryptoPortfolioCF: CryptoPortfolioConverter.Factory,
|
||||
private val userTokensResponseFactory: UserTokensResponseFactory,
|
||||
private val networkFactory: NetworkFactory,
|
||||
private val featureTogglesManager: FeatureTogglesManager,
|
||||
) {
|
||||
|
||||
fun create(userWalletId: UserWalletId, userTokensResponse: UserTokensResponse?): GetWalletAccountsResponse {
|
||||
|
|
@ -69,6 +73,21 @@ internal class DefaultWalletAccountsResponseFactory @Inject constructor(
|
|||
accountId = userWallet?.let {
|
||||
AccountId.forCryptoPortfolio(userWalletId = it.walletId, derivationIndex = DerivationIndex.Main)
|
||||
},
|
||||
extraBlockchains = userWallet?.extraDefaultBlockchains().orEmpty(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun UserWallet.extraDefaultBlockchains(): List<Blockchain> {
|
||||
val batchId = (this as? UserWallet.Cold)?.scanResponse?.card?.batchId ?: return emptyList()
|
||||
return when {
|
||||
batchId == ADI_PROMO_BATCH_ID &&
|
||||
featureTogglesManager.isFeatureEnabled(FeatureToggles.AND_15402_ADI_MAIN_SCREEN_DEFAULT_ENABLED) ->
|
||||
listOf(Blockchain.Adi)
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val ADI_PROMO_BATCH_ID = "BB000053"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
package com.tangem.data.account.utils
|
||||
|
||||
import com.google.common.truth.Truth
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.core.configtoggle.FeatureToggles
|
||||
import com.tangem.core.configtoggle.feature.FeatureTogglesManager
|
||||
import com.tangem.data.account.converter.CryptoPortfolioConverter
|
||||
import com.tangem.data.account.converter.createWalletAccountDTO
|
||||
import com.tangem.data.account.utils.GetWalletAccountsResponseExtTest.Companion.createUserToken
|
||||
|
|
@ -32,12 +35,14 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
private val cryptoPortfolioConverter = mockk<CryptoPortfolioConverter>()
|
||||
private val userTokensResponseFactory = mockk<UserTokensResponseFactory>()
|
||||
private val networkFactory = mockk<NetworkFactory>()
|
||||
private val featureTogglesManager = mockk<FeatureTogglesManager>()
|
||||
|
||||
private val factory = DefaultWalletAccountsResponseFactory(
|
||||
userWalletsListRepository = userWalletsListRepository,
|
||||
cryptoPortfolioCF = cryptoPortfolioCF,
|
||||
userTokensResponseFactory = userTokensResponseFactory,
|
||||
networkFactory = networkFactory,
|
||||
featureTogglesManager = featureTogglesManager,
|
||||
)
|
||||
|
||||
private val userWalletId = UserWalletId("011")
|
||||
|
|
@ -75,6 +80,7 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
userWallet = null,
|
||||
networkFactory = networkFactory,
|
||||
accountId = null,
|
||||
extraBlockchains = emptyList(),
|
||||
)
|
||||
} returns userTokensResponse
|
||||
|
||||
|
|
@ -100,6 +106,7 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
userWallet = null,
|
||||
networkFactory = networkFactory,
|
||||
accountId = null,
|
||||
extraBlockchains = emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -129,6 +136,7 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
userWallet = userWallet,
|
||||
networkFactory = networkFactory,
|
||||
accountId = accounts.first().accountId,
|
||||
extraBlockchains = emptyList(),
|
||||
)
|
||||
} returns defaultResponse
|
||||
|
||||
|
|
@ -159,6 +167,7 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
userWallet = userWallet,
|
||||
networkFactory = networkFactory,
|
||||
accountId = accounts.first().accountId,
|
||||
extraBlockchains = emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -188,6 +197,7 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
userWallet = userWallet,
|
||||
networkFactory = networkFactory,
|
||||
accountId = accounts.first().accountId,
|
||||
extraBlockchains = emptyList(),
|
||||
)
|
||||
} returns defaultResponse
|
||||
|
||||
|
|
@ -210,6 +220,138 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create passes ADI as extra blockchain when batch is BB000053 and toggle is on`() = runTest {
|
||||
// Arrange
|
||||
val userWallet = mockk<UserWallet.Cold>(relaxed = true) {
|
||||
every { walletId } returns userWalletId
|
||||
every { scanResponse.card.batchId } returns "BB000053"
|
||||
}
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(userWallet))
|
||||
every {
|
||||
featureTogglesManager.isFeatureEnabled(FeatureToggles.AND_15402_ADI_MAIN_SCREEN_DEFAULT_ENABLED)
|
||||
} returns true
|
||||
|
||||
val accounts = AccountList.empty(userWallet.walletId).accounts
|
||||
.filterIsInstance<Account.CryptoPortfolio>()
|
||||
val defaultResponse = UserTokensResponse(
|
||||
group = UserTokensResponse.GroupType.NETWORK,
|
||||
sort = UserTokensResponse.SortType.BALANCE,
|
||||
tokens = emptyList(),
|
||||
)
|
||||
every {
|
||||
userTokensResponseFactory.createDefaultResponse(
|
||||
userWallet = userWallet,
|
||||
networkFactory = networkFactory,
|
||||
accountId = accounts.first().accountId,
|
||||
extraBlockchains = listOf(Blockchain.Adi),
|
||||
)
|
||||
} returns defaultResponse
|
||||
every { cryptoPortfolioConverter.convertListBack(accounts) } returns emptyList()
|
||||
|
||||
// Act
|
||||
factory.create(userWalletId, null)
|
||||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userTokensResponseFactory.createDefaultResponse(
|
||||
userWallet = userWallet,
|
||||
networkFactory = networkFactory,
|
||||
accountId = accounts.first().accountId,
|
||||
extraBlockchains = listOf(Blockchain.Adi),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create passes no extra blockchains when batch is BB000053 but toggle is off`() = runTest {
|
||||
// Arrange
|
||||
val userWallet = mockk<UserWallet.Cold>(relaxed = true) {
|
||||
every { walletId } returns userWalletId
|
||||
every { scanResponse.card.batchId } returns "BB000053"
|
||||
}
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(userWallet))
|
||||
every {
|
||||
featureTogglesManager.isFeatureEnabled(FeatureToggles.AND_15402_ADI_MAIN_SCREEN_DEFAULT_ENABLED)
|
||||
} returns false
|
||||
|
||||
val accounts = AccountList.empty(userWallet.walletId).accounts
|
||||
.filterIsInstance<Account.CryptoPortfolio>()
|
||||
val defaultResponse = UserTokensResponse(
|
||||
group = UserTokensResponse.GroupType.NETWORK,
|
||||
sort = UserTokensResponse.SortType.BALANCE,
|
||||
tokens = emptyList(),
|
||||
)
|
||||
every {
|
||||
userTokensResponseFactory.createDefaultResponse(
|
||||
userWallet = userWallet,
|
||||
networkFactory = networkFactory,
|
||||
accountId = accounts.first().accountId,
|
||||
extraBlockchains = emptyList(),
|
||||
)
|
||||
} returns defaultResponse
|
||||
every { cryptoPortfolioConverter.convertListBack(accounts) } returns emptyList()
|
||||
|
||||
// Act
|
||||
factory.create(userWalletId, null)
|
||||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userTokensResponseFactory.createDefaultResponse(
|
||||
userWallet = userWallet,
|
||||
networkFactory = networkFactory,
|
||||
accountId = accounts.first().accountId,
|
||||
extraBlockchains = emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create passes no extra blockchains when batch is not BB000053 even if toggle is on`() = runTest {
|
||||
// Arrange
|
||||
val userWallet = mockk<UserWallet.Cold>(relaxed = true) {
|
||||
every { walletId } returns userWalletId
|
||||
every { scanResponse.card.batchId } returns "AC000001"
|
||||
}
|
||||
|
||||
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(userWallet))
|
||||
every {
|
||||
featureTogglesManager.isFeatureEnabled(FeatureToggles.AND_15402_ADI_MAIN_SCREEN_DEFAULT_ENABLED)
|
||||
} returns true
|
||||
|
||||
val accounts = AccountList.empty(userWallet.walletId).accounts
|
||||
.filterIsInstance<Account.CryptoPortfolio>()
|
||||
val defaultResponse = UserTokensResponse(
|
||||
group = UserTokensResponse.GroupType.NETWORK,
|
||||
sort = UserTokensResponse.SortType.BALANCE,
|
||||
tokens = emptyList(),
|
||||
)
|
||||
every {
|
||||
userTokensResponseFactory.createDefaultResponse(
|
||||
userWallet = userWallet,
|
||||
networkFactory = networkFactory,
|
||||
accountId = accounts.first().accountId,
|
||||
extraBlockchains = emptyList(),
|
||||
)
|
||||
} returns defaultResponse
|
||||
every { cryptoPortfolioConverter.convertListBack(accounts) } returns emptyList()
|
||||
|
||||
// Act
|
||||
factory.create(userWalletId, null)
|
||||
|
||||
// Assert
|
||||
coVerifyOrder {
|
||||
userTokensResponseFactory.createDefaultResponse(
|
||||
userWallet = userWallet,
|
||||
networkFactory = networkFactory,
|
||||
accountId = accounts.first().accountId,
|
||||
extraBlockchains = emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create returns response with assigned tokens`() = runTest {
|
||||
// Arrange
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.data.common.currency
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchainsdk.utils.toCoinId
|
||||
import com.tangem.blockchainsdk.utils.toNetworkId
|
||||
import com.tangem.data.common.network.NetworkFactory
|
||||
|
|
@ -54,9 +55,14 @@ class UserTokensResponseFactory @Inject constructor() {
|
|||
userWallet: UserWallet?,
|
||||
networkFactory: NetworkFactory,
|
||||
accountId: AccountId?,
|
||||
extraBlockchains: List<Blockchain> = emptyList(),
|
||||
): UserTokensResponse {
|
||||
val tokens = if (userWallet != null) {
|
||||
getDefaultWalletBlockchains(userWallet = userWallet, demoConfig = DemoConfig)
|
||||
getDefaultWalletBlockchains(
|
||||
userWallet = userWallet,
|
||||
demoConfig = DemoConfig,
|
||||
extraBlockchains = extraBlockchains,
|
||||
)
|
||||
.map { blockchain ->
|
||||
val derivationPath = networkFactory.createDerivationPath(
|
||||
blockchain = blockchain,
|
||||
|
|
|
|||
|
|
@ -375,6 +375,7 @@ class NetworkFactory @Inject constructor(
|
|||
Blockchain.Linea, Blockchain.LineaTestnet,
|
||||
Blockchain.ArbitrumNova,
|
||||
Blockchain.Plasma, Blockchain.PlasmaTestnet,
|
||||
Blockchain.Adi, Blockchain.AdiTestnet,
|
||||
Blockchain.Monad, Blockchain.MonadTestnet,
|
||||
-> Network.TransactionExtrasType.NONE
|
||||
// endregion
|
||||
|
|
|
|||
|
|
@ -8,10 +8,16 @@ import com.tangem.domain.models.wallet.UserWallet
|
|||
/**
|
||||
* Returns the default blockchains for the multi-currency wallet.
|
||||
*
|
||||
* @param userWallet The user's wallet, which can be either a cold or hot wallet.
|
||||
* @param demoConfig Configuration for demo cards, which may specify different default blockchains.
|
||||
* @param userWallet The user's wallet, which can be either a cold or hot wallet.
|
||||
* @param demoConfig Configuration for demo cards, which may specify different default blockchains.
|
||||
* @param extraBlockchains Additional blockchains appended on top of the standard defaults for non-demo cold wallets
|
||||
* (e.g. batch- or promo-specific entries resolved by the caller).
|
||||
*/
|
||||
fun getDefaultWalletBlockchains(userWallet: UserWallet, demoConfig: DemoConfig): Collection<Blockchain> {
|
||||
fun getDefaultWalletBlockchains(
|
||||
userWallet: UserWallet,
|
||||
demoConfig: DemoConfig,
|
||||
extraBlockchains: List<Blockchain> = emptyList(),
|
||||
): Collection<Blockchain> {
|
||||
return when (userWallet) {
|
||||
is UserWallet.Cold -> {
|
||||
val card = userWallet.scanResponse.card
|
||||
|
|
@ -19,7 +25,7 @@ fun getDefaultWalletBlockchains(userWallet: UserWallet, demoConfig: DemoConfig):
|
|||
var blockchainsInternal = if (demoConfig.isDemoCardId(card.cardId)) {
|
||||
demoConfig.getDemoBlockchains(card.cardId)
|
||||
} else {
|
||||
listOf(Blockchain.Bitcoin, Blockchain.Ethereum)
|
||||
listOf(Blockchain.Bitcoin, Blockchain.Ethereum) + extraBlockchains
|
||||
}
|
||||
|
||||
if (card.isTestCard) {
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ public val Blockchain.mercuryoNetwork: String?
|
|||
Blockchain.Linea, Blockchain.LineaTestnet -> null
|
||||
Blockchain.ArbitrumNova -> null
|
||||
Blockchain.Plasma, Blockchain.PlasmaTestnet -> null
|
||||
Blockchain.Adi, Blockchain.AdiTestnet -> null
|
||||
Blockchain.Monad, Blockchain.MonadTestnet -> null
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue