Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-03 17:41:42 +04:00
parent b861d63402
commit 652009a7bf
29 changed files with 271 additions and 256 deletions

View file

@ -9,6 +9,7 @@ import com.tangem.domain.account.status.usecase.RecoverCryptoPortfolioUseCase
import com.tangem.domain.account.status.utils.CryptoCurrencyBalanceFetcher
import com.tangem.domain.account.tokens.MainAccountTokensMigration
import com.tangem.domain.account.usecase.*
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.feature.referral.data.ExternalReferralRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.Module
@ -94,10 +95,12 @@ internal object AccountDomainModule {
@Provides
@Singleton
fun provideIsAccountsModeEnabledUseCase(
userWalletsListRepository: UserWalletsListRepository,
accountsCRUDRepository: AccountsCRUDRepository,
accountsFeatureToggles: AccountsFeatureToggles,
): IsAccountsModeEnabledUseCase {
return IsAccountsModeEnabledUseCase(
userWalletsListRepository = userWalletsListRepository,
crudRepository = accountsCRUDRepository,
accountsFeatureToggles = accountsFeatureToggles,
)

View file

@ -30,19 +30,16 @@ import com.tangem.hot.sdk.TangemHotSdk
import com.tangem.hot.sdk.model.HotWalletId
import com.tangem.sdk.api.TangemSdkManager
import com.tangem.tap.domain.userWalletList.model.UserWalletEncryptionKey
import com.tangem.tap.domain.userWalletList.utils.encryptionKey
import com.tangem.tap.domain.userWalletList.utils.lock
import com.tangem.tap.domain.userWalletList.utils.publicInformation
import com.tangem.tap.domain.userWalletList.utils.sensitiveInformation
import com.tangem.tap.domain.userWalletList.utils.toUserWallets
import com.tangem.tap.domain.userWalletList.utils.updateWith
import com.tangem.tap.domain.userWalletList.utils.*
import com.tangem.utils.Provider
import com.tangem.utils.ProviderSuspend
import com.tangem.utils.coroutines.runSuspendCatching
import com.tangem.utils.extensions.addOrReplace
import com.tangem.utils.extensions.indexOfFirstOrNull
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
@ -67,8 +64,17 @@ internal class DefaultUserWalletsListRepository(
override val userWallets = MutableStateFlow<List<UserWallet>?>(null)
override val selectedUserWallet = MutableStateFlow<UserWallet?>(null)
private val mutex = Mutex()
override fun getSyncOrNull(id: UserWalletId): UserWallet? {
return userWallets.value?.find { it.walletId == id }
}
override fun getSyncStrict(id: UserWalletId): UserWallet {
return requireNotNull(getSyncOrNull(id)) { "Unable to find user wallet with provided ID: $id" }
}
override suspend fun load() {
mutex.withLock {
if (userWallets.value != null) return
@ -103,6 +109,13 @@ internal class DefaultUserWalletsListRepository(
}
}
override fun loadAndGet(): Flow<List<UserWallet>> = flow {
load()
userWallets.collect {
emit(requireNotNull(it))
}
}
override suspend fun userWalletsSync(): List<UserWallet> {
load()
return requireNotNull(userWallets.value) {
@ -289,8 +302,7 @@ internal class DefaultUserWalletsListRepository(
}
val scanResponse = unlockMethod.scanResponse ?: run {
val res = tangemSdkManagerProvider().scanProduct()
when (res) {
when (val res = tangemSdkManagerProvider().scanProduct()) {
is CompletionResult.Failure -> raise(UnlockWalletError.UserCancelled)
is CompletionResult.Success -> res.data
}
@ -467,9 +479,7 @@ internal class DefaultUserWalletsListRepository(
authMode = true, // In auth mode user wallet can be deleted after 30 failed attempts
hasBiometry = hasBiometry(),
)
val result = passwordRequester.requestPassword(attemptRequest)
return when (result) {
return when (val result = passwordRequester.requestPassword(attemptRequest)) {
HotWalletPasswordRequester.Result.Dismiss -> {
passwordRequester.dismiss()
UnlockWalletError.UserCancelled.left()

View file

@ -1,6 +1,6 @@
package com.tangem.data.account.converter
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWalletId
import javax.inject.Inject
@ -10,7 +10,7 @@ import javax.inject.Inject
* @property getWalletAccountsResponseCF factory for creating a wallet accounts response converter
* @property accountsListCF factory for creating an account list converter
* @property cryptoPortfolioCF factory for creating a crypto portfolio converter
* @property userWalletsStore store for accessing user wallet data
* @property userWalletsListRepository repository for getting user wallets
*
* @constructor Creates an instance of the container with injected factories.
*
@ -20,23 +20,23 @@ internal class AccountConverterFactoryContainer @Inject constructor(
private val getWalletAccountsResponseCF: GetWalletAccountsResponseConverter.Factory,
private val accountsListCF: AccountListConverter.Factory,
private val cryptoPortfolioCF: CryptoPortfolioConverter.Factory,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
) {
fun createWalletAccountsResponseConverter(userWalletId: UserWalletId): GetWalletAccountsResponseConverter {
val userWallet = userWalletsStore.getSyncStrict(key = userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(id = userWalletId)
return getWalletAccountsResponseCF.create(userWallet)
}
fun createAccountListConverter(userWalletId: UserWalletId): AccountListConverter {
val userWallet = userWalletsStore.getSyncStrict(key = userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(id = userWalletId)
return accountsListCF.create(userWallet)
}
fun createCryptoPortfolioConverter(userWalletId: UserWalletId): CryptoPortfolioConverter {
val userWallet = userWalletsStore.getSyncStrict(key = userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(id = userWalletId)
return cryptoPortfolioCF.create(userWallet)
}

View file

@ -22,7 +22,6 @@ import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.di.NetworkMoshi
import com.tangem.datasource.local.accounts.AccountTokenMigrationStore
import com.tangem.datasource.local.datastore.RuntimeStateStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.datasource.utils.MoshiDataStoreSerializer
import com.tangem.datasource.utils.mapWithStringKeyTypes
import com.tangem.datasource.utils.setTypes
@ -56,7 +55,6 @@ internal object AccountDataModule {
tangemTechApi: TangemTechApi,
walletAccountsSaver: WalletAccountsSaver,
accountsResponseStoreFactory: AccountsResponseStoreFactory,
userWalletsStore: UserWalletsStore,
userTokensSaver: UserTokensSaver,
accountConverterFactoryContainer: AccountConverterFactoryContainer,
@ApplicationContext context: Context,
@ -67,7 +65,6 @@ internal object AccountDataModule {
walletAccountsSaver = walletAccountsSaver,
accountsResponseStoreFactory = accountsResponseStoreFactory,
archivedAccountsStoreFactory = ArchivedAccountsStoreFactory,
userWalletsStore = userWalletsStore,
userTokensSaver = userTokensSaver,
archivedAccountsETagStore = RuntimeStateStore(emptyMap()),
convertersContainer = accountConverterFactoryContainer,

View file

@ -2,9 +2,9 @@ package com.tangem.data.account.fetcher
import arrow.core.Either
import arrow.core.raise.either
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.fetcher.MultiAccountListFetcher
import com.tangem.domain.account.fetcher.SingleAccountListFetcher
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import kotlinx.coroutines.coroutineScope
@ -17,13 +17,13 @@ import javax.inject.Inject
* Implementation of [MultiAccountListFetcher]
*
* @property singleAccountListFetcher instance of [SingleAccountListFetcher] to fetch accounts for a single wallet
* @property userWalletsStore instance of [UserWalletsStore] to get all user wallets
* @property userWalletsListRepository repository for getting user wallets
*
[REDACTED_AUTHOR]
*/
internal class DefaultMultiAccountListFetcher @Inject constructor(
private val singleAccountListFetcher: SingleAccountListFetcher,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
) : MultiAccountListFetcher {
override suspend fun invoke(params: MultiAccountListFetcher.Params): Either<Throwable, Unit> = either {
@ -58,7 +58,9 @@ internal class DefaultMultiAccountListFetcher @Inject constructor(
}
}
MultiAccountListFetcher.Params.All -> {
val userWalletsIds = userWalletsStore.userWalletsSync.map(UserWallet::walletId).toSet()
val userWalletsIds = userWalletsListRepository.userWallets.value.orEmpty()
.map(UserWallet::walletId)
.toSet()
invoke(params = MultiAccountListFetcher.Params.Set(ids = userWalletsIds)).bind()
}

View file

@ -4,7 +4,7 @@ import arrow.core.Option
import arrow.core.some
import com.tangem.data.account.store.AccountsResponseStoreFactory
import com.tangem.data.common.currency.ResponseCryptoCurrenciesFactory
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency
@ -20,7 +20,7 @@ import kotlinx.coroutines.flow.*
* Implementation of [MultiWalletCryptoCurrenciesProducer] that produces crypto currencies of all accounts
*
* @property params params
* @property userWalletsStore UserWallet's store
* @property userWalletsListRepository repository for getting user wallets
* @property accountsResponseStoreFactory factory to create store with accounts response
* @property responseCryptoCurrenciesFactory factory for creating [CryptoCurrency] from `UserTokensResponse`
* @property dispatchers dispatchers
@ -29,7 +29,7 @@ import kotlinx.coroutines.flow.*
*/
internal class AccountListCryptoCurrenciesProducer @AssistedInject constructor(
@Assisted val params: MultiWalletCryptoCurrenciesProducer.Params,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val accountsResponseStoreFactory: AccountsResponseStoreFactory,
private val responseCryptoCurrenciesFactory: ResponseCryptoCurrenciesFactory,
override val flowProducerTools: FlowProducerTools,
@ -40,7 +40,7 @@ internal class AccountListCryptoCurrenciesProducer @AssistedInject constructor(
@Suppress("NullableToStringCall")
override fun produce(): Flow<Set<CryptoCurrency>> {
val userWallet = userWalletsStore.getSyncStrict(key = params.userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(id = params.userWalletId)
if (!userWallet.isMultiCurrency) {
error("${this::class.simpleName ?: this::class.toString()} supports only multi-currency wallet")

View file

@ -2,9 +2,9 @@ package com.tangem.data.account.producer
import arrow.core.Option
import arrow.core.some
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.account.producer.MultiAccountListProducer
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
@ -19,7 +19,8 @@ import kotlinx.coroutines.flow.*
* Produces a list of [AccountList]s for all user wallets.
*
* @property params params
* @property userWalletsStore store that provides user wallets
* @property flowProducerTools tools for producing flows
* @property userWalletsListRepository repository for getting user wallets
* @property walletAccountListFlowFactory builder to create flows of [AccountList] for each wallet
* @property dispatchers coroutine dispatchers provider
*
@ -28,7 +29,7 @@ import kotlinx.coroutines.flow.*
internal class DefaultMultiAccountListProducer @AssistedInject constructor(
@Assisted val params: Unit,
override val flowProducerTools: FlowProducerTools,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val walletAccountListFlowFactory: WalletAccountListFlowFactory,
private val dispatchers: CoroutineDispatcherProvider,
) : MultiAccountListProducer {
@ -37,7 +38,7 @@ internal class DefaultMultiAccountListProducer @AssistedInject constructor(
@OptIn(ExperimentalCoroutinesApi::class)
override fun produce(): Flow<List<AccountList>> {
return userWalletsStore.userWallets
return userWalletsListRepository.loadAndGet()
.map { it.map(UserWallet::walletId) }
.distinctUntilChanged()
.flatMapLatest { ids ->

View file

@ -4,7 +4,7 @@ import arrow.core.Option
import arrow.core.some
import com.tangem.data.common.currency.ResponseCryptoCurrenciesFactory
import com.tangem.datasource.local.token.UserTokensResponseStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency
@ -20,7 +20,8 @@ import kotlinx.coroutines.flow.*
* Default implementation of [MultiWalletCryptoCurrenciesProducer]
*
* @property params params
* @property userWalletsStore UserWallet's store
* @property flowProducerTools tools for producing flows
* @property userWalletsListRepository repository for getting user wallets
* @property userTokensResponseStore store of `UserTokensResponse`
* @property responseCryptoCurrenciesFactory factory for creating [CryptoCurrency] from `UserTokensResponse`
* @property dispatchers dispatchers
@ -30,7 +31,7 @@ import kotlinx.coroutines.flow.*
internal class DefaultMultiWalletCryptoCurrenciesProducer @AssistedInject constructor(
@Assisted val params: MultiWalletCryptoCurrenciesProducer.Params,
override val flowProducerTools: FlowProducerTools,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val userTokensResponseStore: UserTokensResponseStore,
private val responseCryptoCurrenciesFactory: ResponseCryptoCurrenciesFactory,
private val dispatchers: CoroutineDispatcherProvider,
@ -39,7 +40,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducer @AssistedInject constr
override val fallback: Option<Set<CryptoCurrency>> = emptySet<CryptoCurrency>().some()
override fun produce(): Flow<Set<CryptoCurrency>> {
val userWallet = userWalletsStore.getSyncStrict(key = params.userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(id = params.userWalletId)
if (!userWallet.isMultiCurrency) {
error("${this::class.simpleName ?: this::class.toString()} supports only multi-currency wallet")

View file

@ -4,9 +4,9 @@ import com.tangem.data.account.converter.AccountListConverter
import com.tangem.data.account.store.AccountsResponseStore
import com.tangem.data.account.store.AccountsResponseStoreFactory
import com.tangem.data.common.currency.CardCryptoCurrencyFactory
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.models.wallet.isMultiCurrency
@ -17,6 +17,7 @@ import javax.inject.Inject
/**
* Factory that creates a flow of [AccountList] for a specific [UserWallet]
*
* @property userWalletsListRepository repository to get user wallets
* @property accountsResponseStoreFactory factory to create [AccountsResponseStore]
* @property accountListConverterFactory factory to create [AccountListConverter]
* @property cardCryptoCurrencyFactory factory to create supported crypto currencies for a card
@ -24,14 +25,14 @@ import javax.inject.Inject
[REDACTED_AUTHOR]
*/
internal class WalletAccountListFlowFactory @Inject constructor(
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val accountsResponseStoreFactory: AccountsResponseStoreFactory,
private val accountListConverterFactory: AccountListConverter.Factory,
private val cardCryptoCurrencyFactory: CardCryptoCurrencyFactory,
) {
fun create(userWalletId: UserWalletId): Flow<AccountList> {
val userWallet = userWalletsStore.getSyncStrict(userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
return if (userWallet.isMultiCurrency) {
createForMultiWallet(userWallet)

View file

@ -22,7 +22,6 @@ import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.api.tangemTech.models.account.GetWalletAccountsResponse
import com.tangem.datasource.api.tangemTech.models.account.toUserTokensResponse
import com.tangem.datasource.local.datastore.RuntimeStateStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.datasource.utils.getSyncOrNull
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.account.models.ArchivedAccount
@ -30,7 +29,6 @@ import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.account.AccountName
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.extensions.replaceBy
@ -48,7 +46,6 @@ internal class DefaultAccountsCRUDRepository(
private val walletAccountsSaver: WalletAccountsSaver,
private val accountsResponseStoreFactory: AccountsResponseStoreFactory,
private val archivedAccountsStoreFactory: ArchivedAccountsStoreFactory,
private val userWalletsStore: UserWalletsStore,
private val userTokensSaver: UserTokensSaver,
private val archivedAccountsETagStore: RuntimeStateStore<Map<String, String?>>,
private val convertersContainer: AccountConverterFactoryContainer,
@ -205,14 +202,6 @@ internal class DefaultAccountsCRUDRepository(
.map { it?.accounts?.size.toOption() }
}
override fun getUserWallet(userWalletId: UserWalletId): UserWallet {
return userWalletsStore.getSyncStrict(userWalletId)
}
override fun getUserWallets(): Flow<List<UserWallet>> = userWalletsStore.userWallets
override fun getUserWalletsSync(): List<UserWallet> = userWalletsStore.userWalletsSync
override fun checkDefaultAccountName(accountList: AccountList, accountName: AccountName) {
val hasDefaultName = accountList.accounts.any { it.accountName is AccountName.DefaultMain }

View file

@ -6,8 +6,8 @@ import com.tangem.data.common.network.NetworkFactory
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
import com.tangem.datasource.api.tangemTech.models.account.GetWalletAccountsResponse
import com.tangem.datasource.api.tangemTech.models.account.WalletAccountDTO
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.account.DerivationIndex
@ -18,7 +18,7 @@ import javax.inject.Inject
/**
* Factory to create default [GetWalletAccountsResponse].
*
* @property userWalletsStore store to get user wallet information
* @property userWalletsListRepository repository to get user wallets
* @property cryptoPortfolioCF converter factory to convert crypto portfolio accounts
* @property userTokensResponseFactory factory to create [UserTokensResponse]
* @property networkFactory factory to create network derivation path
@ -26,14 +26,14 @@ import javax.inject.Inject
[REDACTED_AUTHOR]
*/
internal class DefaultWalletAccountsResponseFactory @Inject constructor(
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val cryptoPortfolioCF: CryptoPortfolioConverter.Factory,
private val userTokensResponseFactory: UserTokensResponseFactory,
private val networkFactory: NetworkFactory,
) {
fun create(userWalletId: UserWalletId, userTokensResponse: UserTokensResponse?): GetWalletAccountsResponse {
val userWallet = userWalletsStore.getSyncOrNull(userWalletId)
val userWallet = userWalletsListRepository.getSyncOrNull(userWalletId)
val accountDTOs = userWallet?.let(::createDefaultAccountDTOs).orEmpty()
val response = userTokensResponse.orDefault(userWallet = userWallet)

View file

@ -2,9 +2,9 @@ package com.tangem.data.account.fetcher
import arrow.core.left
import arrow.core.right
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.fetcher.MultiAccountListFetcher
import com.tangem.domain.account.fetcher.SingleAccountListFetcher
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.test.core.assertEitherLeft
@ -19,9 +19,12 @@ import org.junit.jupiter.api.TestInstance
class DefaultMultiAccountListFetcherTest {
private val singleAccountListFetcher: SingleAccountListFetcher = mockk()
private val userWalletsStore: UserWalletsStore = mockk(relaxUnitFun = true)
private val userWalletsListRepository: UserWalletsListRepository = mockk(relaxUnitFun = true)
private val fetcher = DefaultMultiAccountListFetcher(singleAccountListFetcher, userWalletsStore)
private val fetcher = DefaultMultiAccountListFetcher(
singleAccountListFetcher = singleAccountListFetcher,
userWalletsListRepository = userWalletsListRepository,
)
private val userWalletId1 = UserWalletId("011")
private val userWalletId2 = UserWalletId("012")
@ -35,7 +38,7 @@ class DefaultMultiAccountListFetcherTest {
@AfterEach
fun tearDown() {
clearMocks(singleAccountListFetcher, userWalletsStore)
clearMocks(singleAccountListFetcher, userWalletsListRepository)
}
@Test
@ -98,7 +101,7 @@ class DefaultMultiAccountListFetcherTest {
// Arrange
val params = MultiAccountListFetcher.Params.All
every { userWalletsStore.userWalletsSync } returns listOf(userWallets.first())
every { userWalletsListRepository.userWallets.value } returns listOf(userWallets.first())
coEvery {
singleAccountListFetcher(params = SingleAccountListFetcher.Params(userWalletId1))
@ -111,7 +114,7 @@ class DefaultMultiAccountListFetcherTest {
assertEitherRight(actual)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsStore.userWalletsSync
userWalletsListRepository.userWallets.value
singleAccountListFetcher(params = SingleAccountListFetcher.Params(userWalletId1))
}
}
@ -121,7 +124,7 @@ class DefaultMultiAccountListFetcherTest {
// Arrange
val params = MultiAccountListFetcher.Params.All
every { userWalletsStore.userWalletsSync } returns userWallets
every { userWalletsListRepository.userWallets.value } returns userWallets
val exception = Exception("Fetch failed")
coEvery {
@ -145,7 +148,7 @@ class DefaultMultiAccountListFetcherTest {
assertEitherLeft(actual, expected)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsStore.userWalletsSync
userWalletsListRepository.userWallets.value
singleAccountListFetcher(params = SingleAccountListFetcher.Params(userWalletId1))
singleAccountListFetcher(params = SingleAccountListFetcher.Params(userWalletId2))
}

View file

@ -1,8 +1,8 @@
package com.tangem.data.account.producer
import com.google.common.truth.Truth
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.TokensSortType
import com.tangem.domain.models.wallet.UserWallet
@ -27,15 +27,15 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class DefaultMultiAccountListProducerTest {
private val userWalletsStore: UserWalletsStore = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk()
private val walletAccountListFlowFactory: WalletAccountListFlowFactory = mockk()
private val flowProducerTools: FlowProducerTools = mockk()
private val producer = DefaultMultiAccountListProducer(
params = Unit,
userWalletsStore = userWalletsStore,
walletAccountListFlowFactory = walletAccountListFlowFactory,
flowProducerTools = flowProducerTools,
userWalletsListRepository = userWalletsListRepository,
walletAccountListFlowFactory = walletAccountListFlowFactory,
dispatchers = TestingCoroutineDispatcherProvider(),
)
@ -46,14 +46,14 @@ class DefaultMultiAccountListProducerTest {
@AfterEach
fun tearDownEach() {
clearMocks(userWalletsStore, walletAccountListFlowFactory)
clearMocks(userWalletsListRepository, walletAccountListFlowFactory)
}
@Test
fun produce() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsStore.userWallets } returns userWalletsFlow
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
val accountList = AccountList.empty(userWalletId)
every { walletAccountListFlowFactory.create(userWalletId) } returns flowOf(accountList)
@ -66,7 +66,7 @@ class DefaultMultiAccountListProducerTest {
Truth.assertThat(actual).containsExactly(expected)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsStore.userWallets
userWalletsListRepository.loadAndGet()
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -75,7 +75,7 @@ class DefaultMultiAccountListProducerTest {
fun `flow will updated if factoryFlow is updated`() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsStore.userWallets } returns userWalletsFlow
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
val accountList = AccountList.empty(userWalletId)
val updatedAccountList = AccountList.empty(userWalletId = userWalletId, sortType = TokensSortType.NONE)
@ -98,9 +98,9 @@ class DefaultMultiAccountListProducerTest {
Truth.assertThat(secondEmission).containsExactly(listOf(updatedAccountList))
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsStore.userWallets
userWalletsListRepository.loadAndGet()
walletAccountListFlowFactory.create(userWalletId)
userWalletsStore.userWallets
userWalletsListRepository.loadAndGet()
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -109,7 +109,7 @@ class DefaultMultiAccountListProducerTest {
fun `flow is filtered the same response`() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsStore.userWallets } returns userWalletsFlow
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
val accountList = AccountList.empty(userWalletId)
val factoryFlow = MutableStateFlow<AccountList?>(null)
@ -131,9 +131,9 @@ class DefaultMultiAccountListProducerTest {
Truth.assertThat(secondEmission).containsExactly(listOf(accountList))
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsStore.userWallets
userWalletsListRepository.loadAndGet()
walletAccountListFlowFactory.create(userWalletId)
userWalletsStore.userWallets
userWalletsListRepository.loadAndGet()
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -143,7 +143,7 @@ class DefaultMultiAccountListProducerTest {
fun `flow returns empty list if factory throws exception`() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsStore.userWallets } returns userWalletsFlow
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
val exception = RuntimeException("Converter error")
every { walletAccountListFlowFactory.create(userWalletId) } throws exception
@ -156,7 +156,7 @@ class DefaultMultiAccountListProducerTest {
Truth.assertThat(actual).containsExactly(expected)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsStore.userWallets
userWalletsListRepository.loadAndGet()
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -165,7 +165,7 @@ class DefaultMultiAccountListProducerTest {
fun `flow is empty if userWalletsFlow returns empty flow`() = runTest {
// Arrange
val userWalletsFlow = emptyFlow<List<UserWallet>>()
every { userWalletsStore.userWallets } returns userWalletsFlow
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
// Act
val actual = producer.produce().let(::getEmittedValues)
@ -173,7 +173,7 @@ class DefaultMultiAccountListProducerTest {
// Assert
Truth.assertThat(actual).isEmpty() // no emissions
coVerify(exactly = 1) { userWalletsStore.userWallets }
coVerify(exactly = 1) { userWalletsListRepository.loadAndGet() }
coVerify(inverse = true) { walletAccountListFlowFactory.create(any()) }
}
@ -181,7 +181,7 @@ class DefaultMultiAccountListProducerTest {
fun `flow is empty if factory returns empty flow`() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsStore.userWallets } returns userWalletsFlow
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
every { walletAccountListFlowFactory.create(userWalletId) } returns emptyFlow()
@ -192,7 +192,7 @@ class DefaultMultiAccountListProducerTest {
Truth.assertThat(actual).isEmpty() // no emissions
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsStore.userWallets
userWalletsListRepository.loadAndGet()
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -206,7 +206,7 @@ class DefaultMultiAccountListProducerTest {
}
val userWalletsFlow = MutableStateFlow(listOf(userWallet, userWallet2))
every { userWalletsStore.userWallets } returns userWalletsFlow
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
val accountList = AccountList.empty(userWalletId)
every { walletAccountListFlowFactory.create(userWalletId) } returns flowOf(accountList)
@ -219,7 +219,7 @@ class DefaultMultiAccountListProducerTest {
Truth.assertThat(actual).isEmpty() // no emissions
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsStore.userWallets
userWalletsListRepository.loadAndGet()
walletAccountListFlowFactory.create(userWalletId)
walletAccountListFlowFactory.create(userWalletId2)
}

View file

@ -8,8 +8,8 @@ import com.tangem.common.test.domain.wallet.MockUserWalletFactory
import com.tangem.data.common.currency.ResponseCryptoCurrenciesFactory
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
import com.tangem.datasource.local.token.UserTokensResponseStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.card.configs.GenericCardConfig
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency
@ -35,23 +35,23 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
private val cryptoCurrencyFactory = MockCryptoCurrencyFactory()
private val params = MultiWalletCryptoCurrenciesProducer.Params(userWalletId = userWallet.walletId)
private val userWalletsStore: UserWalletsStore = mockk(relaxUnitFun = true)
private val userWalletsListRepository: UserWalletsListRepository = mockk(relaxUnitFun = true)
private val userTokensResponseStore: UserTokensResponseStore = mockk(relaxUnitFun = true)
private val responseCryptoCurrenciesFactory: ResponseCryptoCurrenciesFactory = mockk()
private val flowProducerTools: FlowProducerTools = mockk()
private val producer = DefaultMultiWalletCryptoCurrenciesProducer(
params = params,
userWalletsStore = userWalletsStore,
flowProducerTools = flowProducerTools,
userWalletsListRepository = userWalletsListRepository,
userTokensResponseStore = userTokensResponseStore,
responseCryptoCurrenciesFactory = responseCryptoCurrenciesFactory,
flowProducerTools = flowProducerTools,
dispatchers = TestingCoroutineDispatcherProvider(),
)
@BeforeEach
fun resetMocks() {
clearMocks(userWalletsStore, userTokensResponseStore, responseCryptoCurrenciesFactory)
clearMocks(userWalletsListRepository, userTokensResponseStore, responseCryptoCurrenciesFactory)
}
@Test
@ -59,7 +59,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
// Arrange
val userTokensResponseFlow = flowOf<UserTokensResponse?>(null)
every { userWalletsStore.getSyncStrict(params.userWalletId) } returns userWallet
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
every { userTokensResponseStore.get(params.userWalletId) } returns userTokensResponseFlow
// Act
@ -72,7 +72,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual.first()).isEqualTo(expected)
verifyOrder {
userWalletsStore.getSyncStrict(params.userWalletId)
userWalletsListRepository.getSyncStrict(params.userWalletId)
userTokensResponseStore.get(params.userWalletId)
}
@ -113,7 +113,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
cryptoCurrencyFactory.createCoin(Blockchain.Bitcoin),
)
every { userWalletsStore.getSyncStrict(params.userWalletId) } returns userWallet
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
every { userTokensResponseStore.get(params.userWalletId) } returns userTokensResponseFlow
every {
@ -146,7 +146,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual1.first()).isEqualTo(expected1)
verifyOrder {
userWalletsStore.getSyncStrict(params.userWalletId)
userWalletsListRepository.getSyncStrict(params.userWalletId)
userTokensResponseStore.get(params.userWalletId)
responseCryptoCurrenciesFactory.createCurrencies(
response = userTokensResponse,
@ -188,7 +188,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
val cryptoCurrencies = emptySet<CryptoCurrency>()
every { userWalletsStore.getSyncStrict(params.userWalletId) } returns userWallet
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
every { userTokensResponseStore.get(params.userWalletId) } returns userTokensResponseFlow
every {
@ -213,7 +213,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual1.first()).isEqualTo(expected1)
verifyOrder {
userWalletsStore.getSyncStrict(params.userWalletId)
userWalletsListRepository.getSyncStrict(params.userWalletId)
userTokensResponseStore.get(params.userWalletId)
responseCryptoCurrenciesFactory.createCurrencies(
response = userTokensResponse,
@ -257,7 +257,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
}
.buffer(capacity = 5)
every { userWalletsStore.getSyncStrict(params.userWalletId) } returns userWallet
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
every { userTokensResponseStore.get(params.userWalletId) } returns userTokensResponseFlow
every {
@ -279,7 +279,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual1.first()).isEqualTo(expected1)
verifyOrder {
userWalletsStore.getSyncStrict(params.userWalletId)
userWalletsListRepository.getSyncStrict(params.userWalletId)
userTokensResponseStore.get(params.userWalletId)
}
@ -304,7 +304,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
@Test
fun `flow is empty if store returns empty flow`() = runTest {
// Arrange
every { userWalletsStore.getSyncStrict(params.userWalletId) } returns userWallet
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
every { userTokensResponseStore.get(params.userWalletId) } returns emptyFlow()
// Act
@ -316,7 +316,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual.first()).isEqualTo(expected)
verifyOrder {
userWalletsStore.getSyncStrict(params.userWalletId)
userWalletsListRepository.getSyncStrict(params.userWalletId)
userTokensResponseStore.get(params.userWalletId)
}
@ -332,7 +332,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
every { isMultiCurrency } returns false
}
every { userWalletsStore.getSyncStrict(params.userWalletId) } returns mockUserWallet
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
// Act
val actual = runCatching { producer.produce() }.exceptionOrNull()
@ -345,7 +345,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual).isInstanceOf(expected::class.java)
Truth.assertThat(actual).hasMessageThat().isEqualTo(expected.message)
verifyOrder { userWalletsStore.getSyncStrict(params.userWalletId) }
verifyOrder { userWalletsListRepository.getSyncStrict(params.userWalletId) }
verify(inverse = true) {
userTokensResponseStore.get(any())

View file

@ -9,8 +9,8 @@ import com.tangem.data.account.store.AccountsResponseStore
import com.tangem.data.account.store.AccountsResponseStoreFactory
import com.tangem.data.common.currency.CardCryptoCurrencyFactory
import com.tangem.datasource.api.tangemTech.models.account.GetWalletAccountsResponse
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.models.wallet.isMultiCurrency
@ -29,7 +29,7 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class WalletAccountListFlowFactoryTest {
private val userWalletsStore: UserWalletsStore = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk()
private val accountsResponseStoreFactory: AccountsResponseStoreFactory = mockk()
private val accountsResponseStore: AccountsResponseStore = mockk()
private val accountsResponseStoreFlow = MutableStateFlow<GetWalletAccountsResponse?>(value = null)
@ -40,7 +40,7 @@ class WalletAccountListFlowFactoryTest {
private val cardCryptoCurrencyFactory: CardCryptoCurrencyFactory = mockk()
private val factory = WalletAccountListFlowFactory(
userWalletsStore = userWalletsStore,
userWalletsListRepository = userWalletsListRepository,
accountsResponseStoreFactory = accountsResponseStoreFactory,
accountListConverterFactory = accountListConverterFactory,
cardCryptoCurrencyFactory = cardCryptoCurrencyFactory,
@ -52,7 +52,7 @@ class WalletAccountListFlowFactoryTest {
@AfterEach
fun tearDownEach() {
clearMocks(
userWalletsStore,
userWalletsListRepository,
accountsResponseStoreFactory,
accountsResponseStore,
accountListConverterFactory,
@ -70,7 +70,7 @@ class WalletAccountListFlowFactoryTest {
every { this@mockk.isMultiCurrency } returns true
}
every { userWalletsStore.getSyncStrict(userWalletId) } returns userWallet
every { userWalletsListRepository.getSyncStrict(userWalletId) } returns userWallet
val accountsResponse = createGetWalletAccountsResponse(userWalletId)
every { accountsResponseStoreFactory.create(userWalletId) } returns accountsResponseStore
@ -105,7 +105,7 @@ class WalletAccountListFlowFactoryTest {
fun `create for single wallet`() = runTest {
val userWallet = MockUserWalletFactory.create().copy(isMultiCurrency = false)
every { userWalletsStore.getSyncStrict(userWallet.walletId) } returns userWallet
every { userWalletsListRepository.getSyncStrict(userWallet.walletId) } returns userWallet
val currency = cryptoCurrencyFactory.ethereum
every { cardCryptoCurrencyFactory.createPrimaryCurrencyForSingleCurrencyCard(userWallet) } returns currency
@ -134,7 +134,7 @@ class WalletAccountListFlowFactoryTest {
fun `flow is created for single wallet with token`() = runTest {
val nodl = MockUserWalletFactory.createSingleWalletWithToken()
every { userWalletsStore.getSyncStrict(nodl.walletId) } returns nodl
every { userWalletsListRepository.getSyncStrict(nodl.walletId) } returns nodl
val currencies = cryptoCurrencyFactory.ethereumAndStellar.toSet()
every {

View file

@ -17,7 +17,6 @@ import com.tangem.datasource.api.tangemTech.models.account.GetWalletAccountsResp
import com.tangem.datasource.api.tangemTech.models.account.GetWalletArchivedAccountsResponse
import com.tangem.datasource.api.tangemTech.models.account.WalletAccountDTO
import com.tangem.datasource.local.datastore.RuntimeStateStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.account.models.ArchivedAccount
import com.tangem.domain.models.account.Account.CryptoPortfolio
@ -52,7 +51,6 @@ class DefaultAccountsCRUDRepositoryTest {
private val archivedAccountsInnerStore = RuntimeStateStore<List<ArchivedAccount>?>(defaultValue = null)
private val archivedAccountsStore = ArchivedAccountsStore(runtimeStore = archivedAccountsInnerStore)
private val userWalletsStore: UserWalletsStore = mockk()
private val userTokensSaver: UserTokensSaver = mockk()
private val archivedAccountsETagStore: RuntimeStateStore<Map<String, String?>> = mockk(relaxUnitFun = true)
@ -67,7 +65,6 @@ class DefaultAccountsCRUDRepositoryTest {
walletAccountsSaver = walletAccountsSaver,
accountsResponseStoreFactory = accountsResponseStoreFactory,
archivedAccountsStoreFactory = archivedAccountsStoreFactory,
userWalletsStore = userWalletsStore,
userTokensSaver = userTokensSaver,
archivedAccountsETagStore = archivedAccountsETagStore,
convertersContainer = convertersContainer,

View file

@ -8,8 +8,8 @@ import com.tangem.data.common.currency.UserTokensResponseFactory
import com.tangem.data.common.network.NetworkFactory
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
import com.tangem.datasource.api.tangemTech.models.account.GetWalletAccountsResponse
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
@ -23,14 +23,14 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class DefaultWalletAccountsResponseFactoryTest {
private val userWalletsStore = mockk<UserWalletsStore>()
private val userWalletsListRepository = mockk<UserWalletsListRepository>()
private val cryptoPortfolioCF = mockk<CryptoPortfolioConverter.Factory>()
private val cryptoPortfolioConverter = mockk<CryptoPortfolioConverter>()
private val userTokensResponseFactory = mockk<UserTokensResponseFactory>()
private val networkFactory = mockk<NetworkFactory>()
private val factory = DefaultWalletAccountsResponseFactory(
userWalletsStore = userWalletsStore,
userWalletsListRepository = userWalletsListRepository,
cryptoPortfolioCF = cryptoPortfolioCF,
userTokensResponseFactory = userTokensResponseFactory,
networkFactory = networkFactory,
@ -46,7 +46,7 @@ class DefaultWalletAccountsResponseFactoryTest {
@AfterEach
fun tearDownEach() {
clearMocks(
userWalletsStore,
userWalletsListRepository,
cryptoPortfolioCF,
cryptoPortfolioConverter,
userTokensResponseFactory,
@ -63,7 +63,7 @@ class DefaultWalletAccountsResponseFactoryTest {
tokens = emptyList(),
)
coEvery { userWalletsStore.getSyncOrNull(userWalletId) } returns null
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns null
every {
userTokensResponseFactory.createDefaultResponse(
userWallet = null,
@ -89,7 +89,7 @@ class DefaultWalletAccountsResponseFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsStore.getSyncOrNull(userWalletId)
userWalletsListRepository.getSyncOrNull(userWalletId)
userTokensResponseFactory.createDefaultResponse(
userWallet = null,
networkFactory = networkFactory,
@ -105,7 +105,7 @@ class DefaultWalletAccountsResponseFactoryTest {
every { walletId } returns userWalletId
}
coEvery { userWalletsStore.getSyncOrNull(userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val accounts = AccountList.empty(userWallet.walletId).accounts
.filterIsInstance<Account.CryptoPortfolio>()
@ -145,7 +145,7 @@ class DefaultWalletAccountsResponseFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsStore.getSyncOrNull(userWalletId)
userWalletsListRepository.getSyncOrNull(userWalletId)
cryptoPortfolioConverter.convertListBack(accounts)
userTokensResponseFactory.createDefaultResponse(
userWallet = userWallet,
@ -165,7 +165,7 @@ class DefaultWalletAccountsResponseFactoryTest {
val accounts = AccountList.empty(userWallet.walletId).accounts
.filterIsInstance<Account.CryptoPortfolio>()
coEvery { userWalletsStore.getSyncOrNull(userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val defaultResponse = UserTokensResponse(
group = UserTokensResponse.GroupType.NETWORK,
@ -206,7 +206,7 @@ class DefaultWalletAccountsResponseFactoryTest {
val userWallet = mockk<UserWallet>(relaxed = true) {
every { walletId } returns userWalletId
}
coEvery { userWalletsStore.getSyncOrNull(userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userTokensResponse = UserTokensResponse(
group = UserTokensResponse.GroupType.NETWORK,

View file

@ -10,6 +10,7 @@ tasks.withType<Test>().configureEach {
dependencies {
api(projects.domain.common)
api(projects.domain.core)
api(projects.domain.models)
api(projects.domain.wallets.models)

View file

@ -6,7 +6,6 @@ import com.tangem.domain.account.models.ArchivedAccount
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.account.AccountName
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import kotlinx.coroutines.flow.Flow
@ -108,20 +107,6 @@ interface AccountsCRUDRepository {
*/
fun getTotalActiveAccountsCount(userWalletId: UserWalletId): Flow<Option<Int>>
/**
* Retrieves a user wallet by its unique identifier
*
* @param userWalletId the unique identifier of the user wallet
* @return the [UserWallet] associated with the given identifier
*/
fun getUserWallet(userWalletId: UserWalletId): UserWallet
/** Provides a flow of all user wallets */
fun getUserWallets(): Flow<List<UserWallet>>
/** Synchronously retrieves all user wallets */
fun getUserWalletsSync(): List<UserWallet>
/** Checks if the provided account name is the default name within the given account list
*
* @param accountList the list of accounts to check against

View file

@ -4,6 +4,7 @@ import arrow.core.Option
import arrow.core.getOrElse
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.isMultiCurrency
import kotlinx.coroutines.ExperimentalCoroutinesApi
@ -14,12 +15,15 @@ import kotlinx.coroutines.flow.*
* Accounts mode is considered enabled if there are at least two accounts in any of the user wallets that support
* multiple currencies.
*
* @property crudRepository repository to interact with user wallets and their accounts
* @property crudRepository repository to perform CRUD operations on accounts.
* @property userWalletsListRepository repository to get the list of user wallets.
* @property accountsFeatureToggles feature toggles for accounts.
*
[REDACTED_AUTHOR]
*/
class IsAccountsModeEnabledUseCase(
private val crudRepository: AccountsCRUDRepository,
private val userWalletsListRepository: UserWalletsListRepository,
private val accountsFeatureToggles: AccountsFeatureToggles,
) {
@ -27,7 +31,7 @@ class IsAccountsModeEnabledUseCase(
operator fun invoke(): Flow<Boolean> {
if (!accountsFeatureToggles.isFeatureEnabled) return flowOf(value = false)
return crudRepository.getUserWallets()
return userWalletsListRepository.loadAndGet()
.flatMapLatest { userWallets ->
val totalAccountsCountList = getTotalAccountsCountList(userWallets)
@ -40,7 +44,7 @@ class IsAccountsModeEnabledUseCase(
suspend fun invokeSync(): Boolean {
if (!accountsFeatureToggles.isFeatureEnabled) return false
return crudRepository.getUserWalletsSync()
return userWalletsListRepository.userWallets.value.orEmpty()
.map { userWallet ->
// If the wallet does not support multiple currencies, we consider its account count as 0
if (!userWallet.isMultiCurrency) return@map 0
@ -50,7 +54,6 @@ class IsAccountsModeEnabledUseCase(
.isModeEnabled()
}
@Suppress("UnusedFlow")
private fun getTotalAccountsCountList(userWallets: List<UserWallet>): List<Flow<Int>> {
return userWallets
.map { userWallet ->

View file

@ -5,6 +5,7 @@ import arrow.core.some
import com.google.common.truth.Truth
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.models.wallet.isMultiCurrency
@ -24,13 +25,18 @@ import org.junit.jupiter.api.TestInstance
class IsAccountsModeEnabledUseCaseTest {
private val accountsCRUDRepository: AccountsCRUDRepository = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk()
private val featureToggles: AccountsFeatureToggles = mockk()
private val useCase = IsAccountsModeEnabledUseCase(accountsCRUDRepository, featureToggles)
private val useCase = IsAccountsModeEnabledUseCase(
crudRepository = accountsCRUDRepository,
userWalletsListRepository = userWalletsListRepository,
accountsFeatureToggles = featureToggles,
)
@AfterEach
fun tearDown() {
clearMocks(accountsCRUDRepository, featureToggles)
clearMocks(userWalletsListRepository, accountsCRUDRepository, featureToggles)
}
@Nested
@ -49,14 +55,14 @@ class IsAccountsModeEnabledUseCaseTest {
Truth.assertThat(actual).isFalse()
verify(exactly = 1) { featureToggles.isFeatureEnabled }
verify(inverse = true) { accountsCRUDRepository.getUserWallets() }
verify(inverse = true) { userWalletsListRepository.loadAndGet() }
}
@Test
fun `returns false when getUserWallets emits empty flow`() = runTest {
fun `returns false when loadAndGet emits empty flow`() = runTest {
// Arrange
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWallets() } returns emptyFlow()
every { userWalletsListRepository.loadAndGet() } returns emptyFlow()
// Act
val actual = useCase.invoke().firstOrNull()
@ -66,19 +72,19 @@ class IsAccountsModeEnabledUseCaseTest {
verifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWallets()
userWalletsListRepository.loadAndGet()
}
verify(inverse = true) { accountsCRUDRepository.getTotalActiveAccountsCount(any()) }
}
@Test
fun `returns false when getUserWallets emits one wallet with isMultiCurrency false`() = runTest {
fun `returns false when loadAndGet emits one wallet with isMultiCurrency false`() = runTest {
// Arrange
val wallet = createUserWallet(isMultiCurrency = false)
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWallets() } returns flowOf(listOf(wallet))
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet))
// Act
val actual = useCase.invoke().first()
@ -88,19 +94,19 @@ class IsAccountsModeEnabledUseCaseTest {
verifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWallets()
userWalletsListRepository.loadAndGet()
}
verify(inverse = true) { accountsCRUDRepository.getTotalActiveAccountsCount(any()) }
}
@Test
fun `returns true when getUserWallets emits one wallet with isMultiCurrency true`() = runTest {
fun `returns true when loadAndGet emits one wallet with isMultiCurrency true`() = runTest {
// Arrange
val wallet = createUserWallet(isMultiCurrency = true)
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWallets() } returns flowOf(listOf(wallet))
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet))
every { accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId) } returns flowOf(2.some())
// Act
@ -111,18 +117,18 @@ class IsAccountsModeEnabledUseCaseTest {
verifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWallets()
userWalletsListRepository.loadAndGet()
accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId)
}
}
@Test
fun `returns false when getUserWallets emits one wallet with isMultiCurrency true and None counts`() = runTest {
fun `returns false when loadAndGet emits one wallet with isMultiCurrency true and None counts`() = runTest {
// Arrange
val wallet = createUserWallet(isMultiCurrency = true)
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWallets() } returns flowOf(listOf(wallet))
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet))
every { accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId) } returns flowOf(none())
// Act
@ -133,19 +139,19 @@ class IsAccountsModeEnabledUseCaseTest {
verifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWallets()
userWalletsListRepository.loadAndGet()
accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId)
}
}
@Test
fun `returns true when getUserWallets emits two wallets, one isMultiCurrency false, one true`() = runTest {
fun `returns true when loadAndGet emits two wallets, one isMultiCurrency false, one true`() = runTest {
// Arrange
val wallet1 = createUserWallet(isMultiCurrency = false)
val wallet2 = createUserWallet(isMultiCurrency = true)
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWallets() } returns flowOf(listOf(wallet1, wallet2))
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet1, wallet2))
every { accountsCRUDRepository.getTotalActiveAccountsCount(wallet2.walletId) } returns flowOf(2.some())
// Act
@ -156,7 +162,7 @@ class IsAccountsModeEnabledUseCaseTest {
verifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWallets()
userWalletsListRepository.loadAndGet()
accountsCRUDRepository.getTotalActiveAccountsCount(wallet2.walletId)
}
@ -180,14 +186,14 @@ class IsAccountsModeEnabledUseCaseTest {
Truth.assertThat(actual).isFalse()
verify(exactly = 1) { featureToggles.isFeatureEnabled }
verify(inverse = true) { accountsCRUDRepository.getUserWalletsSync() }
verify(inverse = true) { userWalletsListRepository.userWallets.value }
}
@Test
fun `returns false when getUserWalletsSync returns empty list`() = runTest {
// Arrange
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWalletsSync() } returns emptyList()
every { userWalletsListRepository.userWallets.value } returns emptyList()
// Act
val actual = useCase.invokeSync()
@ -197,7 +203,7 @@ class IsAccountsModeEnabledUseCaseTest {
verifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
}
coVerify(inverse = true) { accountsCRUDRepository.getTotalActiveAccountsCountSync(any()) }
@ -209,7 +215,7 @@ class IsAccountsModeEnabledUseCaseTest {
val wallet = createUserWallet(isMultiCurrency = false)
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(wallet)
every { userWalletsListRepository.userWallets.value } returns listOf(wallet)
// Act
val actual = useCase.invokeSync()
@ -219,7 +225,7 @@ class IsAccountsModeEnabledUseCaseTest {
verifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
}
coVerify(inverse = true) { accountsCRUDRepository.getTotalActiveAccountsCountSync(any()) }
@ -231,7 +237,7 @@ class IsAccountsModeEnabledUseCaseTest {
val wallet = createUserWallet(isMultiCurrency = true)
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(wallet)
every { userWalletsListRepository.userWallets.value } returns listOf(wallet)
coEvery { accountsCRUDRepository.getTotalActiveAccountsCountSync(wallet.walletId) } returns 2.some()
// Act
@ -242,7 +248,7 @@ class IsAccountsModeEnabledUseCaseTest {
coVerifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
accountsCRUDRepository.getTotalActiveAccountsCountSync(wallet.walletId)
}
}
@ -253,7 +259,7 @@ class IsAccountsModeEnabledUseCaseTest {
val wallet = createUserWallet(isMultiCurrency = true)
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(wallet)
every { userWalletsListRepository.userWallets.value } returns listOf(wallet)
coEvery { accountsCRUDRepository.getTotalActiveAccountsCountSync(wallet.walletId) } returns none()
// Act
@ -264,7 +270,7 @@ class IsAccountsModeEnabledUseCaseTest {
coVerifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
accountsCRUDRepository.getTotalActiveAccountsCountSync(wallet.walletId)
}
}
@ -276,7 +282,7 @@ class IsAccountsModeEnabledUseCaseTest {
val wallet2 = createUserWallet(isMultiCurrency = true)
every { featureToggles.isFeatureEnabled } returns true
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(wallet1, wallet2)
every { userWalletsListRepository.userWallets.value } returns listOf(wallet1, wallet2)
coEvery { accountsCRUDRepository.getTotalActiveAccountsCountSync(wallet2.walletId) } returns 2.some()
// Act
@ -287,7 +293,7 @@ class IsAccountsModeEnabledUseCaseTest {
coVerifyOrder {
featureToggles.isFeatureEnabled
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
accountsCRUDRepository.getTotalActiveAccountsCountSync(wallet2.walletId)
}

View file

@ -7,6 +7,7 @@ import com.tangem.domain.account.status.usecase.*
import com.tangem.domain.account.status.utils.CryptoCurrencyBalanceFetcher
import com.tangem.domain.account.status.utils.CryptoCurrencyMetadataCleaner
import com.tangem.domain.account.supplier.SingleAccountListSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.express.ExpressServiceFetcher
import com.tangem.domain.networks.multi.MultiNetworkStatusFetcher
import com.tangem.domain.networks.multi.MultiNetworkStatusSupplier
@ -36,12 +37,12 @@ internal object AccountStatusUseCaseModule {
@Provides
@Singleton
fun provideGetAccountCurrencyByAddressUseCase(
accountsCRUDRepository: AccountsCRUDRepository,
userWalletsListRepository: UserWalletsListRepository,
multiNetworkStatusSupplier: MultiNetworkStatusSupplier,
singleAccountListSupplier: SingleAccountListSupplier,
): GetAccountCurrencyByAddressUseCase {
return GetAccountCurrencyByAddressUseCase(
accountsCRUDRepository = accountsCRUDRepository,
userWalletsListRepository = userWalletsListRepository,
multiNetworkStatusSupplier = multiNetworkStatusSupplier,
singleAccountListSupplier = singleAccountListSupplier,
)
@ -50,12 +51,12 @@ internal object AccountStatusUseCaseModule {
@Provides
@Singleton
fun provideGetCryptoCurrencyActionsUseCaseV2(
accountsCRUDRepository: AccountsCRUDRepository,
userWalletsListRepository: UserWalletsListRepository,
singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
getCryptoCurrencyActionsUseCase: GetCryptoCurrencyActionsUseCase,
): GetCryptoCurrencyActionsUseCaseV2 {
return GetCryptoCurrencyActionsUseCaseV2(
accountsCRUDRepository = accountsCRUDRepository,
userWalletsListRepository = userWalletsListRepository,
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
getCryptoCurrencyActionsUseCase = getCryptoCurrencyActionsUseCase,
)

View file

@ -3,8 +3,8 @@ package com.tangem.domain.account.status.producer
import arrow.core.Option
import arrow.core.some
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.assisted.Assisted
@ -20,7 +20,8 @@ import kotlinx.coroutines.flow.flowOn
* Produces a flow of [AccountStatusList] for multiple user wallets.
*
* @property params Parameters for the producer (currently unused).
* @property accountsCRUDRepository Repository to get the list of user wallets.
* @property flowProducerTools Tools for managing the flow producer.
* @property userWalletsListRepository Repository to get the list of user wallets.
* @property singleAccountStatusListSupplier Supplier to get the account status list for a single user wallet.
* @property dispatchers Coroutine dispatcher provider for managing threading.
*
@ -29,7 +30,7 @@ import kotlinx.coroutines.flow.flowOn
internal class DefaultMultiAccountStatusListProducer @AssistedInject constructor(
@Assisted val params: Unit,
override val flowProducerTools: FlowProducerTools,
private val accountsCRUDRepository: AccountsCRUDRepository,
private val userWalletsListRepository: UserWalletsListRepository,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val dispatchers: CoroutineDispatcherProvider,
) : MultiAccountStatusListProducer {
@ -38,7 +39,7 @@ internal class DefaultMultiAccountStatusListProducer @AssistedInject constructor
@OptIn(ExperimentalCoroutinesApi::class)
override fun produce(): Flow<List<AccountStatusList>> {
return accountsCRUDRepository.getUserWallets()
return userWalletsListRepository.loadAndGet()
.flatMapLatest { userWallets ->
val flows = userWallets.map {
singleAccountStatusListSupplier(

View file

@ -7,8 +7,8 @@ import com.tangem.core.analytics.api.AnalyticsExceptionHandler
import com.tangem.domain.account.models.AccountCurrencyId
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.account.supplier.SingleAccountListSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.core.utils.lceContent
import com.tangem.domain.core.utils.lceLoading
@ -55,10 +55,16 @@ import java.math.BigDecimal
* Produces a flow of [AccountStatusList] for a single user wallet.
*
* @property params Parameters containing the user wallet ID.
* @property accountsCRUDRepository Repository for accessing account data.
* @property flowProducerTools Tools for managing the flow producer.
* @property userWalletsListRepository Repository for getting user wallet by id.
* @property singleAccountListSupplier Supplier to get the list of accounts for the user wallet.
* @property cryptoCurrencyStatusesFlowFactory Factory to create flows of cryptocurrency statuses.
* @property networksRepository Repository for checking network statuses in a cache.
* @property dispatchers Coroutine dispatcher provider for managing threading.
* @property networkStatusSupplier Supplier for getting network statuses.
* @property quoteStatusSupplier Supplier for getting quote statuses.
* @property stakingBalanceSupplier Supplier for getting staking balances.
* @property stakingIdFactory Factory for creating staking IDs.
* @property analyticsExceptionHandler Handler for analytics exceptions.
*
[REDACTED_AUTHOR]
*/
@ -66,11 +72,11 @@ import java.math.BigDecimal
@OptIn(ExperimentalCoroutinesApi::class)
internal class DefaultSingleAccountStatusListProducer @AssistedInject constructor(
@Assisted private val params: SingleAccountStatusListProducer.Params,
private val accountsCRUDRepository: AccountsCRUDRepository,
override val flowProducerTools: FlowProducerTools,
private val userWalletsListRepository: UserWalletsListRepository,
private val singleAccountListSupplier: SingleAccountListSupplier,
private val networksRepository: NetworksRepository,
private val dispatchers: CoroutineDispatcherProvider,
override val flowProducerTools: FlowProducerTools,
private val networkStatusSupplier: MultiNetworkStatusSupplier,
private val quoteStatusSupplier: MultiQuoteStatusSupplier,
private val stakingBalanceSupplier: MultiStakingBalanceSupplier,
@ -88,7 +94,7 @@ internal class DefaultSingleAccountStatusListProducer @AssistedInject constructo
@Suppress("LongMethod")
private fun flattenFlow(): Flow<AccountStatusList> = channelFlow {
val walletId = params.userWalletId
val userWallet = accountsCRUDRepository.getUserWallet(userWalletId = params.userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(id = params.userWalletId)
val flattenCurrency: MutableSharedFlow<Map<AccountCurrencyId, CryptoCurrency>> = MutableSharedFlow(
replay = 1,

View file

@ -9,9 +9,9 @@ import arrow.core.raise.option
import arrow.core.toNonEmptyListOrNull
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.account.producer.SingleAccountListProducer
import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.account.status.model.AccountCryptoCurrency
import com.tangem.domain.account.supplier.SingleAccountListSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.network.getAddress
@ -29,14 +29,14 @@ private typealias WalletIdWithNetworkId = Pair<UserWalletId, Network.ID>
/**
* Use case to retrieve an [AccountCryptoCurrency] based on a provided address.
*
* @property accountsCRUDRepository Repository to access user wallets.
* @property userWalletsListRepository Repository to access user wallets.
* @property multiNetworkStatusSupplier Supplier to get network status for multiple networks.
* @property singleAccountListSupplier Supplier to get account lists for a single wallet.
*
[REDACTED_AUTHOR]
*/
class GetAccountCurrencyByAddressUseCase(
private val accountsCRUDRepository: AccountsCRUDRepository,
private val userWalletsListRepository: UserWalletsListRepository,
private val multiNetworkStatusSupplier: MultiNetworkStatusSupplier,
private val singleAccountListSupplier: SingleAccountListSupplier,
) {
@ -65,7 +65,7 @@ class GetAccountCurrencyByAddressUseCase(
}
private fun OptionRaise.getUserWalletIds(): NonEmptyList<UserWalletId> {
val userWalletIds = accountsCRUDRepository.getUserWalletsSync()
val userWalletIds = userWalletsListRepository.userWallets.value.orEmpty()
.filter(UserWallet::isMultiCurrency)
.map(UserWallet::walletId)
.toNonEmptyListOrNull()

View file

@ -1,9 +1,9 @@
package com.tangem.domain.account.status.usecase
import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.account.status.producer.SingleAccountStatusListProducer
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.status.utils.AccountCryptoCurrencyStatusFinder
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.tokens.GetCryptoCurrencyActionsUseCase
@ -17,14 +17,14 @@ import kotlinx.coroutines.flow.transformLatest
/**
* Use case to retrieve the available actions for a specific cryptocurrency associated with an account.
*
* @property accountsCRUDRepository repository for account CRUD operations.
* @property userWalletsListRepository repository to get the user wallets list.
* @property singleAccountStatusListSupplier supplier to get the list of account statuses.
* @property getCryptoCurrencyActionsUseCase use case to get the actions for a specific cryptocurrency status.
*
[REDACTED_AUTHOR]
*/
class GetCryptoCurrencyActionsUseCaseV2(
private val accountsCRUDRepository: AccountsCRUDRepository,
private val userWalletsListRepository: UserWalletsListRepository,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val getCryptoCurrencyActionsUseCase: GetCryptoCurrencyActionsUseCase,
) {
@ -45,7 +45,7 @@ class GetCryptoCurrencyActionsUseCaseV2(
)
if (accountCurrencyStatus != null) {
val userWallet = accountsCRUDRepository.getUserWallet(userWalletId = accountId.userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(id = accountId.userWalletId)
val actionsFlow = getCryptoCurrencyActionsUseCase(
userWallet = userWallet,
cryptoCurrencyStatus = accountCurrencyStatus.status,

View file

@ -2,8 +2,8 @@ package com.tangem.domain.account.status.producer
import com.google.common.truth.Truth
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
@ -21,7 +21,7 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class DefaultMultiAccountStatusListProducerTest {
private val accountsCRUDRepository: AccountsCRUDRepository = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk()
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier = mockk()
private val dispatchers = TestingCoroutineDispatcherProvider()
private val flowProducerTools: FlowProducerTools = mockk()
@ -38,7 +38,7 @@ class DefaultMultiAccountStatusListProducerTest {
private val producer = DefaultMultiAccountStatusListProducer(
params = Unit,
accountsCRUDRepository = accountsCRUDRepository,
userWalletsListRepository = userWalletsListRepository,
singleAccountStatusListSupplier = singleAccountStatusListSupplier,
dispatchers = dispatchers,
flowProducerTools = flowProducerTools,
@ -46,7 +46,7 @@ class DefaultMultiAccountStatusListProducerTest {
@AfterEach
fun tearDown() {
clearMocks(accountsCRUDRepository, singleAccountStatusListSupplier)
clearMocks(userWalletsListRepository, singleAccountStatusListSupplier)
}
@Test
@ -55,7 +55,7 @@ class DefaultMultiAccountStatusListProducerTest {
val wallets = listOf(userWallet1, userWallet2)
val walletsFlow = MutableStateFlow(wallets)
every { accountsCRUDRepository.getUserWallets() } returns walletsFlow
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
val accountStatusList1 = mockk<AccountStatusList>()
val accountStatusList2 = mockk<AccountStatusList>()
@ -79,7 +79,7 @@ class DefaultMultiAccountStatusListProducerTest {
Truth.assertThat(actual).containsExactly(expected)
coVerify(ordering = Ordering.SEQUENCE) {
accountsCRUDRepository.getUserWallets()
userWalletsListRepository.loadAndGet()
singleAccountStatusListSupplier(
params = SingleAccountStatusListProducer.Params(userWalletId1),
)
@ -93,7 +93,7 @@ class DefaultMultiAccountStatusListProducerTest {
fun `produce returns empty flow if userWallets is empty list`() = runTest {
// Arrange
val walletsFlow = MutableStateFlow<List<UserWallet>>(emptyList())
every { accountsCRUDRepository.getUserWallets() } returns walletsFlow
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
// Act
val actual = producer.produce().let(::getEmittedValues)
@ -102,27 +102,26 @@ class DefaultMultiAccountStatusListProducerTest {
Truth.assertThat(actual).isEmpty()
coVerify(ordering = Ordering.SEQUENCE) {
accountsCRUDRepository.getUserWallets()
userWalletsListRepository.loadAndGet()
}
}
// TODO: uncomment after migration on UserWalletsListRepository
// @Test
// fun `produce returns empty flow if userWallets is null`() = runTest {
// // Arrange
// val walletsFlow = MutableStateFlow<List<UserWallet>?>(null)
// every { accountsCRUDRepository.getUserWallets() } returns walletsFlow
//
// // Act
// val actual = producer.produce().let(::getEmittedValues)
//
// // Assert
// Truth.assertThat(actual).isEmpty()
//
// coVerify(ordering = Ordering.SEQUENCE) {
// accountsCRUDRepository.getUserWallets()
// }
// }
@Test
fun `produce returns empty flow if userWallets is null`() = runTest {
// Arrange
val walletsFlow = flowOf<List<UserWallet>>(emptyList())
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
// Act
val actual = producer.produce().let(::getEmittedValues)
// Assert
Truth.assertThat(actual).isEmpty()
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
}
}
@Test
fun `flow will updated if userWallets are updated`() = runTest {
@ -131,7 +130,7 @@ class DefaultMultiAccountStatusListProducerTest {
val userWallet3 = mockk<UserWallet> { every { walletId } returns userWalletId3 }
val walletsFlow = MutableStateFlow(listOf(userWallet1, userWallet2))
every { accountsCRUDRepository.getUserWallets() } returns walletsFlow
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
val accountStatusList1 = mockk<AccountStatusList>()
val accountStatusList2 = mockk<AccountStatusList>()
@ -171,7 +170,7 @@ class DefaultMultiAccountStatusListProducerTest {
Truth.assertThat(actual2).containsExactly(expected2)
coVerify(ordering = Ordering.SEQUENCE) {
accountsCRUDRepository.getUserWallets()
userWalletsListRepository.loadAndGet()
singleAccountStatusListSupplier(
params = SingleAccountStatusListProducer.Params(userWalletId1),
)
@ -187,7 +186,7 @@ class DefaultMultiAccountStatusListProducerTest {
singleAccountStatusListSupplier(
params = SingleAccountStatusListProducer.Params(userWalletId3),
)
accountsCRUDRepository.getUserWallets()
userWalletsListRepository.loadAndGet()
singleAccountStatusListSupplier(
params = SingleAccountStatusListProducer.Params(userWalletId1),
)

View file

@ -3,9 +3,9 @@ package com.tangem.domain.account.status.usecase
import com.tangem.common.test.domain.token.MockCryptoCurrencyFactory
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.account.producer.SingleAccountListProducer
import com.tangem.domain.account.repository.AccountsCRUDRepository
import com.tangem.domain.account.status.model.AccountCryptoCurrency
import com.tangem.domain.account.supplier.SingleAccountListSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.network.NetworkAddress
import com.tangem.domain.models.network.NetworkStatus
@ -28,19 +28,19 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class GetAccountCurrencyByAddressUseCaseTest {
private val accountsCRUDRepository: AccountsCRUDRepository = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk()
private val multiNetworkStatusSupplier: MultiNetworkStatusSupplier = mockk()
private val singleAccountListSupplier: SingleAccountListSupplier = mockk()
private val useCase = GetAccountCurrencyByAddressUseCase(
accountsCRUDRepository = accountsCRUDRepository,
userWalletsListRepository = userWalletsListRepository,
multiNetworkStatusSupplier = multiNetworkStatusSupplier,
singleAccountListSupplier = singleAccountListSupplier,
)
@AfterEach
fun tearDown() {
clearMocks(accountsCRUDRepository, multiNetworkStatusSupplier, singleAccountListSupplier)
clearMocks(userWalletsListRepository, multiNetworkStatusSupplier, singleAccountListSupplier)
}
@Test
@ -55,27 +55,10 @@ class GetAccountCurrencyByAddressUseCaseTest {
assertNone(actual)
}
// TODO: uncomment after migration on UserWalletsListRepository
// @Test
// fun `returns None if userWalletIds is null`() = runTest {
// // Arrange
// every { accountsCRUDRepository.getUserWalletsSync() } returns MutableStateFlow(null)
//
// // Act
// val actual = useCase(validAddress)
//
// // Assert
// assertNone(actual)
//
// coVerifySequence {
// accountsCRUDRepository.getUserWalletsSync()
// }
// }
@Test
fun `returns None if userWalletIds is empty list`() = runTest {
fun `returns None if userWalletIds is null`() = runTest {
// Arrange
every { accountsCRUDRepository.getUserWalletsSync() } returns emptyList()
every { userWalletsListRepository.userWallets.value } returns null
// Act
val actual = useCase(validAddress)
@ -84,7 +67,23 @@ class GetAccountCurrencyByAddressUseCaseTest {
assertNone(actual)
coVerifySequence {
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
}
}
@Test
fun `returns None if userWalletIds is empty list`() = runTest {
// Arrange
every { userWalletsListRepository.userWallets.value } returns emptyList()
// Act
val actual = useCase(validAddress)
// Assert
assertNone(actual)
coVerifySequence {
userWalletsListRepository.userWallets.value
}
}
@ -95,7 +94,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
every { isMultiCurrency } returns false
}
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(singleWallet)
every { userWalletsListRepository.userWallets.value } returns listOf(singleWallet)
// Act
val actual = useCase(validAddress)
@ -104,14 +103,14 @@ class GetAccountCurrencyByAddressUseCaseTest {
assertNone(actual)
coVerifySequence {
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
}
}
@Test
fun `returns None if multiNetworkStatusSupplier returns null`() = runTest {
// Arrange
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(multiUserWallet)
every { userWalletsListRepository.userWallets.value } returns listOf(multiUserWallet)
coEvery {
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
} returns null
@ -123,7 +122,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
assertNone(actual)
coVerifySequence {
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
}
}
@ -131,7 +130,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
@Test
fun `returns None if multiNetworkStatusSupplier returns empty list`() = runTest {
// Arrange
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(multiUserWallet)
every { userWalletsListRepository.userWallets.value } returns listOf(multiUserWallet)
coEvery {
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
} returns emptySet()
@ -143,7 +142,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
assertNone(actual)
coVerifySequence {
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
}
}
@ -156,7 +155,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
value = NetworkStatus.Unreachable(address = null),
)
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(multiUserWallet)
every { userWalletsListRepository.userWallets.value } returns listOf(multiUserWallet)
coEvery {
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
} returns setOf(networkStatus)
@ -168,7 +167,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
assertNone(actual)
coVerifySequence {
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
}
}
@ -183,7 +182,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
value = NetworkStatus.Unreachable(address = validNetworkAddress),
)
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(multiUserWallet)
every { userWalletsListRepository.userWallets.value } returns listOf(multiUserWallet)
coEvery {
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
} returns setOf(networkStatus)
@ -200,7 +199,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
assertNone(actual)
coVerifySequence {
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
singleAccountListSupplier.getSyncOrNull(
params = SingleAccountListProducer.Params(userWalletId = userWalletId),
@ -220,7 +219,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
)
val accountList = AccountList.empty(userWalletId)
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(multiUserWallet)
every { userWalletsListRepository.userWallets.value } returns listOf(multiUserWallet)
coEvery {
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
} returns setOf(networkStatus)
@ -237,7 +236,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
assertNone(actual)
coVerifySequence {
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
singleAccountListSupplier.getSyncOrNull(
params = SingleAccountListProducer.Params(userWalletId = userWalletId),
@ -255,7 +254,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
)
val accountList = AccountList.empty(userWalletId = userWalletId, cryptoCurrencies = setOf(currency))
every { accountsCRUDRepository.getUserWalletsSync() } returns listOf(multiUserWallet)
every { userWalletsListRepository.userWallets.value } returns listOf(multiUserWallet)
coEvery {
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
} returns setOf(networkStatus)
@ -273,7 +272,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
assertSome(actual, expected)
coVerifySequence {
accountsCRUDRepository.getUserWalletsSync()
userWalletsListRepository.userWallets.value
multiNetworkStatusSupplier.getSyncOrNull(params = MultiNetworkStatusProducer.Params(userWalletId), 1000)
singleAccountListSupplier.getSyncOrNull(
params = SingleAccountListProducer.Params(userWalletId = userWalletId),

View file

@ -5,6 +5,7 @@ import com.tangem.domain.common.wallets.error.*
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
/**
@ -30,12 +31,21 @@ interface UserWalletsListRepository {
*/
val selectedUserWallet: StateFlow<UserWallet?>
/** Get user wallet by [id] */
fun getSyncOrNull(id: UserWalletId): UserWallet?
/** Get user wallet by [id] */
fun getSyncStrict(id: UserWalletId): UserWallet
/**
* Loads user wallets list and selected wallet.
* If the list is already loaded, it does nothing.
*/
suspend fun load()
/** Loads user wallets list and selected wallet and returns a flow of the list */
fun loadAndGet(): Flow<List<UserWallet>>
/**
* Gets and if necessary loads user wallets list and selected wallet.
*/