Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-12 11:50:44 +04:00
parent 4c8af6b8e9
commit 1472431435
54 changed files with 370 additions and 352 deletions

View file

@ -1,53 +0,0 @@
package com.tangem.tap.data
import com.tangem.common.CompletionResult
import com.tangem.common.catching
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
class UserWalletsStoreRepositoryProxy(
private val userWalletsListRepository: UserWalletsListRepository,
) : UserWalletsStore {
override val selectedUserWalletOrNull: UserWallet?
get() = userWalletsListRepository.selectedUserWallet.value
override val userWallets: Flow<List<UserWallet>>
get() = flow {
userWalletsListRepository.load()
userWalletsListRepository.userWallets.collect {
emit(requireNotNull(it))
}
}
override val userWalletsSync: List<UserWallet>
get() = userWalletsListRepository.userWallets.value.orEmpty()
override fun getSyncOrNull(key: UserWalletId): UserWallet? {
return userWalletsListRepository.userWallets.value?.find { it.walletId == key }
}
override fun getSyncStrict(key: UserWalletId): UserWallet {
return requireNotNull(getSyncOrNull(key)) { "Unable to find user wallet with provided ID: $key" }
}
override suspend fun update(
userWalletId: UserWalletId,
update: suspend (UserWallet) -> UserWallet,
): CompletionResult<UserWallet> {
return catching {
val userWallet = userWalletsListRepository.userWallets.value?.find { it.walletId == userWalletId }
requireNotNull(userWallet) { "Unable to find user wallet with provided ID: $userWalletId" }
val updatedUserWallet = update(userWallet)
userWalletsListRepository.saveWithoutLock(
userWallet = updatedUserWallet,
canOverride = true,
)
updatedUserWallet
}
}
}

View file

@ -1,21 +0,0 @@
package com.tangem.tap.di.data
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.tap.data.UserWalletsStoreRepositoryProxy
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
internal object UserWalletsStoreModule {
@Provides
@Singleton
fun provideUserWalletsStore(userWalletsListRepository: UserWalletsListRepository): UserWalletsStore {
return UserWalletsStoreRepositoryProxy(userWalletsListRepository)
}
}

View file

@ -38,9 +38,7 @@ 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
@ -69,14 +67,6 @@ internal class DefaultUserWalletsListRepository(
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
@ -111,13 +101,6 @@ 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) {

View file

@ -1,39 +0,0 @@
package com.tangem.tap.domain.userWalletList.repository
import com.tangem.common.CompletionResult
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.tap.domain.userWalletList.model.UserWalletEncryptionKey
internal interface UserWalletsKeysRepository {
/**
* Obtaining the encryption keys of all user wallets from the biometric vault. Biometric authentication required
* If that operation runs more than biometric cipher key expiration time then the user will not receive all
* encryption keys
* @return [CompletionResult] of operation with stored [UserWalletEncryptionKey] list
* */
suspend fun getAll(): CompletionResult<List<UserWalletEncryptionKey>>
/**
* Save the encryption key for user wallet. Biometric authentication not required
* @param encryptionKey [UserWalletEncryptionKey] to save
* @return [CompletionResult] of operation
* */
suspend fun save(encryptionKey: UserWalletEncryptionKey): CompletionResult<Unit>
/**
* Delete encryption keys for user wallets. Biometric authentication not required
* @param userWalletsIds List of [UserWalletId] whose encryption keys will be deleted
* */
suspend fun delete(userWalletsIds: List<UserWalletId>)
/**
* Clear all encryption keys for user wallets. Biometric authentication not required
* */
suspend fun clear()
/**
* Determine if the user has saved user wallets
* @return [Boolean] true if user has saved wallets
* */
fun hasSavedEncryptionKeys(): Boolean
}

View file

@ -1,28 +0,0 @@
package com.tangem.datasource.local.userwallet
import com.tangem.common.CompletionResult
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import kotlinx.coroutines.flow.Flow
@Deprecated(
message = "Use UserWalletsListRepository instead",
replaceWith = ReplaceWith("UserWalletsListRepository"),
)
interface UserWalletsStore {
val selectedUserWalletOrNull: UserWallet?
val userWallets: Flow<List<UserWallet>>
val userWalletsSync: List<UserWallet>
fun getSyncOrNull(key: UserWalletId): UserWallet?
fun getSyncStrict(key: UserWalletId): UserWallet
suspend fun update(
userWalletId: UserWalletId,
update: suspend (UserWallet) -> UserWallet,
): CompletionResult<UserWallet>
}

View file

@ -1,6 +1,7 @@
package com.tangem.data.account.converter
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.wallet.UserWalletId
import javax.inject.Inject

View file

@ -5,6 +5,7 @@ import arrow.core.some
import com.tangem.data.account.store.AccountsResponseStoreFactory
import com.tangem.data.common.currency.ResponseCryptoCurrenciesFactory
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency

View file

@ -5,6 +5,7 @@ import arrow.core.some
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.common.wallets.loadAndGet
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.utils.coroutines.CoroutineDispatcherProvider

View file

@ -5,6 +5,7 @@ import arrow.core.some
import com.tangem.data.common.currency.ResponseCryptoCurrenciesFactory
import com.tangem.datasource.local.token.UserTokensResponseStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency

View file

@ -7,6 +7,7 @@ import com.tangem.data.common.currency.CardCryptoCurrencyFactory
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.common.wallets.getSyncStrict
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.models.wallet.isMultiCurrency

View file

@ -8,6 +8,7 @@ import com.tangem.datasource.api.tangemTech.models.account.GetWalletAccountsResp
import com.tangem.datasource.api.tangemTech.models.account.WalletAccountDTO
import com.tangem.domain.account.models.AccountList
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncOrNull
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.account.DerivationIndex

View file

@ -27,7 +27,7 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class DefaultMultiAccountListProducerTest {
private val userWalletsListRepository: UserWalletsListRepository = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk(relaxUnitFun = true)
private val walletAccountListFlowFactory: WalletAccountListFlowFactory = mockk()
private val flowProducerTools: FlowProducerTools = mockk()
@ -53,7 +53,7 @@ class DefaultMultiAccountListProducerTest {
fun produce() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val accountList = AccountList.empty(userWalletId)
every { walletAccountListFlowFactory.create(userWalletId) } returns flowOf(accountList)
@ -65,8 +65,9 @@ class DefaultMultiAccountListProducerTest {
val expected = listOf(accountList)
Truth.assertThat(actual).containsExactly(expected)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -75,7 +76,7 @@ class DefaultMultiAccountListProducerTest {
fun `flow will updated if factoryFlow is updated`() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val accountList = AccountList.empty(userWalletId)
val updatedAccountList = AccountList.empty(userWalletId = userWalletId, sortType = TokensSortType.NONE)
@ -97,10 +98,12 @@ class DefaultMultiAccountListProducerTest {
// Assert (second emission)
Truth.assertThat(secondEmission).containsExactly(listOf(updatedAccountList))
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
walletAccountListFlowFactory.create(userWalletId)
userWalletsListRepository.loadAndGet()
userWalletsListRepository.load()
userWalletsListRepository.userWallets
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -109,7 +112,7 @@ class DefaultMultiAccountListProducerTest {
fun `flow is filtered the same response`() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val accountList = AccountList.empty(userWalletId)
val factoryFlow = MutableStateFlow<AccountList?>(null)
@ -130,10 +133,12 @@ class DefaultMultiAccountListProducerTest {
// Assert (second emission)
Truth.assertThat(secondEmission).containsExactly(listOf(accountList))
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
walletAccountListFlowFactory.create(userWalletId)
userWalletsListRepository.loadAndGet()
userWalletsListRepository.load()
userWalletsListRepository.userWallets
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -143,7 +148,7 @@ class DefaultMultiAccountListProducerTest {
fun `flow returns empty list if factory throws exception`() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val exception = RuntimeException("Converter error")
every { walletAccountListFlowFactory.create(userWalletId) } throws exception
@ -155,8 +160,9 @@ class DefaultMultiAccountListProducerTest {
val expected = emptyList<AccountList>()
Truth.assertThat(actual).containsExactly(expected)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -164,8 +170,8 @@ class DefaultMultiAccountListProducerTest {
@Test
fun `flow is empty if userWalletsFlow returns empty flow`() = runTest {
// Arrange
val userWalletsFlow = emptyFlow<List<UserWallet>>()
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
val userWalletsFlow = MutableStateFlow<List<UserWallet>>(emptyList())
every { userWalletsListRepository.userWallets } returns userWalletsFlow
// Act
val actual = producer.produce().let(::getEmittedValues)
@ -173,7 +179,10 @@ class DefaultMultiAccountListProducerTest {
// Assert
Truth.assertThat(actual).isEmpty() // no emissions
coVerify(exactly = 1) { userWalletsListRepository.loadAndGet() }
coVerify(exactly = 1) {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
}
coVerify(inverse = true) { walletAccountListFlowFactory.create(any()) }
}
@ -181,7 +190,7 @@ class DefaultMultiAccountListProducerTest {
fun `flow is empty if factory returns empty flow`() = runTest {
// Arrange
val userWalletsFlow = MutableStateFlow(value = listOf(userWallet))
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every { walletAccountListFlowFactory.create(userWalletId) } returns emptyFlow()
@ -191,8 +200,9 @@ class DefaultMultiAccountListProducerTest {
// Assert
Truth.assertThat(actual).isEmpty() // no emissions
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
walletAccountListFlowFactory.create(userWalletId)
}
}
@ -206,7 +216,7 @@ class DefaultMultiAccountListProducerTest {
}
val userWalletsFlow = MutableStateFlow(listOf(userWallet, userWallet2))
every { userWalletsListRepository.loadAndGet() } returns userWalletsFlow
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val accountList = AccountList.empty(userWalletId)
every { walletAccountListFlowFactory.create(userWalletId) } returns flowOf(accountList)
@ -218,8 +228,9 @@ class DefaultMultiAccountListProducerTest {
// Assert
Truth.assertThat(actual).isEmpty() // no emissions
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
walletAccountListFlowFactory.create(userWalletId)
walletAccountListFlowFactory.create(userWalletId2)
}

View file

@ -59,7 +59,9 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
// Arrange
val userTokensResponseFlow = flowOf<UserTokensResponse?>(null)
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every { userTokensResponseStore.get(params.userWalletId) } returns userTokensResponseFlow
// Act
@ -72,7 +74,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual.first()).isEqualTo(expected)
verifyOrder {
userWalletsListRepository.getSyncStrict(params.userWalletId)
userWalletsListRepository.userWallets
userTokensResponseStore.get(params.userWalletId)
}
@ -113,7 +115,9 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
cryptoCurrencyFactory.createCoin(Blockchain.Bitcoin),
)
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every { userTokensResponseStore.get(params.userWalletId) } returns userTokensResponseFlow
every {
@ -146,7 +150,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual1.first()).isEqualTo(expected1)
verifyOrder {
userWalletsListRepository.getSyncStrict(params.userWalletId)
userWalletsListRepository.userWallets
userTokensResponseStore.get(params.userWalletId)
responseCryptoCurrenciesFactory.createCurrencies(
response = userTokensResponse,
@ -188,7 +192,9 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
val cryptoCurrencies = emptySet<CryptoCurrency>()
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every { userTokensResponseStore.get(params.userWalletId) } returns userTokensResponseFlow
every {
@ -213,7 +219,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual1.first()).isEqualTo(expected1)
verifyOrder {
userWalletsListRepository.getSyncStrict(params.userWalletId)
userWalletsListRepository.userWallets
userTokensResponseStore.get(params.userWalletId)
responseCryptoCurrenciesFactory.createCurrencies(
response = userTokensResponse,
@ -257,7 +263,9 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
}
.buffer(capacity = 5)
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every { userTokensResponseStore.get(params.userWalletId) } returns userTokensResponseFlow
every {
@ -279,7 +287,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual1.first()).isEqualTo(expected1)
verifyOrder {
userWalletsListRepository.getSyncStrict(params.userWalletId)
userWalletsListRepository.userWallets
userTokensResponseStore.get(params.userWalletId)
}
@ -304,7 +312,9 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
@Test
fun `flow is empty if store returns empty flow`() = runTest {
// Arrange
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every { userTokensResponseStore.get(params.userWalletId) } returns emptyFlow()
// Act
@ -316,7 +326,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual.first()).isEqualTo(expected)
verifyOrder {
userWalletsListRepository.getSyncStrict(params.userWalletId)
userWalletsListRepository.userWallets
userTokensResponseStore.get(params.userWalletId)
}
@ -329,10 +339,13 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
fun `produce throws exception if UserWallet isn't multi-currency wallet`() = runTest {
// Arrange
val mockUserWallet = mockk<UserWallet> {
every { walletId } returns userWallet.walletId
every { isMultiCurrency } returns false
}
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
// Act
val actual = runCatching { producer.produce() }.exceptionOrNull()
@ -345,7 +358,7 @@ internal class DefaultMultiWalletCryptoCurrenciesProducerTest {
Truth.assertThat(actual).isInstanceOf(expected::class.java)
Truth.assertThat(actual).hasMessageThat().isEqualTo(expected.message)
verifyOrder { userWalletsListRepository.getSyncStrict(params.userWalletId) }
verifyOrder { userWalletsListRepository.userWallets }
verify(inverse = true) {
userTokensResponseStore.get(any())

View file

@ -70,7 +70,9 @@ class WalletAccountListFlowFactoryTest {
every { this@mockk.isMultiCurrency } returns true
}
every { userWalletsListRepository.getSyncStrict(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val accountsResponse = createGetWalletAccountsResponse(userWalletId)
every { accountsResponseStoreFactory.create(userWalletId) } returns accountsResponseStore
@ -88,7 +90,8 @@ class WalletAccountListFlowFactoryTest {
val expected = accountList
Truth.assertThat(actual).containsExactly(expected)
coVerify(ordering = Ordering.SEQUENCE) {
coVerifySequence {
userWalletsListRepository.userWallets
accountsResponseStoreFactory.create(userWalletId)
accountsResponseStore.data
accountListConverterFactory.create(userWallet)
@ -105,7 +108,9 @@ class WalletAccountListFlowFactoryTest {
fun `create for single wallet`() = runTest {
val userWallet = MockUserWalletFactory.create().copy(isMultiCurrency = false)
every { userWalletsListRepository.getSyncStrict(userWallet.walletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val currency = cryptoCurrencyFactory.ethereum
every { cardCryptoCurrencyFactory.createPrimaryCurrencyForSingleCurrencyCard(userWallet) } returns currency
@ -117,11 +122,12 @@ class WalletAccountListFlowFactoryTest {
val expected = AccountList.empty(userWalletId = userWallet.walletId, cryptoCurrencies = setOf(currency))
Truth.assertThat(actual).containsExactly(expected)
coVerify(ordering = Ordering.SEQUENCE) {
coVerifySequence {
cardCryptoCurrencyFactory.createPrimaryCurrencyForSingleCurrencyCard(userWallet)
}
coVerify(inverse = true) {
userWalletsListRepository.userWallets
cardCryptoCurrencyFactory.createCurrenciesForSingleCurrencyCardWithToken(userWallet = any())
accountsResponseStoreFactory.create(any())
accountsResponseStore.data
@ -134,7 +140,9 @@ class WalletAccountListFlowFactoryTest {
fun `flow is created for single wallet with token`() = runTest {
val nodl = MockUserWalletFactory.createSingleWalletWithToken()
every { userWalletsListRepository.getSyncStrict(nodl.walletId) } returns nodl
val userWalletsFlow = MutableStateFlow(listOf(nodl))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val currencies = cryptoCurrencyFactory.ethereumAndStellar.toSet()
every {
@ -148,7 +156,8 @@ class WalletAccountListFlowFactoryTest {
val expected = AccountList.empty(userWalletId = nodl.walletId, cryptoCurrencies = currencies)
Truth.assertThat(actual).containsExactly(expected)
coVerify(ordering = Ordering.SEQUENCE) {
coVerifySequence {
userWalletsListRepository.userWallets
cardCryptoCurrencyFactory.createCurrenciesForSingleCurrencyCardWithToken(userWallet = nodl)
}

View file

@ -13,7 +13,11 @@ 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
import io.mockk.*
import io.mockk.clearMocks
import io.mockk.coVerifyOrder
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
@ -63,7 +67,9 @@ class DefaultWalletAccountsResponseFactoryTest {
tokens = emptyList(),
)
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns null
val userWalletsFlow = MutableStateFlow<List<UserWallet>?>(null)
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every {
userTokensResponseFactory.createDefaultResponse(
userWallet = null,
@ -89,7 +95,7 @@ class DefaultWalletAccountsResponseFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
userWalletsListRepository.userWallets
userTokensResponseFactory.createDefaultResponse(
userWallet = null,
networkFactory = networkFactory,
@ -105,7 +111,9 @@ class DefaultWalletAccountsResponseFactoryTest {
every { walletId } returns userWalletId
}
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val accounts = AccountList.empty(userWallet.walletId).accounts
.filterIsInstance<Account.CryptoPortfolio>()
@ -145,7 +153,7 @@ class DefaultWalletAccountsResponseFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
userWalletsListRepository.userWallets
cryptoPortfolioConverter.convertListBack(accounts)
userTokensResponseFactory.createDefaultResponse(
userWallet = userWallet,
@ -165,7 +173,9 @@ class DefaultWalletAccountsResponseFactoryTest {
val accounts = AccountList.empty(userWallet.walletId).accounts
.filterIsInstance<Account.CryptoPortfolio>()
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val defaultResponse = UserTokensResponse(
group = UserTokensResponse.GroupType.NETWORK,
@ -206,7 +216,9 @@ class DefaultWalletAccountsResponseFactoryTest {
val userWallet = mockk<UserWallet>(relaxed = true) {
every { walletId } returns userWalletId
}
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val userTokensResponse = UserTokensResponse(
group = UserTokensResponse.GroupType.NETWORK,

View file

@ -9,6 +9,7 @@ import com.tangem.datasource.local.token.UserTokensResponseStore
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency

View file

@ -13,6 +13,7 @@ import com.tangem.datasource.local.appsflyer.AppsFlyerStore
import com.tangem.datasource.local.token.UserTokensResponseStore
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncOrNull
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider

View file

@ -5,6 +5,7 @@ import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.api.tangemTech.converters.WalletIdBodyConverter
import com.tangem.datasource.local.appsflyer.AppsFlyerStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncOrNull
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider

View file

@ -24,6 +24,7 @@ import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.test.core.ProvideTestModels
import io.mockk.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
@ -78,11 +79,12 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
fun `create currencies in ETH for multi-currency wallet`(model: CreateTestModel.MultiWallet) = runTest {
// Arrange
val userWallet = createMultiWallet()
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
val userTokensResponse = model.userTokensResponse
val network = ethereum.network
every { accountsFeatureToggles.isFeatureEnabled } returns false
coEvery { userWalletsListRepository.getSyncStrict(id = userWallet.walletId) } returns userWallet
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { userTokensResponseStore.getSyncOrNull(userWallet.walletId) } returns userTokensResponse
// Act
@ -94,7 +96,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = userWallet.walletId)
userWalletsListRepository.userWallets
userTokensResponseStore.getSyncOrNull(userWalletId = userWallet.walletId)
}
}
@ -130,8 +132,9 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
fun `create currencies for single-currency wallet (ETH)`(model: CreateTestModel.SingleWallet) = runTest {
// Arrange
val userWallet = createSingleWallet()
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
coEvery { userWalletsListRepository.getSyncStrict(id = userWallet.walletId) } returns userWallet
every { userWalletsListRepository.userWallets } returns userWalletsFlow
// Act
val actual = factory.create(userWalletId = userWallet.walletId, network = model.network)
@ -142,7 +145,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = userWallet.walletId)
userWalletsListRepository.userWallets
userWallet.scanResponse.cardTypesResolver.getBlockchain()
}
@ -168,8 +171,9 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
) = runTest {
// Arrange
val userWallet = MockUserWalletFactory.createSingleWalletWithToken()
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
coEvery { userWalletsListRepository.getSyncStrict(id = userWallet.walletId) } returns userWallet
every { userWalletsListRepository.userWallets } returns userWalletsFlow
// Act
val actual = factory.create(userWalletId = userWallet.walletId, network = model.network)
@ -186,7 +190,7 @@ internal class DefaultCardCryptoCurrencyFactoryTest {
Truth.assertThat(actual).isEqualTo(expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = userWallet.walletId)
userWalletsListRepository.userWallets
userWallet.scanResponse.cardTypesResolver.getBlockchain()
}

View file

@ -14,6 +14,7 @@ import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
import io.mockk.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -118,8 +119,10 @@ class UserTokensSaverTest {
val error = ApiResponseError.UnknownException(Exception("API Error"))
var onFailSendCalled = false
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { accountsFeatureToggles.isFeatureEnabled } returns true
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { enricher(userWalletId, response) } returns enrichedResponse
coEvery { tangemTechApi.saveTokens(any(), any()) } returns ApiResponse.Error(error) as ApiResponse<Unit>
@ -132,6 +135,7 @@ class UserTokensSaverTest {
// THEN
coVerifyOrder {
userWalletsListRepository.userWallets
enricher(userWalletId, response)
tangemTechApi.saveTokens(userWalletId.stringValue, enrichedResponse)
}
@ -165,7 +169,9 @@ class UserTokensSaverTest {
walletType = WalletType.COLD,
)
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { enricher(userWalletId, response) } returns enrichedResponse
coEvery {
tangemTechApi.saveTokens(userWalletId.stringValue, enrichedResponse)
@ -177,6 +183,7 @@ class UserTokensSaverTest {
// THEN
coVerifyOrder {
enricher(userWalletId, response)
userWalletsListRepository.userWallets
tangemTechApi.saveTokens(userWalletId.stringValue, enrichedResponse)
}
}

View file

@ -14,6 +14,7 @@ import com.tangem.domain.wallets.models.AppsFlyerConversionData
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
import io.mockk.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Nested
@ -65,7 +66,9 @@ internal class DefaultWalletServerBinderTest {
)
val apiResponse = ApiResponse.Success(Unit)
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { appsFlyerStore.get() } returns conversionData
coEvery { tangemTechApi.createWallet(requestBody) } returns apiResponse
@ -74,7 +77,7 @@ internal class DefaultWalletServerBinderTest {
Truth.assertThat(actual).isEqualTo(apiResponse)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
userWalletsListRepository.userWallets
appsFlyerStore.get()
tangemTechApi.createWallet(requestBody)
}
@ -82,15 +85,15 @@ internal class DefaultWalletServerBinderTest {
@Test
fun `bind will skipped if userWalletsListRepository returns null`() = runTest {
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns null
val userWalletsFlow = MutableStateFlow<List<UserWallet>?>(null)
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val actual = binder.bind(userWalletId = userWalletId)
Truth.assertThat(actual).isEqualTo(null)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
}
coVerifyOrder { userWalletsListRepository.userWallets }
coVerify(inverse = true) {
appsFlyerStore.get()
@ -107,7 +110,9 @@ internal class DefaultWalletServerBinderTest {
)
val apiResponse = ApiResponse.Success(Unit)
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { appsFlyerStore.get() } returns null
coEvery { tangemTechApi.createWallet(requestBody) } returns apiResponse
@ -116,7 +121,7 @@ internal class DefaultWalletServerBinderTest {
Truth.assertThat(actual).isEqualTo(apiResponse)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
userWalletsListRepository.userWallets
appsFlyerStore.get()
tangemTechApi.createWallet(requestBody)
}
@ -133,7 +138,9 @@ internal class DefaultWalletServerBinderTest {
)
val apiResponse = ApiResponse.Error(ApiResponseError.TimeoutException()) as ApiResponse<Unit>
coEvery { userWalletsListRepository.getSyncOrNull(userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { appsFlyerStore.get() } returns conversionData
coEvery { tangemTechApi.createWallet(requestBody) } returns apiResponse
@ -142,7 +149,7 @@ internal class DefaultWalletServerBinderTest {
Truth.assertThat(actual).isEqualTo(apiResponse)
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(userWalletId)
userWalletsListRepository.userWallets
appsFlyerStore.get()
tangemTechApi.createWallet(requestBody)
}

View file

@ -11,6 +11,7 @@ import com.tangem.datasource.exchangeservice.swap.ExpressUtils.getRefCode
import com.tangem.datasource.local.preferences.AppPreferencesStore
import com.tangem.datasource.local.token.ExpressAssetsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.core.lce.Lce
import com.tangem.domain.core.utils.catchOn
import com.tangem.domain.core.utils.lceContent

View file

@ -18,6 +18,7 @@ import com.tangem.domain.card.common.extensions.hotWalletExcludedBlockchains
import com.tangem.domain.card.common.extensions.supportedBlockchains
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.managetokens.model.AddCustomTokenForm
import com.tangem.domain.managetokens.model.ManagedCryptoCurrency
import com.tangem.domain.managetokens.repository.CustomTokensRepository

View file

@ -27,6 +27,7 @@ import com.tangem.domain.card.common.TapWorkarounds.isTestCard
import com.tangem.domain.card.common.extensions.*
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.managetokens.model.*
import com.tangem.domain.managetokens.model.ManagedCryptoCurrency.SourceNetwork
import com.tangem.domain.managetokens.repository.ManageTokensRepository

View file

@ -21,6 +21,7 @@ import com.tangem.datasource.api.markets.models.response.TokenMarketExchangesRes
import com.tangem.datasource.local.datastore.RuntimeStateStore
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.markets.*
import com.tangem.domain.markets.repositories.MarketsTokenRepository
import com.tangem.domain.models.account.DerivationIndex

View file

@ -5,6 +5,7 @@ import arrow.core.some
import com.tangem.data.common.network.NetworkFactory
import com.tangem.data.networks.store.NetworksStatusesStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncOrNull
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.network.NetworkStatus
import com.tangem.domain.networks.multi.MultiNetworkStatusProducer

View file

@ -11,6 +11,7 @@ import com.tangem.data.networks.store.NetworksStatusesStore
import com.tangem.data.networks.toSimple
import com.tangem.domain.card.configs.GenericCardConfig
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncOrNull
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.models.network.NetworkStatus
import com.tangem.domain.networks.multi.MultiNetworkStatusProducer
@ -65,7 +66,9 @@ internal class DefaultMultiNetworkStatusProducerTest {
val networksStatusesFlow = flowOf(simpleStatuses)
every { networksStatusesStore.get(params.userWalletId) } returns networksStatusesFlow
every { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every {
networkFactory.create(
@ -94,7 +97,7 @@ internal class DefaultMultiNetworkStatusProducerTest {
verifyOrder {
networksStatusesStore.get(params.userWalletId)
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
networkFactory.create(
networkId = simpleStatuses.first().id,
derivationPath = simpleStatuses.first().id.derivationPath,
@ -129,7 +132,9 @@ internal class DefaultMultiNetworkStatusProducerTest {
// region every
every { networksStatusesStore.get(params.userWalletId) } returns networksStatusesFlow
every { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every {
networkFactory.create(
networkId = simpleStatuses.first().id,
@ -177,7 +182,7 @@ internal class DefaultMultiNetworkStatusProducerTest {
Truth.assertThat(actual1.first()).isEqualTo(expected1)
verifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
networkFactory.create(
networkId = simpleStatuses.first().id,
derivationPath = simpleStatuses.first().id.derivationPath,
@ -202,7 +207,7 @@ internal class DefaultMultiNetworkStatusProducerTest {
Truth.assertThat(actual2).isEqualTo(expected2)
verifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
networkFactory.create(
networkId = updatedSimpleStatuses.first().id,
derivationPath = updatedSimpleStatuses.first().id.derivationPath,
@ -230,7 +235,9 @@ internal class DefaultMultiNetworkStatusProducerTest {
// region every
every { networksStatusesStore.get(params.userWalletId) } returns networksStatusesFlow
every { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every {
networkFactory.create(
@ -263,7 +270,7 @@ internal class DefaultMultiNetworkStatusProducerTest {
Truth.assertThat(actual1.first()).isEqualTo(expected1)
verifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
networkFactory.create(
networkId = simpleStatuses.first().id,
derivationPath = simpleStatuses.first().id.derivationPath,
@ -312,7 +319,9 @@ internal class DefaultMultiNetworkStatusProducerTest {
// region every
every { networksStatusesStore.get(params.userWalletId) } returns networksStatusesFlow
every { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
every {
networkFactory.create(
networkId = simpleStatuses.first().id,
@ -354,7 +363,7 @@ internal class DefaultMultiNetworkStatusProducerTest {
Truth.assertThat(actual2.first()).isEqualTo(expected2)
verifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
networkFactory.create(
networkId = simpleStatuses.first().id,
derivationPath = simpleStatuses.first().id.derivationPath,
@ -382,7 +391,7 @@ internal class DefaultMultiNetworkStatusProducerTest {
Truth.assertThat(actual.first()).isEqualTo(expected)
verify { networksStatusesStore.get(params.userWalletId) }
verify(inverse = true) { userWalletsListRepository.getSyncOrNull(params.userWalletId) }
verify(inverse = true) { userWalletsListRepository.userWallets }
}
@Test
@ -398,7 +407,9 @@ internal class DefaultMultiNetworkStatusProducerTest {
val networksStatusesFlow = flowOf(simpleStatuses)
every { networksStatusesStore.get(params.userWalletId) } returns networksStatusesFlow
every { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { networkFactory.create(networkId = any(), any(), any()) } returns null
// Act
@ -411,7 +422,7 @@ internal class DefaultMultiNetworkStatusProducerTest {
verifyOrder {
networksStatusesStore.get(params.userWalletId)
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
networkFactory.create(
networkId = simpleStatuses.first().id,
derivationPath = simpleStatuses.first().id.derivationPath,

View file

@ -18,6 +18,7 @@ import com.tangem.datasource.local.nft.converter.NFTSdkCollectionConverter
import com.tangem.datasource.local.nft.converter.NFTSdkCollectionIdentifierConverter
import com.tangem.domain.card.common.extensions.canHandleToken
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.StatusSource
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network

View file

@ -22,6 +22,8 @@ import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.card.common.extensions.canHandleBlockchain
import com.tangem.domain.card.common.extensions.canHandleToken
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.common.wallets.loadAndGet
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.onramp.model.HotCryptoCurrency
@ -89,8 +91,7 @@ internal class DefaultHotCryptoRepository(
.map { it[userWalletId] }
.filterNotNull()
.map { response ->
val userWallet = userWalletsListRepository.getSyncOrNull(userWalletId)
?: error("UserWalletId [$userWalletId] not found")
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
HotCryptoCurrencyConverter(
userWallet = userWallet,

View file

@ -18,6 +18,7 @@ import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO
import com.tangem.datasource.local.token.P2PEthPoolVaultsStore
import com.tangem.datasource.local.token.StakingYieldsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncOrNull
import com.tangem.domain.core.utils.catchOn
import com.tangem.domain.models.staking.StakingID
import com.tangem.domain.models.wallet.UserWallet

View file

@ -16,12 +16,12 @@ import com.tangem.datasource.local.token.P2PEthPoolVaultsStore
import com.tangem.datasource.local.token.StakingYieldsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.staking.StakingID
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.staking.multi.MultiStakingBalanceFetcher
import com.tangem.test.core.assertEitherLeft
import com.tangem.test.core.assertEitherRight
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
import io.mockk.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -62,7 +62,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val yields = listOf(MockYieldDTOFactory.create(tonId), MockYieldDTOFactory.create(solanaId))
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
@ -80,7 +82,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitApi.getMultipleYieldBalances(requests)
@ -97,7 +99,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val yields = listOf(MockYieldDTOFactory.create(tonId))
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
@ -112,7 +116,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId = userWalletId, stakingIds = setOf(solanaId))
@ -129,13 +133,15 @@ internal class DefaultMultiStakingBalanceFetcherTest {
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
val userWallet = MockUserWalletFactory.create().copy(isMultiCurrency = false)
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
// Actual
val actual = fetcher.invoke(params)
// Assert
coVerifyOrder { userWalletsListRepository.getSyncOrNull(params.userWalletId) }
coVerifyOrder { userWalletsListRepository.userWallets }
coVerify(inverse = true) {
stakeKitBalancesStore.refresh(userWalletId = any(), stakingIds = any())
@ -155,13 +161,14 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns null
val userWalletsFlow = MutableStateFlow(null)
coEvery { userWalletsListRepository.userWallets } returns userWalletsFlow
// Actual
val actual = fetcher.invoke(params)
// Assert
coVerifyOrder { userWalletsListRepository.getSyncOrNull(params.userWalletId) }
coVerifyOrder { userWalletsListRepository.userWallets }
coVerify(inverse = true) {
stakeKitBalancesStore.refresh(userWalletId = any(), stakingIds = any())
@ -181,7 +188,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns null
// Actual
@ -189,7 +198,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
stakeKitBalancesStore.refresh(params.userWalletId, tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
@ -210,7 +219,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns emptyList()
// Actual
@ -218,7 +229,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
@ -239,7 +250,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val yields = listOf(
MockYieldDTOFactory.create(tonId).copy(id = null),
@ -252,7 +265,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
@ -273,7 +286,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val yields = listOf(MockYieldDTOFactory.create(StakingID(integrationId = "polygon", address = "0x1")))
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
@ -283,7 +298,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
@ -310,7 +325,9 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val userWalletsFlow = MutableStateFlow(listOf(userWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
val yields = listOf(MockYieldDTOFactory.create(tonId), MockYieldDTOFactory.create(solanaId))
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
@ -328,7 +345,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsListRepository.getSyncOrNull(params.userWalletId)
userWalletsListRepository.userWallets
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitApi.getMultipleYieldBalances(requests)
@ -343,8 +360,8 @@ internal class DefaultMultiStakingBalanceFetcherTest {
}
private companion object {
val userWalletId = UserWalletId("011")
val userWallet = MockUserWalletFactory.create()
val userWalletId = userWallet.walletId
val tonId = MockYieldBalanceWrapperDTOFactory.defaultStakingId
val solanaId = StakingID(

View file

@ -5,6 +5,7 @@ import arrow.core.right
import com.tangem.data.common.account.WalletAccountsFetcher
import com.tangem.datasource.api.tangemTech.models.account.flattenTokens
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.core.utils.catchOn
import com.tangem.domain.express.ExpressServiceFetcher
import com.tangem.domain.express.models.ExpressAsset

View file

@ -11,6 +11,7 @@ import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
import com.tangem.datasource.local.token.UserTokensResponseStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.core.utils.catchOn
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.express.ExpressServiceFetcher

View file

@ -17,6 +17,8 @@ import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.card.CardTypesResolver
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.common.wallets.loadAndGet
import com.tangem.domain.core.error.DataError
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.express.ExpressServiceFetcher

View file

@ -14,6 +14,7 @@ import com.tangem.test.core.assertEither
import com.tangem.test.core.assertEitherRight
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
import io.mockk.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -43,8 +44,13 @@ internal class AccountListCryptoCurrenciesFetcherTest {
fun `returns failure if wallet is not multi-currency`() = runTest {
// Arrange
val params = MultiWalletCryptoCurrenciesFetcher.Params(userWalletId = userWalletId)
val mockUserWallet = mockk<UserWallet> { every { isMultiCurrency } returns false }
every { userWalletsListRepository.getSyncStrict(id = params.userWalletId) } returns mockUserWallet
val mockUserWallet = mockk<UserWallet> {
every { walletId } returns userWalletId
every { isMultiCurrency } returns false
}
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
// Act
val actual = fetcher(params)
@ -55,7 +61,7 @@ internal class AccountListCryptoCurrenciesFetcherTest {
).left()
assertEither(actual, expected)
verify { userWalletsListRepository.getSyncStrict(id = params.userWalletId) }
verify { userWalletsListRepository.userWallets }
coVerify(inverse = true) { walletAccountsFetcher.fetch(any()) }
}
@ -63,10 +69,15 @@ internal class AccountListCryptoCurrenciesFetcherTest {
fun `returns accounts if wallet is multi-currency`() = runTest {
// Arrange
val params = MultiWalletCryptoCurrenciesFetcher.Params(userWalletId = userWalletId)
val mockUserWallet = mockk<UserWallet> { every { isMultiCurrency } returns true }
val mockUserWallet = mockk<UserWallet> {
every { walletId } returns userWalletId
every { isMultiCurrency } returns true
}
val response = mockk<GetWalletAccountsResponse>(relaxed = true)
every { userWalletsListRepository.getSyncStrict(id = params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { walletAccountsFetcher.fetch(userWalletId = params.userWalletId) } returns response
coEvery { expressServiceFetcher.fetch(userWallet = mockUserWallet, assetIds = emptySet()) } returns Unit.right()
@ -77,7 +88,7 @@ internal class AccountListCryptoCurrenciesFetcherTest {
assertEitherRight(actual)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.getSyncStrict(id = params.userWalletId)
userWalletsListRepository.userWallets
walletAccountsFetcher.fetch(userWalletId = params.userWalletId)
expressServiceFetcher.fetch(userWallet = mockUserWallet, assetIds = emptySet())
}
@ -87,10 +98,15 @@ internal class AccountListCryptoCurrenciesFetcherTest {
fun `returns error if walletAccountsFetcher returns error`() = runTest {
// Arrange
val params = MultiWalletCryptoCurrenciesFetcher.Params(userWalletId = userWalletId)
val mockUserWallet = mockk<UserWallet> { every { isMultiCurrency } returns true }
val mockUserWallet = mockk<UserWallet> {
every { walletId } returns userWalletId
every { isMultiCurrency } returns true
}
val error = RuntimeException("fetch error")
every { userWalletsListRepository.getSyncStrict(id = params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { walletAccountsFetcher.fetch(userWalletId = params.userWalletId) } throws error
// Act
@ -101,7 +117,7 @@ internal class AccountListCryptoCurrenciesFetcherTest {
assertEither(actual, expected)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.getSyncStrict(id = params.userWalletId)
userWalletsListRepository.userWallets
walletAccountsFetcher.fetch(userWalletId = params.userWalletId)
}
}

View file

@ -24,6 +24,7 @@ import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesFetcher
import com.tangem.test.core.assertEither
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
import io.mockk.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -76,10 +77,13 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
val params = MultiWalletCryptoCurrenciesFetcher.Params(userWalletId = userWalletId)
val mockUserWallet = mockk<UserWallet> {
every { walletId } returns userWalletId
every { isMultiCurrency } returns false
}
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
// Act
val actual = fetcher(params)
@ -90,7 +94,7 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
).left()
assertEither(actual, expected)
verifyOrder { userWalletsListRepository.getSyncStrict(id = params.userWalletId) }
verifyOrder { userWalletsListRepository.userWallets }
coVerify(inverse = true) {
userTokensResponseStore.getSyncOrNull(any())
}
@ -121,7 +125,9 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
),
)
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { userTokensResponseStore.getSyncOrNull(userWalletId = params.userWalletId) } returns null
every {
cardCryptoCurrencyFactory.createDefaultCoinsForMultiCurrencyWallet(mockUserWallet)
@ -145,7 +151,7 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
assertEither(actual, expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = params.userWalletId)
userWalletsListRepository.userWallets
userTokensResponseStore.getSyncOrNull(userWalletId = params.userWalletId)
cardCryptoCurrencyFactory.createDefaultCoinsForMultiCurrencyWallet(mockUserWallet)
customTokensMerger.mergeIfPresented(userWalletId = params.userWalletId, response = userTokensResponse)
@ -169,7 +175,9 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
data = defaultResponse.copy(group = UserTokensResponse.GroupType.TOKEN),
)
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { userTokensResponseStore.getSyncOrNull(userWalletId = params.userWalletId) } returns defaultResponse
coEvery { tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue) } returns apiResponse
coEvery {
@ -191,7 +199,7 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
assertEither(actual, expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = params.userWalletId)
userWalletsListRepository.userWallets
userTokensResponseStore.getSyncOrNull(userWalletId = params.userWalletId)
tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue)
customTokensMerger.mergeIfPresented(userWalletId = params.userWalletId, response = apiResponse.data)
@ -219,7 +227,9 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
data = defaultResponse.copy(group = UserTokensResponse.GroupType.TOKEN),
)
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue) } returns apiResponse
coEvery {
customTokensMerger.mergeIfPresented(userWalletId = params.userWalletId, response = apiResponse.data)
@ -240,7 +250,7 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
assertEither(actual, expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = params.userWalletId)
userWalletsListRepository.userWallets
tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue)
customTokensMerger.mergeIfPresented(userWalletId = params.userWalletId, response = apiResponse.data)
userTokensSaver.store(userWalletId = params.userWalletId, response = apiResponse.data)
@ -283,7 +293,9 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
),
)
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue) } returns apiResponse
coEvery { userTokensResponseStore.getSyncOrNull(userWalletId = userWalletId) } returns null
coEvery {
@ -308,7 +320,7 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
assertEither(actual, expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = params.userWalletId)
userWalletsListRepository.userWallets
tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue)
userTokensResponseStore.getSyncOrNull(userWalletId = userWalletId)
customTokensMerger.mergeIfPresented(userWalletId = params.userWalletId, response = userTokensResponse)
@ -337,7 +349,9 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
cause = ApiResponseError.TimeoutException(),
) as ApiResponse<UserTokensResponse>
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue) } returns apiResponse
coEvery { userTokensResponseStore.getSyncOrNull(userWalletId = userWalletId) } returns defaultResponse
coEvery {
@ -359,7 +373,7 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
assertEither(actual, expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = params.userWalletId)
userWalletsListRepository.userWallets
tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue)
userTokensResponseStore.getSyncOrNull(userWalletId = userWalletId)
customTokensMerger.mergeIfPresented(userWalletId = params.userWalletId, response = defaultResponse)
@ -407,7 +421,9 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
),
)
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue) } returns apiResponse
coEvery { userTokensResponseStore.getSyncOrNull(userWalletId = userWalletId) } returns null
coEvery {
@ -432,7 +448,7 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
assertEither(actual, expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = params.userWalletId)
userWalletsListRepository.userWallets
tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue)
userTokensResponseStore.getSyncOrNull(userWalletId = userWalletId)
cardCryptoCurrencyFactory.createDefaultCoinsForMultiCurrencyWallet(mockUserWallet)
@ -463,7 +479,9 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
),
) as ApiResponse<UserTokensResponse>
every { userWalletsListRepository.getSyncStrict(params.userWalletId) } returns mockUserWallet
val userWalletsFlow = MutableStateFlow(listOf(mockUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue) } returns apiResponse
coEvery { userTokensResponseStore.getSyncOrNull(userWalletId = userWalletId) } returns defaultResponse
coEvery {
@ -485,7 +503,7 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcherTest {
assertEither(actual, expected)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(id = params.userWalletId)
userWalletsListRepository.userWallets
tangemTechApi.getUserTokens(userId = params.userWalletId.stringValue)
userTokensResponseStore.getSyncOrNull(userWalletId = userWalletId)
userTokensSaver.push(userWalletId = params.userWalletId, response = defaultResponse)

View file

@ -9,6 +9,7 @@ import com.tangem.data.common.cache.CacheRegistry
import com.tangem.data.txhistory.repository.paging.TxHistoryPagingSource
import com.tangem.datasource.local.txhistory.TxHistoryItemsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.models.wallet.UserWalletId

View file

@ -18,6 +18,7 @@ import com.tangem.datasource.api.visa.VisaApi
import com.tangem.datasource.api.visa.models.response.VisaTxHistoryResponse
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.models.wallet.requireColdWallet

View file

@ -9,6 +9,7 @@ import com.tangem.datasource.api.pay.models.request.RefreshTokenByCardWalletRequ
import com.tangem.datasource.api.visa.VisaApi
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.common.wallets.update
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId

View file

@ -1,6 +1,7 @@
package com.tangem.data.walletconnect
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.models.wallet.isMultiCurrency
import com.tangem.domain.walletconnect.repository.WalletConnectRepository

View file

@ -30,6 +30,7 @@ import com.tangem.data.walletmanager.utils.*
import com.tangem.datasource.asset.loader.AssetLoader
import com.tangem.datasource.local.walletmanager.WalletManagersStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network

View file

@ -26,6 +26,8 @@ import com.tangem.datasource.local.preferences.utils.getSyncOrNull
import com.tangem.datasource.local.preferences.utils.store
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncOrNull
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.wallets.models.SeedPhraseNotificationsStatus

View file

@ -4,6 +4,7 @@ import arrow.core.getOrElse
import com.tangem.common.extensions.ByteArrayKey
import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network

View file

@ -8,6 +8,7 @@ import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.data.common.network.NetworkFactory
import com.tangem.data.wallets.derivations.MissedDerivationsFinder
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network

View file

@ -12,6 +12,7 @@ import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.wallets.derivations.ColdMapDerivationsRepository
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
import io.mockk.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
@ -51,15 +52,21 @@ internal class DefaultDerivationsRepositoryTest {
@Test
fun `error if userWalletId not found`() = runTest {
val currencies = MockCryptoCurrencyFactory(defaultUserWallet).ethereum.let(::listOf)
coEvery { userWalletsListRepository.getSyncStrict(defaultUserWalletId) } throws IllegalStateException()
val userWalletsFlow = MutableStateFlow<List<UserWallet>?>(null)
every { userWalletsListRepository.userWallets } returns userWalletsFlow
runCatching {
repository.derivePublicKeys(userWalletId = defaultUserWalletId, currencies = currencies)
}
.onSuccess { error("Should throws exception") }
.onFailure { Truth.assertThat(it).isInstanceOf(IllegalStateException::class.java) }
.onFailure {
Truth.assertThat(it).isInstanceOf(IllegalArgumentException::class.java)
Truth.assertThat(it).hasMessageThat()
.isEqualTo("Unable to find user wallet with provided ID: $defaultUserWalletId")
}
coVerify(exactly = 1) { userWalletsListRepository.getSyncStrict(defaultUserWalletId) }
coVerify(exactly = 1) { userWalletsListRepository.userWallets }
coVerify(inverse = true) {
coldDerivationsRepository.derivePublicKeysByNetworks(any(), any())
userWalletsListRepository.saveWithoutLock(any(), any())
@ -71,7 +78,7 @@ internal class DefaultDerivationsRepositoryTest {
repository.derivePublicKeys(userWalletId = defaultUserWalletId, currencies = emptyList())
coVerify(inverse = true) {
userWalletsListRepository.getSyncStrict(any())
userWalletsListRepository.userWallets
coldDerivationsRepository.derivePublicKeysByNetworks(any(), any())
userWalletsListRepository.saveWithoutLock(any(), any())
}
@ -80,8 +87,10 @@ internal class DefaultDerivationsRepositoryTest {
@Test
fun `error if coldDerivationsRepository throws exception`() = runTest {
val currencies = MockCryptoCurrencyFactory(defaultUserWallet).ethereum.let(::listOf)
val userWalletsFlow = MutableStateFlow(listOf(defaultUserWallet))
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery { userWalletsListRepository.getSyncStrict(defaultUserWalletId) } returns defaultUserWallet
coEvery {
coldDerivationsRepository.derivePublicKeysByNetworks(
userWallet = defaultUserWallet,
@ -96,7 +105,7 @@ internal class DefaultDerivationsRepositoryTest {
.onFailure { Truth.assertThat(it).isInstanceOf(IllegalStateException::class.java) }
coVerifyOrder {
userWalletsListRepository.getSyncStrict(defaultUserWalletId)
userWalletsListRepository.userWallets
coldDerivationsRepository.derivePublicKeysByNetworks(
userWallet = defaultUserWallet,
networks = currencies.map(CryptoCurrency.Coin::network),
@ -109,9 +118,11 @@ internal class DefaultDerivationsRepositoryTest {
@Test
fun `success case`() = runTest {
val currencies = MockCryptoCurrencyFactory(defaultUserWallet).ethereum.let(::listOf)
val userWalletsFlow = MutableStateFlow(listOf(defaultUserWallet))
val updatedWallet = defaultUserWallet.copy(cardsInWallet = setOf("AC01"))
coEvery { userWalletsListRepository.getSyncStrict(defaultUserWalletId) } returns defaultUserWallet
every { userWalletsListRepository.userWallets } returns userWalletsFlow
coEvery {
coldDerivationsRepository.derivePublicKeysByNetworks(
userWallet = defaultUserWallet,
@ -125,7 +136,7 @@ internal class DefaultDerivationsRepositoryTest {
repository.derivePublicKeys(userWalletId = defaultUserWalletId, currencies = currencies)
coVerifyOrder {
userWalletsListRepository.getSyncStrict(defaultUserWalletId)
userWalletsListRepository.userWallets
coldDerivationsRepository.derivePublicKeysByNetworks(
userWallet = defaultUserWallet,
networks = currencies.map(CryptoCurrency.Coin::network),

View file

@ -5,6 +5,7 @@ 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.common.wallets.loadAndGet
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.isMultiCurrency
import kotlinx.coroutines.ExperimentalCoroutinesApi

View file

@ -10,7 +10,7 @@ import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.models.wallet.isMultiCurrency
import io.mockk.*
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flowOf
@ -25,7 +25,7 @@ import org.junit.jupiter.api.TestInstance
class IsAccountsModeEnabledUseCaseTest {
private val accountsCRUDRepository: AccountsCRUDRepository = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk(relaxUnitFun = true)
private val featureToggles: AccountsFeatureToggles = mockk()
private val useCase = IsAccountsModeEnabledUseCase(
@ -55,27 +55,10 @@ class IsAccountsModeEnabledUseCaseTest {
Truth.assertThat(actual).isFalse()
verify(exactly = 1) { featureToggles.isFeatureEnabled }
verify(inverse = true) { userWalletsListRepository.loadAndGet() }
}
@Test
fun `returns false when loadAndGet emits empty flow`() = runTest {
// Arrange
every { featureToggles.isFeatureEnabled } returns true
every { userWalletsListRepository.loadAndGet() } returns emptyFlow()
// Act
val actual = useCase.invoke().firstOrNull()
// Assert
Truth.assertThat(actual).isFalse()
verifyOrder {
featureToggles.isFeatureEnabled
userWalletsListRepository.loadAndGet()
coVerify(inverse = true) {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
}
verify(inverse = true) { accountsCRUDRepository.getTotalActiveAccountsCount(any()) }
}
@Test
@ -84,7 +67,7 @@ class IsAccountsModeEnabledUseCaseTest {
val wallet = createUserWallet(isMultiCurrency = false)
every { featureToggles.isFeatureEnabled } returns true
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet))
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(wallet))
// Act
val actual = useCase.invoke().first()
@ -92,9 +75,10 @@ class IsAccountsModeEnabledUseCaseTest {
// Assert
Truth.assertThat(actual).isFalse()
verifyOrder {
coVerifyOrder {
featureToggles.isFeatureEnabled
userWalletsListRepository.loadAndGet()
userWalletsListRepository.load()
userWalletsListRepository.userWallets
}
verify(inverse = true) { accountsCRUDRepository.getTotalActiveAccountsCount(any()) }
@ -106,7 +90,7 @@ class IsAccountsModeEnabledUseCaseTest {
val wallet = createUserWallet(isMultiCurrency = true)
every { featureToggles.isFeatureEnabled } returns true
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet))
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(wallet))
every { accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId) } returns flowOf(2.some())
// Act
@ -115,9 +99,10 @@ class IsAccountsModeEnabledUseCaseTest {
// Assert
Truth.assertThat(actual).isTrue()
verifyOrder {
coVerifyOrder {
featureToggles.isFeatureEnabled
userWalletsListRepository.loadAndGet()
userWalletsListRepository.load()
userWalletsListRepository.userWallets
accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId)
}
}
@ -128,7 +113,7 @@ class IsAccountsModeEnabledUseCaseTest {
val wallet = createUserWallet(isMultiCurrency = true)
every { featureToggles.isFeatureEnabled } returns true
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet))
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(wallet))
every { accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId) } returns flowOf(none())
// Act
@ -137,9 +122,10 @@ class IsAccountsModeEnabledUseCaseTest {
// Assert
Truth.assertThat(actual).isFalse()
verifyOrder {
coVerifyOrder {
featureToggles.isFeatureEnabled
userWalletsListRepository.loadAndGet()
userWalletsListRepository.load()
userWalletsListRepository.userWallets
accountsCRUDRepository.getTotalActiveAccountsCount(wallet.walletId)
}
}
@ -151,7 +137,7 @@ class IsAccountsModeEnabledUseCaseTest {
val wallet2 = createUserWallet(isMultiCurrency = true)
every { featureToggles.isFeatureEnabled } returns true
every { userWalletsListRepository.loadAndGet() } returns flowOf(listOf(wallet1, wallet2))
every { userWalletsListRepository.userWallets } returns MutableStateFlow(listOf(wallet1, wallet2))
every { accountsCRUDRepository.getTotalActiveAccountsCount(wallet2.walletId) } returns flowOf(2.some())
// Act
@ -160,9 +146,10 @@ class IsAccountsModeEnabledUseCaseTest {
// Assert
Truth.assertThat(actual).isTrue()
verifyOrder {
coVerifyOrder {
featureToggles.isFeatureEnabled
userWalletsListRepository.loadAndGet()
userWalletsListRepository.load()
userWalletsListRepository.userWallets
accountsCRUDRepository.getTotalActiveAccountsCount(wallet2.walletId)
}

View file

@ -5,6 +5,7 @@ import arrow.core.some
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.loadAndGet
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.assisted.Assisted

View file

@ -9,6 +9,7 @@ import com.tangem.domain.account.models.AccountList
import com.tangem.domain.account.models.AccountStatusList
import com.tangem.domain.account.supplier.SingleAccountListSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.core.flow.FlowProducerTools
import com.tangem.domain.core.utils.lceContent
import com.tangem.domain.core.utils.lceLoading

View file

@ -4,6 +4,7 @@ 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.common.wallets.getSyncStrict
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.tokens.GetCryptoCurrencyActionsUseCase

View file

@ -9,7 +9,10 @@ import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.test.core.getEmittedValues
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
import io.mockk.*
import io.mockk.clearMocks
import io.mockk.coVerifySequence
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
@ -21,7 +24,7 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class DefaultMultiAccountStatusListProducerTest {
private val userWalletsListRepository: UserWalletsListRepository = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk(relaxUnitFun = true)
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier = mockk()
private val dispatchers = TestingCoroutineDispatcherProvider()
private val flowProducerTools: FlowProducerTools = mockk()
@ -55,7 +58,7 @@ class DefaultMultiAccountStatusListProducerTest {
val wallets = listOf(userWallet1, userWallet2)
val walletsFlow = MutableStateFlow(wallets)
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
every { userWalletsListRepository.userWallets } returns walletsFlow
val accountStatusList1 = mockk<AccountStatusList>()
val accountStatusList2 = mockk<AccountStatusList>()
@ -78,8 +81,9 @@ class DefaultMultiAccountStatusListProducerTest {
val expected = listOf(accountStatusList1, accountStatusList2)
Truth.assertThat(actual).containsExactly(expected)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
singleAccountStatusListSupplier(
params = SingleAccountStatusListProducer.Params(userWalletId1),
)
@ -93,7 +97,7 @@ class DefaultMultiAccountStatusListProducerTest {
fun `produce returns empty flow if userWallets is empty list`() = runTest {
// Arrange
val walletsFlow = MutableStateFlow<List<UserWallet>>(emptyList())
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
every { userWalletsListRepository.userWallets } returns walletsFlow
// Act
val actual = producer.produce().let(::getEmittedValues)
@ -101,16 +105,17 @@ class DefaultMultiAccountStatusListProducerTest {
// Assert
Truth.assertThat(actual).isEmpty()
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
}
}
@Test
fun `produce returns empty flow if userWallets is null`() = runTest {
// Arrange
val walletsFlow = flowOf<List<UserWallet>>(emptyList())
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
val walletsFlow = MutableStateFlow<List<UserWallet>>(emptyList())
every { userWalletsListRepository.userWallets } returns walletsFlow
// Act
val actual = producer.produce().let(::getEmittedValues)
@ -118,8 +123,9 @@ class DefaultMultiAccountStatusListProducerTest {
// Assert
Truth.assertThat(actual).isEmpty()
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
}
}
@ -130,7 +136,7 @@ class DefaultMultiAccountStatusListProducerTest {
val userWallet3 = mockk<UserWallet> { every { walletId } returns userWalletId3 }
val walletsFlow = MutableStateFlow(listOf(userWallet1, userWallet2))
every { userWalletsListRepository.loadAndGet() } returns walletsFlow
every { userWalletsListRepository.userWallets } returns walletsFlow
val accountStatusList1 = mockk<AccountStatusList>()
val accountStatusList2 = mockk<AccountStatusList>()
@ -169,8 +175,9 @@ class DefaultMultiAccountStatusListProducerTest {
val expected2 = listOf(accountStatusList1, accountStatusList2, accountStatusList3)
Truth.assertThat(actual2).containsExactly(expected2)
coVerify(ordering = Ordering.SEQUENCE) {
userWalletsListRepository.loadAndGet()
coVerifySequence {
userWalletsListRepository.load()
userWalletsListRepository.userWallets
singleAccountStatusListSupplier(
params = SingleAccountStatusListProducer.Params(userWalletId1),
)
@ -186,7 +193,8 @@ class DefaultMultiAccountStatusListProducerTest {
singleAccountStatusListSupplier(
params = SingleAccountStatusListProducer.Params(userWalletId3),
)
userWalletsListRepository.loadAndGet()
userWalletsListRepository.load()
userWalletsListRepository.userWallets
singleAccountStatusListSupplier(
params = SingleAccountStatusListProducer.Params(userWalletId1),
)

View file

@ -5,7 +5,6 @@ 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
/**
@ -31,21 +30,12 @@ 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.
*/

View file

@ -5,6 +5,8 @@ import arrow.core.raise.either
import com.tangem.domain.common.wallets.error.SaveWalletError
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
/**
* Update user wallet by [userWalletId] and return updated wallet.
@ -29,4 +31,22 @@ suspend fun UserWalletsListRepository.update(
.bind()
updatedUserWallet
}
/** Get user wallet by [id] */
fun UserWalletsListRepository.getSyncOrNull(id: UserWalletId): UserWallet? {
return userWallets.value?.find { it.walletId == id }
}
/** Get user wallet by [id] or throw an exception if it is not found */
fun UserWalletsListRepository.getSyncStrict(id: UserWalletId): UserWallet {
return requireNotNull(getSyncOrNull(id)) { "Unable to find user wallet with provided ID: $id" }
}
/** Loads user wallets list and selected wallet and returns a flow of the list */
fun UserWalletsListRepository.loadAndGet(): Flow<List<UserWallet>> = flow {
load()
userWallets.collect {
emit(requireNotNull(it))
}
}

View file

@ -9,6 +9,7 @@ import com.tangem.datasource.api.common.response.getOrThrow
import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.api.tangemTech.models.StartReferralBody
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWalletId