Updated on 2026-08-14
This commit is contained in:
parent
207dbeed3c
commit
0ae9e75e90
16 changed files with 55 additions and 60 deletions
|
|
@ -37,9 +37,9 @@ internal class CryptoPortfolioConverter @AssistedInject constructor(
|
||||||
tokens = tokens,
|
tokens = tokens,
|
||||||
userWallet = userWallet,
|
userWallet = userWallet,
|
||||||
accountIndex = value.derivationIndex.toDerivationIndex(),
|
accountIndex = value.derivationIndex.toDerivationIndex(),
|
||||||
).toSet()
|
)
|
||||||
} else {
|
} else {
|
||||||
emptySet()
|
emptyList()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,9 @@ internal class WalletAccountListFlowFactory @Inject constructor(
|
||||||
val isSingleWalletWithToken = userWallet.requireColdWallet().cardTypesResolver.isSingleWalletWithToken()
|
val isSingleWalletWithToken = userWallet.requireColdWallet().cardTypesResolver.isSingleWalletWithToken()
|
||||||
|
|
||||||
val currencies = if (isSingleWalletWithToken) {
|
val currencies = if (isSingleWalletWithToken) {
|
||||||
cardCryptoCurrencyFactory.createCurrenciesForSingleCurrencyCardWithToken(userWallet = userWallet).toSet()
|
cardCryptoCurrencyFactory.createCurrenciesForSingleCurrencyCardWithToken(userWallet = userWallet)
|
||||||
} else {
|
} else {
|
||||||
setOf(cardCryptoCurrencyFactory.createPrimaryCurrencyForSingleCurrencyCard(userWallet = userWallet))
|
listOf(cardCryptoCurrencyFactory.createPrimaryCurrencyForSingleCurrencyCard(userWallet = userWallet))
|
||||||
}
|
}
|
||||||
|
|
||||||
return AccountList.empty(userWalletId = userWallet.walletId, cryptoCurrencies = currencies)
|
return AccountList.empty(userWalletId = userWallet.walletId, cryptoCurrencies = currencies)
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ class WalletAccountListFlowFactoryTest {
|
||||||
val actual = factory.create(userWallet.walletId).let(::getEmittedValues)
|
val actual = factory.create(userWallet.walletId).let(::getEmittedValues)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
val expected = AccountList.empty(userWalletId = userWallet.walletId, cryptoCurrencies = setOf(currency))
|
val expected = AccountList.empty(userWalletId = userWallet.walletId, cryptoCurrencies = listOf(currency))
|
||||||
Truth.assertThat(actual).containsExactly(expected)
|
Truth.assertThat(actual).containsExactly(expected)
|
||||||
|
|
||||||
coVerifySequence {
|
coVerifySequence {
|
||||||
|
|
@ -144,7 +144,7 @@ class WalletAccountListFlowFactoryTest {
|
||||||
|
|
||||||
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
every { userWalletsListRepository.userWallets } returns userWalletsFlow
|
||||||
|
|
||||||
val currencies = cryptoCurrencyFactory.ethereumAndStellar.toSet()
|
val currencies = cryptoCurrencyFactory.ethereumAndStellar
|
||||||
every {
|
every {
|
||||||
cardCryptoCurrencyFactory.createCurrenciesForSingleCurrencyCardWithToken(userWallet = nodl)
|
cardCryptoCurrencyFactory.createCurrenciesForSingleCurrencyCardWithToken(userWallet = nodl)
|
||||||
} returns currencies.toList()
|
} returns currencies.toList()
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ data class AccountList private constructor(
|
||||||
*/
|
*/
|
||||||
fun empty(
|
fun empty(
|
||||||
userWalletId: UserWalletId,
|
userWalletId: UserWalletId,
|
||||||
cryptoCurrencies: Set<CryptoCurrency> = emptySet(),
|
cryptoCurrencies: List<CryptoCurrency> = emptyList(),
|
||||||
sortType: TokensSortType = TokensSortType.NONE,
|
sortType: TokensSortType = TokensSortType.NONE,
|
||||||
groupType: TokensGroupType = TokensGroupType.NONE,
|
groupType: TokensGroupType = TokensGroupType.NONE,
|
||||||
): AccountList {
|
): AccountList {
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ class AddCryptoPortfolioUseCase(
|
||||||
accountName = accountName,
|
accountName = accountName,
|
||||||
icon = icon,
|
icon = icon,
|
||||||
derivationIndex = derivationIndex,
|
derivationIndex = derivationIndex,
|
||||||
cryptoCurrencies = emptySet(),
|
cryptoCurrencies = emptyList(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,6 @@ import com.tangem.domain.models.currency.CryptoCurrency
|
||||||
import com.tangem.domain.models.wallet.UserWalletId
|
import com.tangem.domain.models.wallet.UserWalletId
|
||||||
import com.tangem.domain.tokens.error.TokenListSortingError
|
import com.tangem.domain.tokens.error.TokenListSortingError
|
||||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.awaitAll
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
|
|
@ -137,7 +135,6 @@ class ApplyTokenListSortingUseCaseV2(
|
||||||
errors[account.accountId] = it
|
errors[account.accountId] = it
|
||||||
return@map account
|
return@map account
|
||||||
}
|
}
|
||||||
.toSet()
|
|
||||||
|
|
||||||
account.copy(cryptoCurrencies = accountCurrencies)
|
account.copy(cryptoCurrencies = accountCurrencies)
|
||||||
}
|
}
|
||||||
|
|
@ -171,17 +168,13 @@ class ApplyTokenListSortingUseCaseV2(
|
||||||
|
|
||||||
private suspend fun Raise<TokenListSortingError>.applySorting(accountList: AccountList) {
|
private suspend fun Raise<TokenListSortingError>.applySorting(accountList: AccountList) {
|
||||||
coroutineScope {
|
coroutineScope {
|
||||||
val results = awaitAll(
|
val results = Either.catch {
|
||||||
async {
|
accountsCRUDRepository.saveAccountsLocally(accountList)
|
||||||
Either.catch { accountsCRUDRepository.saveAccountsLocally(accountList) }
|
accountsCRUDRepository.syncTokens(accountList.userWalletId)
|
||||||
},
|
}
|
||||||
async {
|
|
||||||
Either.catch { accountsCRUDRepository.syncTokens(accountList.userWalletId) }
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
ensure(results.none { it.isLeft() }) {
|
ensure(results.isRight()) {
|
||||||
val message = results.mapNotNull { it.leftOrNull() }.joinToString()
|
val message = results.leftOrNull()
|
||||||
raise(TokenListSortingError.DataError(IllegalStateException(message)))
|
raise(TokenListSortingError.DataError(IllegalStateException(message)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class ManageCryptoCurrenciesUseCase(
|
||||||
}
|
}
|
||||||
|
|
||||||
saveAccount(
|
saveAccount(
|
||||||
account = accountStatus.account.copy(cryptoCurrencies = modifiedCurrencyList.total.toSet()),
|
account = accountStatus.account.copy(cryptoCurrencies = modifiedCurrencyList.total),
|
||||||
)
|
)
|
||||||
|
|
||||||
derivePublicKeys(userWalletId = userWalletId, currencies = modifiedCurrencyList.added)
|
derivePublicKeys(userWalletId = userWalletId, currencies = modifiedCurrencyList.added)
|
||||||
|
|
@ -126,7 +126,7 @@ class ManageCryptoCurrenciesUseCase(
|
||||||
val modifiedCurrencyList = accountStatus.tokenList.flattenCurrencies()
|
val modifiedCurrencyList = accountStatus.tokenList.flattenCurrencies()
|
||||||
.modify(add = listOf(tokenToAdd))
|
.modify(add = listOf(tokenToAdd))
|
||||||
|
|
||||||
saveAccount(account = accountStatus.account.copy(cryptoCurrencies = modifiedCurrencyList.total.toSet()))
|
saveAccount(account = accountStatus.account.copy(cryptoCurrencies = modifiedCurrencyList.total))
|
||||||
|
|
||||||
parallelUpdatingScope.launch {
|
parallelUpdatingScope.launch {
|
||||||
syncTokens(userWalletId, modifiedCurrencyList)
|
syncTokens(userWalletId, modifiedCurrencyList)
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ class RecoverCryptoPortfolioUseCase(
|
||||||
accountName = this.name,
|
accountName = this.name,
|
||||||
icon = this.icon,
|
icon = this.icon,
|
||||||
derivationIndex = this.derivationIndex,
|
derivationIndex = this.derivationIndex,
|
||||||
cryptoCurrencies = emptySet(),
|
cryptoCurrencies = emptyList(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ internal class ApplyTokenListSortingUseCaseTest {
|
||||||
@Test
|
@Test
|
||||||
fun `when getAccountListSync throws exception then error should be received`() = runTest {
|
fun `when getAccountListSync throws exception then error should be received`() = runTest {
|
||||||
// Arrange
|
// Arrange
|
||||||
val accountList = AccountList.empty(userWalletId = userWalletId, cryptoCurrencies = emptySet())
|
val accountList = AccountList.empty(userWalletId = userWalletId, cryptoCurrencies = emptyList())
|
||||||
|
|
||||||
val exception = IllegalStateException("No internet connection")
|
val exception = IllegalStateException("No internet connection")
|
||||||
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } throws exception
|
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } throws exception
|
||||||
|
|
@ -92,7 +92,7 @@ internal class ApplyTokenListSortingUseCaseTest {
|
||||||
@Test
|
@Test
|
||||||
fun `when saveAccountsLocally throws exception then error should be received`() = runTest {
|
fun `when saveAccountsLocally throws exception then error should be received`() = runTest {
|
||||||
// Arrange
|
// Arrange
|
||||||
val accountList = AccountList.empty(userWalletId = userWalletId, cryptoCurrencies = emptySet())
|
val accountList = AccountList.empty(userWalletId = userWalletId, cryptoCurrencies = emptyList())
|
||||||
|
|
||||||
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
||||||
|
|
||||||
|
|
@ -114,14 +114,16 @@ internal class ApplyTokenListSortingUseCaseTest {
|
||||||
coVerifyOrder {
|
coVerifyOrder {
|
||||||
accountsCRUDRepository.getAccountListSync(userWalletId)
|
accountsCRUDRepository.getAccountListSync(userWalletId)
|
||||||
accountsCRUDRepository.saveAccountsLocally(accountList)
|
accountsCRUDRepository.saveAccountsLocally(accountList)
|
||||||
accountsCRUDRepository.syncTokens(userWalletId = userWalletId)
|
}
|
||||||
|
coVerifyOrder(inverse = true) {
|
||||||
|
accountsCRUDRepository.syncTokens(userWalletId = any())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when syncTokens throws exception then error should be received`() = runTest {
|
fun `when syncTokens throws exception then error should be received`() = runTest {
|
||||||
// Arrange
|
// Arrange
|
||||||
val accountList = AccountList.empty(userWalletId = userWalletId, cryptoCurrencies = emptySet())
|
val accountList = AccountList.empty(userWalletId = userWalletId, cryptoCurrencies = emptyList())
|
||||||
|
|
||||||
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
||||||
|
|
||||||
|
|
@ -156,13 +158,13 @@ internal class ApplyTokenListSortingUseCaseTest {
|
||||||
|
|
||||||
val accountList = AccountList.empty(
|
val accountList = AccountList.empty(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
cryptoCurrencies = setOf(token1, token2, token3),
|
cryptoCurrencies = listOf(token1, token2, token3),
|
||||||
sortType = TokensSortType.NONE,
|
sortType = TokensSortType.NONE,
|
||||||
groupType = TokensGroupType.NONE,
|
groupType = TokensGroupType.NONE,
|
||||||
)
|
)
|
||||||
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
||||||
|
|
||||||
val sortedTokens = setOf(token2, token3, token1)
|
val sortedTokens = listOf(token2, token3, token1)
|
||||||
val updatedAccountList = AccountList.empty(
|
val updatedAccountList = AccountList.empty(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
cryptoCurrencies = sortedTokens,
|
cryptoCurrencies = sortedTokens,
|
||||||
|
|
@ -197,13 +199,13 @@ internal class ApplyTokenListSortingUseCaseTest {
|
||||||
|
|
||||||
val accountList = AccountList.empty(
|
val accountList = AccountList.empty(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
cryptoCurrencies = setOf(token1, token2, token3),
|
cryptoCurrencies = listOf(token1, token2, token3),
|
||||||
sortType = TokensSortType.NONE,
|
sortType = TokensSortType.NONE,
|
||||||
groupType = TokensGroupType.NONE,
|
groupType = TokensGroupType.NONE,
|
||||||
)
|
)
|
||||||
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
||||||
|
|
||||||
val sortedTokens = setOf(token2, token3, token1)
|
val sortedTokens = listOf(token2, token3, token1)
|
||||||
val updatedAccountList = AccountList.empty(
|
val updatedAccountList = AccountList.empty(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
cryptoCurrencies = sortedTokens,
|
cryptoCurrencies = sortedTokens,
|
||||||
|
|
@ -238,13 +240,13 @@ internal class ApplyTokenListSortingUseCaseTest {
|
||||||
|
|
||||||
val accountList = AccountList.empty(
|
val accountList = AccountList.empty(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
cryptoCurrencies = setOf(token1, token2, token3),
|
cryptoCurrencies = listOf(token1, token2, token3),
|
||||||
sortType = TokensSortType.NONE,
|
sortType = TokensSortType.NONE,
|
||||||
groupType = TokensGroupType.NONE,
|
groupType = TokensGroupType.NONE,
|
||||||
)
|
)
|
||||||
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
||||||
|
|
||||||
val sortedTokens = setOf(token2, token3, token1)
|
val sortedTokens = listOf(token2, token3, token1)
|
||||||
val updatedAccountList = AccountList.empty(
|
val updatedAccountList = AccountList.empty(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
cryptoCurrencies = sortedTokens,
|
cryptoCurrencies = sortedTokens,
|
||||||
|
|
@ -279,13 +281,13 @@ internal class ApplyTokenListSortingUseCaseTest {
|
||||||
|
|
||||||
val accountList = AccountList.empty(
|
val accountList = AccountList.empty(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
cryptoCurrencies = setOf(token1, token2, token3),
|
cryptoCurrencies = listOf(token1, token2, token3),
|
||||||
sortType = TokensSortType.BALANCE,
|
sortType = TokensSortType.BALANCE,
|
||||||
groupType = TokensGroupType.NETWORK,
|
groupType = TokensGroupType.NETWORK,
|
||||||
)
|
)
|
||||||
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
coEvery { accountsCRUDRepository.getAccountListSync(userWalletId) } returns accountList.some()
|
||||||
|
|
||||||
val sortedTokens = setOf(token2, token3, token1)
|
val sortedTokens = listOf(token2, token3, token1)
|
||||||
val updatedAccountList = AccountList.empty(
|
val updatedAccountList = AccountList.empty(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
cryptoCurrencies = sortedTokens,
|
cryptoCurrencies = sortedTokens,
|
||||||
|
|
@ -323,13 +325,13 @@ internal class ApplyTokenListSortingUseCaseTest {
|
||||||
name = "Account 1",
|
name = "Account 1",
|
||||||
icon = CryptoPortfolioIcon.ofDefaultCustomAccount(),
|
icon = CryptoPortfolioIcon.ofDefaultCustomAccount(),
|
||||||
derivationIndex = 1,
|
derivationIndex = 1,
|
||||||
cryptoCurrencies = setOf(token1, token2, token3),
|
cryptoCurrencies = listOf(token1, token2, token3),
|
||||||
)
|
)
|
||||||
.getOrNull()!!
|
.getOrNull()!!
|
||||||
|
|
||||||
val accountList = (AccountList.empty(
|
val accountList = (AccountList.empty(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
cryptoCurrencies = setOf(token1, token2, token3),
|
cryptoCurrencies = listOf(token1, token2, token3),
|
||||||
sortType = TokensSortType.NONE,
|
sortType = TokensSortType.NONE,
|
||||||
groupType = TokensGroupType.NONE,
|
groupType = TokensGroupType.NONE,
|
||||||
) + customAccount).getOrNull()!!
|
) + customAccount).getOrNull()!!
|
||||||
|
|
@ -344,7 +346,7 @@ internal class ApplyTokenListSortingUseCaseTest {
|
||||||
val updatedAccountList = AccountList(
|
val updatedAccountList = AccountList(
|
||||||
userWalletId = userWalletId,
|
userWalletId = userWalletId,
|
||||||
accounts = listOf(
|
accounts = listOf(
|
||||||
accountList.mainAccount.copy(cryptoCurrencies = setOf(token3, token2, token1)),
|
accountList.mainAccount.copy(cryptoCurrencies = listOf(token3, token2, token1)),
|
||||||
customAccount, // unchanged due to error
|
customAccount, // unchanged due to error
|
||||||
),
|
),
|
||||||
totalAccounts = accountList.totalAccounts,
|
totalAccounts = accountList.totalAccounts,
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ class GetAccountCurrencyByAddressUseCaseTest {
|
||||||
network = currency.network,
|
network = currency.network,
|
||||||
value = NetworkStatus.Unreachable(address = validNetworkAddress),
|
value = NetworkStatus.Unreachable(address = validNetworkAddress),
|
||||||
)
|
)
|
||||||
val accountList = AccountList.empty(userWalletId = userWalletId, cryptoCurrencies = setOf(currency))
|
val accountList = AccountList.empty(userWalletId = userWalletId, cryptoCurrencies = listOf(currency))
|
||||||
|
|
||||||
every { userWalletsListRepository.userWallets.value } returns listOf(multiUserWallet)
|
every { userWalletsListRepository.userWallets.value } returns listOf(multiUserWallet)
|
||||||
coEvery {
|
coEvery {
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ class GetAccountCurrencyStatusUseCaseTest {
|
||||||
|
|
||||||
val account = mockk<Account.CryptoPortfolio>(relaxed = true) {
|
val account = mockk<Account.CryptoPortfolio>(relaxed = true) {
|
||||||
every { this@mockk.derivationIndex } returns DerivationIndex(1).getOrNull()!!
|
every { this@mockk.derivationIndex } returns DerivationIndex(1).getOrNull()!!
|
||||||
every { this@mockk.cryptoCurrencies } returns setOf(currency)
|
every { this@mockk.cryptoCurrencies } returns listOf(currency)
|
||||||
}
|
}
|
||||||
val currencyStatus = CryptoCurrencyStatus(currency = currency, value = CryptoCurrencyStatus.Loading)
|
val currencyStatus = CryptoCurrencyStatus(currency = currency, value = CryptoCurrencyStatus.Loading)
|
||||||
val accountStatus = AccountStatus.CryptoPortfolio(
|
val accountStatus = AccountStatus.CryptoPortfolio(
|
||||||
|
|
@ -140,7 +140,7 @@ class GetAccountCurrencyStatusUseCaseTest {
|
||||||
fun `invokeSync returns Some if network is null`() = runTest {
|
fun `invokeSync returns Some if network is null`() = runTest {
|
||||||
// Arrange
|
// Arrange
|
||||||
val account = mockk<Account.CryptoPortfolio>(relaxed = true) {
|
val account = mockk<Account.CryptoPortfolio>(relaxed = true) {
|
||||||
every { this@mockk.cryptoCurrencies } returns setOf(currency)
|
every { this@mockk.cryptoCurrencies } returns listOf(currency)
|
||||||
}
|
}
|
||||||
val currencyStatus = CryptoCurrencyStatus(currency = currency, value = CryptoCurrencyStatus.Loading)
|
val currencyStatus = CryptoCurrencyStatus(currency = currency, value = CryptoCurrencyStatus.Loading)
|
||||||
val accountStatus = AccountStatus.CryptoPortfolio(
|
val accountStatus = AccountStatus.CryptoPortfolio(
|
||||||
|
|
@ -223,7 +223,7 @@ class GetAccountCurrencyStatusUseCaseTest {
|
||||||
|
|
||||||
val account = mockk<Account.CryptoPortfolio>(relaxed = true) {
|
val account = mockk<Account.CryptoPortfolio>(relaxed = true) {
|
||||||
every { this@mockk.derivationIndex } returns DerivationIndex(1).getOrNull()!!
|
every { this@mockk.derivationIndex } returns DerivationIndex(1).getOrNull()!!
|
||||||
every { this@mockk.cryptoCurrencies } returns setOf(currency)
|
every { this@mockk.cryptoCurrencies } returns listOf(currency)
|
||||||
}
|
}
|
||||||
val currencyStatus = CryptoCurrencyStatus(currency = currency, value = CryptoCurrencyStatus.Loading)
|
val currencyStatus = CryptoCurrencyStatus(currency = currency, value = CryptoCurrencyStatus.Loading)
|
||||||
val accountStatus = AccountStatus.CryptoPortfolio(
|
val accountStatus = AccountStatus.CryptoPortfolio(
|
||||||
|
|
@ -257,7 +257,7 @@ class GetAccountCurrencyStatusUseCaseTest {
|
||||||
fun `invoke returns data if network is null`() = runTest {
|
fun `invoke returns data if network is null`() = runTest {
|
||||||
// Arrange
|
// Arrange
|
||||||
val account = mockk<Account.CryptoPortfolio>(relaxed = true) {
|
val account = mockk<Account.CryptoPortfolio>(relaxed = true) {
|
||||||
every { this@mockk.cryptoCurrencies } returns setOf(currency)
|
every { this@mockk.cryptoCurrencies } returns listOf(currency)
|
||||||
}
|
}
|
||||||
val currencyStatus = CryptoCurrencyStatus(currency = currency, value = CryptoCurrencyStatus.Loading)
|
val currencyStatus = CryptoCurrencyStatus(currency = currency, value = CryptoCurrencyStatus.Loading)
|
||||||
val accountStatus = AccountStatus.CryptoPortfolio(
|
val accountStatus = AccountStatus.CryptoPortfolio(
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,7 @@ class RecoverCryptoPortfolioUseCaseTest {
|
||||||
accountName = AccountName(name).getOrNull()!!,
|
accountName = AccountName(name).getOrNull()!!,
|
||||||
icon = icon,
|
icon = icon,
|
||||||
derivationIndex = derivationIndex,
|
derivationIndex = derivationIndex,
|
||||||
cryptoCurrencies = emptySet(),
|
cryptoCurrencies = emptyList(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ sealed interface Account {
|
||||||
override val accountName: AccountName,
|
override val accountName: AccountName,
|
||||||
val icon: CryptoPortfolioIcon,
|
val icon: CryptoPortfolioIcon,
|
||||||
val derivationIndex: DerivationIndex,
|
val derivationIndex: DerivationIndex,
|
||||||
val cryptoCurrencies: Set<CryptoCurrency>,
|
val cryptoCurrencies: List<CryptoCurrency>,
|
||||||
) : Account {
|
) : Account {
|
||||||
|
|
||||||
/** Indicates if the account is the main account */
|
/** Indicates if the account is the main account */
|
||||||
|
|
@ -60,7 +60,7 @@ sealed interface Account {
|
||||||
fun copy(
|
fun copy(
|
||||||
accountName: AccountName = this.accountName,
|
accountName: AccountName = this.accountName,
|
||||||
icon: CryptoPortfolioIcon = this.icon,
|
icon: CryptoPortfolioIcon = this.icon,
|
||||||
cryptoCurrencies: Set<CryptoCurrency> = this.cryptoCurrencies,
|
cryptoCurrencies: List<CryptoCurrency> = this.cryptoCurrencies,
|
||||||
): CryptoPortfolio {
|
): CryptoPortfolio {
|
||||||
return CryptoPortfolio(
|
return CryptoPortfolio(
|
||||||
accountId = this.accountId,
|
accountId = this.accountId,
|
||||||
|
|
@ -102,7 +102,7 @@ sealed interface Account {
|
||||||
name: String,
|
name: String,
|
||||||
icon: CryptoPortfolioIcon,
|
icon: CryptoPortfolioIcon,
|
||||||
derivationIndex: Int,
|
derivationIndex: Int,
|
||||||
cryptoCurrencies: Set<CryptoCurrency> = emptySet(),
|
cryptoCurrencies: List<CryptoCurrency> = emptyList(),
|
||||||
): Either<Error, CryptoPortfolio> {
|
): Either<Error, CryptoPortfolio> {
|
||||||
return either {
|
return either {
|
||||||
val accountName = AccountName(value = name).getOrElse {
|
val accountName = AccountName(value = name).getOrElse {
|
||||||
|
|
@ -138,7 +138,7 @@ sealed interface Account {
|
||||||
accountName: AccountName,
|
accountName: AccountName,
|
||||||
icon: CryptoPortfolioIcon,
|
icon: CryptoPortfolioIcon,
|
||||||
derivationIndex: DerivationIndex,
|
derivationIndex: DerivationIndex,
|
||||||
cryptoCurrencies: Set<CryptoCurrency> = emptySet(),
|
cryptoCurrencies: List<CryptoCurrency> = emptyList(),
|
||||||
): CryptoPortfolio {
|
): CryptoPortfolio {
|
||||||
return CryptoPortfolio(
|
return CryptoPortfolio(
|
||||||
accountId = accountId,
|
accountId = accountId,
|
||||||
|
|
@ -157,7 +157,7 @@ sealed interface Account {
|
||||||
*/
|
*/
|
||||||
fun createMainAccount(
|
fun createMainAccount(
|
||||||
userWalletId: UserWalletId,
|
userWalletId: UserWalletId,
|
||||||
cryptoCurrencies: Set<CryptoCurrency> = emptySet(),
|
cryptoCurrencies: List<CryptoCurrency> = emptyList(),
|
||||||
): CryptoPortfolio {
|
): CryptoPortfolio {
|
||||||
val derivationIndex = DerivationIndex.Main
|
val derivationIndex = DerivationIndex.Main
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ class AccountTest {
|
||||||
@Test
|
@Test
|
||||||
fun `CryptoPortfolio tokensCount`() {
|
fun `CryptoPortfolio tokensCount`() {
|
||||||
// Arrange
|
// Arrange
|
||||||
val emptyCurrencies = emptySet<CryptoCurrency>()
|
val emptyCurrencies = emptyList<CryptoCurrency>()
|
||||||
val filledCurrencies = setOf(mockk<CryptoCurrency>())
|
val filledCurrencies = listOf(mockk<CryptoCurrency>())
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
val actual1 = createCryptoPortfolioStub(currencies = emptyCurrencies)
|
val actual1 = createCryptoPortfolioStub(currencies = emptyCurrencies)
|
||||||
|
|
@ -68,8 +68,8 @@ class AccountTest {
|
||||||
@Test
|
@Test
|
||||||
fun `CryptoPortfolio networksCount`() {
|
fun `CryptoPortfolio networksCount`() {
|
||||||
// Arrange
|
// Arrange
|
||||||
val emptyCurrencies = emptySet<CryptoCurrency>()
|
val emptyCurrencies = emptyList<CryptoCurrency>()
|
||||||
val filledCurrencies = setOf(
|
val filledCurrencies = listOf(
|
||||||
mockk<CryptoCurrency> {
|
mockk<CryptoCurrency> {
|
||||||
every { network } returns mockk()
|
every { network } returns mockk()
|
||||||
},
|
},
|
||||||
|
|
@ -102,7 +102,7 @@ class AccountTest {
|
||||||
name = name,
|
name = name,
|
||||||
icon = mockk(),
|
icon = mockk(),
|
||||||
derivationIndex = 0,
|
derivationIndex = 0,
|
||||||
cryptoCurrencies = emptySet(),
|
cryptoCurrencies = emptyList(),
|
||||||
)
|
)
|
||||||
.leftOrNull()!!
|
.leftOrNull()!!
|
||||||
|
|
||||||
|
|
@ -123,7 +123,7 @@ class AccountTest {
|
||||||
name = "Test Account",
|
name = "Test Account",
|
||||||
icon = CryptoPortfolioIcon.ofMainAccount(userWalletId = UserWalletId("011")),
|
icon = CryptoPortfolioIcon.ofMainAccount(userWalletId = UserWalletId("011")),
|
||||||
derivationIndex = derivationIndex.value,
|
derivationIndex = derivationIndex.value,
|
||||||
cryptoCurrencies = emptySet(),
|
cryptoCurrencies = emptyList(),
|
||||||
)
|
)
|
||||||
.getOrNull()!!
|
.getOrNull()!!
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ class AccountTest {
|
||||||
accountName = AccountName.DefaultMain,
|
accountName = AccountName.DefaultMain,
|
||||||
icon = CryptoPortfolioIcon.ofMainAccount(userWalletId),
|
icon = CryptoPortfolioIcon.ofMainAccount(userWalletId),
|
||||||
derivationIndex = derivationIndex,
|
derivationIndex = derivationIndex,
|
||||||
cryptoCurrencies = emptySet(),
|
cryptoCurrencies = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
Truth.assertThat(actual).isEqualTo(expected)
|
Truth.assertThat(actual).isEqualTo(expected)
|
||||||
|
|
@ -161,7 +161,7 @@ class AccountTest {
|
||||||
userWalletId: UserWalletId = UserWalletId("011"),
|
userWalletId: UserWalletId = UserWalletId("011"),
|
||||||
name: String = "Test Account",
|
name: String = "Test Account",
|
||||||
derivationIndex: Int = 0,
|
derivationIndex: Int = 0,
|
||||||
currencies: Set<CryptoCurrency> = emptySet(),
|
currencies: List<CryptoCurrency> = emptyList(),
|
||||||
): CryptoPortfolio {
|
): CryptoPortfolio {
|
||||||
val accountIndex = DerivationIndex(value = derivationIndex).getOrNull()!!
|
val accountIndex = DerivationIndex(value = derivationIndex).getOrNull()!!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ internal class TesterAccountsViewModel @Inject constructor(
|
||||||
name = "Account #$nextIndex",
|
name = "Account #$nextIndex",
|
||||||
icon = CryptoPortfolioIcon.ofDefaultCustomAccount(),
|
icon = CryptoPortfolioIcon.ofDefaultCustomAccount(),
|
||||||
derivationIndex = nextIndex,
|
derivationIndex = nextIndex,
|
||||||
cryptoCurrencies = emptySet(),
|
cryptoCurrencies = emptyList(),
|
||||||
)
|
)
|
||||||
.getOrNull()
|
.getOrNull()
|
||||||
?: break
|
?: break
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ object MockAccounts {
|
||||||
derivationIndex: Int,
|
derivationIndex: Int,
|
||||||
name: String = "Account #$derivationIndex",
|
name: String = "Account #$derivationIndex",
|
||||||
icon: CryptoPortfolioIcon = CryptoPortfolioIcon.ofDefaultCustomAccount(),
|
icon: CryptoPortfolioIcon = CryptoPortfolioIcon.ofDefaultCustomAccount(),
|
||||||
cryptoCurrencies: Set<CryptoCurrency> = emptySet(),
|
cryptoCurrencies: List<CryptoCurrency> = emptyList(),
|
||||||
userWalletId: UserWalletId = this.userWalletId,
|
userWalletId: UserWalletId = this.userWalletId,
|
||||||
): Account.CryptoPortfolio {
|
): Account.CryptoPortfolio {
|
||||||
val derivationIndex = DerivationIndex(derivationIndex).getOrNull()!!
|
val derivationIndex = DerivationIndex(derivationIndex).getOrNull()!!
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue