From b6fad30af95c395aa0e68493f8b7c7a2f3b424e1 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 21 Aug 2025 13:35:17 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../domain/account/models/AccountList.kt | 35 ++++- .../usecase/AddCryptoPortfolioUseCase.kt | 17 +-- .../usecase/RecoverCryptoPortfolioUseCase.kt | 12 +- .../usecase/UpdateCryptoPortfolioUseCase.kt | 2 +- .../domain/account/models/AccountListTest.kt | 2 +- .../usecase/AddCryptoPortfolioUseCaseTest.kt | 10 +- .../ArchiveCryptoPortfolioUseCaseTest.kt | 6 +- .../GetUnoccupiedAccountIndexUseCaseTest.kt | 4 +- .../RecoverCryptoPortfolioUseCaseTest.kt | 12 +- .../UpdateCryptoPortfolioUseCaseTest.kt | 4 +- .../tangem/domain/account/utils/AccountExt.kt | 11 +- .../tangem/domain/models/account/Account.kt | 123 +++++++----------- .../domain/models/account/AccountTest.kt | 37 ++---- .../archived/ArchivedAccountListModel.kt | 2 +- .../createedit/AccountCreateEditModel.kt | 4 +- .../entity/AccountCreateEditUMBuilder.kt | 2 +- .../account/details/AccountDetailsModel.kt | 2 +- 17 files changed, 126 insertions(+), 159 deletions(-) diff --git a/domain/account/src/main/java/com/tangem/domain/account/models/AccountList.kt b/domain/account/src/main/java/com/tangem/domain/account/models/AccountList.kt index 319babf91b..89f7fd33c8 100644 --- a/domain/account/src/main/java/com/tangem/domain/account/models/AccountList.kt +++ b/domain/account/src/main/java/com/tangem/domain/account/models/AccountList.kt @@ -3,7 +3,10 @@ package com.tangem.domain.account.models import arrow.core.Either import arrow.core.raise.either import arrow.core.raise.ensure +import com.tangem.domain.models.TokensGroupType +import com.tangem.domain.models.TokensSortType import com.tangem.domain.models.account.Account +import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.wallet.UserWallet import com.tangem.utils.extensions.addOrReplace import kotlinx.serialization.Serializable @@ -22,6 +25,8 @@ data class AccountList private constructor( val userWallet: UserWallet, val accounts: Set, val totalAccounts: Int, + val sortType: TokensSortType, + val groupType: TokensGroupType, ) { /** Retrieves the main crypto portfolio account from the list of accounts */ @@ -48,6 +53,8 @@ data class AccountList private constructor( userWallet = this.userWallet, accounts = accounts, totalAccounts = this.totalAccounts + if (isNewAccount) 1 else 0, + sortType = this.sortType, + groupType = this.groupType, ) } @@ -68,6 +75,8 @@ data class AccountList private constructor( userWallet = this.userWallet, accounts = accounts, totalAccounts = this.totalAccounts - if (isExistingAccount) 1 else 0, + sortType = this.sortType, + groupType = this.groupType, ) } @@ -132,6 +141,8 @@ data class AccountList private constructor( userWallet: UserWallet, accounts: Set, totalAccounts: Int, + sortType: TokensSortType = TokensSortType.NONE, + groupType: TokensGroupType = TokensGroupType.NONE, ): Either = either { ensure(accounts.isNotEmpty()) { Error.EmptyAccountsList } @@ -149,10 +160,16 @@ data class AccountList private constructor( val uniqueAccountIdsCount = accounts.map { it.accountId.value }.distinct().size ensure(accounts.size == uniqueAccountIdsCount) { Error.DuplicateAccountIds } - val uniqueAccountNameCount = accounts.map { it.name.value }.distinct().size + val uniqueAccountNameCount = accounts.map { it.accountName.value }.distinct().size ensure(accounts.size == uniqueAccountNameCount) { Error.DuplicateAccountNames } - AccountList(userWallet = userWallet, accounts = accounts, totalAccounts = totalAccounts) + AccountList( + userWallet = userWallet, + accounts = accounts, + totalAccounts = totalAccounts, + sortType = sortType, + groupType = groupType, + ) } /** @@ -160,13 +177,23 @@ data class AccountList private constructor( * * @param userWallet the user wallet associated with the account list */ - fun empty(userWallet: UserWallet): AccountList { + fun empty( + userWallet: UserWallet, + cryptoCurrencies: Set = emptySet(), + sortType: TokensSortType = TokensSortType.NONE, + groupType: TokensGroupType = TokensGroupType.NONE, + ): AccountList { return AccountList( userWallet = userWallet, accounts = setOf( - Account.CryptoPortfolio.createMainAccount(userWalletId = userWallet.walletId), + Account.CryptoPortfolio.createMainAccount( + userWalletId = userWallet.walletId, + cryptoCurrencies = cryptoCurrencies, + ), ), totalAccounts = 1, + sortType = sortType, + groupType = groupType, ) } diff --git a/domain/account/src/main/java/com/tangem/domain/account/usecase/AddCryptoPortfolioUseCase.kt b/domain/account/src/main/java/com/tangem/domain/account/usecase/AddCryptoPortfolioUseCase.kt index 75722f9824..6a3866bc4b 100644 --- a/domain/account/src/main/java/com/tangem/domain/account/usecase/AddCryptoPortfolioUseCase.kt +++ b/domain/account/src/main/java/com/tangem/domain/account/usecase/AddCryptoPortfolioUseCase.kt @@ -64,14 +64,9 @@ class AddCryptoPortfolioUseCase( return Account.CryptoPortfolio( accountId = AccountId.forCryptoPortfolio(userWalletId = userWalletId, derivationIndex = derivationIndex), accountName = accountName, - accountIcon = icon, + icon = icon, derivationIndex = derivationIndex, - isArchived = false, - cryptoCurrencyList = Account.CryptoPortfolio.CryptoCurrencyList( - currencies = emptySet(), - sortType = TokensSortType.NONE, - groupType = TokensGroupType.NONE, - ), + cryptoCurrencies = emptySet(), ) } @@ -88,7 +83,13 @@ class AddCryptoPortfolioUseCase( catch = { raise(Error.DataOperationFailed(cause = it)) }, ) - return AccountList.empty(userWallet = userWallet) + // TODO: [REDACTED_JIRA] + return AccountList.empty( + userWallet = userWallet, + cryptoCurrencies = emptySet(), + sortType = TokensSortType.NONE, + groupType = TokensGroupType.NONE, + ) } private suspend fun Raise.saveAccounts(accountList: AccountList) { diff --git a/domain/account/src/main/java/com/tangem/domain/account/usecase/RecoverCryptoPortfolioUseCase.kt b/domain/account/src/main/java/com/tangem/domain/account/usecase/RecoverCryptoPortfolioUseCase.kt index 9679a036b6..f5dcec41aa 100644 --- a/domain/account/src/main/java/com/tangem/domain/account/usecase/RecoverCryptoPortfolioUseCase.kt +++ b/domain/account/src/main/java/com/tangem/domain/account/usecase/RecoverCryptoPortfolioUseCase.kt @@ -8,8 +8,6 @@ import arrow.core.raise.either import com.tangem.domain.account.models.AccountList import com.tangem.domain.account.models.ArchivedAccount import com.tangem.domain.account.repository.AccountsCRUDRepository -import com.tangem.domain.models.TokensGroupType -import com.tangem.domain.models.TokensSortType import com.tangem.domain.models.account.Account import com.tangem.domain.models.account.AccountId import com.tangem.domain.models.wallet.UserWalletId @@ -66,14 +64,10 @@ class RecoverCryptoPortfolioUseCase( return Account.CryptoPortfolio( accountId = this.accountId, accountName = this.name, - accountIcon = this.icon, + icon = this.icon, derivationIndex = this.derivationIndex, - isArchived = false, - cryptoCurrencyList = Account.CryptoPortfolio.CryptoCurrencyList( - currencies = emptySet(), - sortType = TokensSortType.NONE, - groupType = TokensGroupType.NONE, - ), + // TODO: [REDACTED_JIRA] + cryptoCurrencies = emptySet(), ) } diff --git a/domain/account/src/main/java/com/tangem/domain/account/usecase/UpdateCryptoPortfolioUseCase.kt b/domain/account/src/main/java/com/tangem/domain/account/usecase/UpdateCryptoPortfolioUseCase.kt index 8c2208e552..4451a5f50d 100644 --- a/domain/account/src/main/java/com/tangem/domain/account/usecase/UpdateCryptoPortfolioUseCase.kt +++ b/domain/account/src/main/java/com/tangem/domain/account/usecase/UpdateCryptoPortfolioUseCase.kt @@ -79,7 +79,7 @@ class UpdateCryptoPortfolioUseCase( } private fun Account.CryptoPortfolio.setIcon(icon: CryptoPortfolioIcon?): Account.CryptoPortfolio { - return if (icon != null) this.copy(accountIcon = icon) else this + return if (icon != null) this.copy(icon = icon) else this } /** diff --git a/domain/account/src/test/kotlin/com/tangem/domain/account/models/AccountListTest.kt b/domain/account/src/test/kotlin/com/tangem/domain/account/models/AccountListTest.kt index d5323c0a85..0c43198fa0 100644 --- a/domain/account/src/test/kotlin/com/tangem/domain/account/models/AccountListTest.kt +++ b/domain/account/src/test/kotlin/com/tangem/domain/account/models/AccountListTest.kt @@ -123,7 +123,7 @@ class AccountListTest { accounts = setOf( Account.CryptoPortfolio.createMainAccount(userWalletId), Account.CryptoPortfolio.createMainAccount(userWalletId).copy( - accountIcon = CryptoPortfolioIcon.ofDefaultCustomAccount(), + icon = CryptoPortfolioIcon.ofDefaultCustomAccount(), ), ), expected = AccountList.Error.ExceedsMaxMainAccountsCount.left(), diff --git a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/AddCryptoPortfolioUseCaseTest.kt b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/AddCryptoPortfolioUseCaseTest.kt index cf47f9b807..f30bc1dfda 100644 --- a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/AddCryptoPortfolioUseCaseTest.kt +++ b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/AddCryptoPortfolioUseCaseTest.kt @@ -46,7 +46,7 @@ class AddCryptoPortfolioUseCaseTest { // Act val actual = useCase( userWalletId = userWalletId, - accountName = newAccount.name, + accountName = newAccount.accountName, icon = newAccount.icon, derivationIndex = newAccount.derivationIndex, ) @@ -75,7 +75,7 @@ class AddCryptoPortfolioUseCaseTest { // Act val actual = useCase( userWalletId = userWalletId, - accountName = newAccount.name, + accountName = newAccount.accountName, icon = newAccount.icon, derivationIndex = newAccount.derivationIndex, ) @@ -107,7 +107,7 @@ class AddCryptoPortfolioUseCaseTest { // Act val actual = useCase( userWalletId = userWalletId, - accountName = newAccount.name, + accountName = newAccount.accountName, icon = newAccount.icon, derivationIndex = newAccount.derivationIndex, ) @@ -138,7 +138,7 @@ class AddCryptoPortfolioUseCaseTest { // Act val actual = useCase( userWalletId = userWalletId, - accountName = newAccount.name, + accountName = newAccount.accountName, icon = newAccount.icon, derivationIndex = newAccount.derivationIndex, ) @@ -170,7 +170,7 @@ class AddCryptoPortfolioUseCaseTest { // Act val actual = useCase( userWalletId = userWalletId, - accountName = newAccount.name, + accountName = newAccount.accountName, icon = newAccount.icon, derivationIndex = newAccount.derivationIndex, ) diff --git a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/ArchiveCryptoPortfolioUseCaseTest.kt b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/ArchiveCryptoPortfolioUseCaseTest.kt index aaea0a5379..1e442938fa 100644 --- a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/ArchiveCryptoPortfolioUseCaseTest.kt +++ b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/ArchiveCryptoPortfolioUseCaseTest.kt @@ -39,8 +39,7 @@ class ArchiveCryptoPortfolioUseCaseTest { val accountList = (AccountList.empty(userWallet) + account).getOrNull()!! val accountId = account.accountId - val archivedAccount = account.copy(isArchived = true) - val updatedAccountList = (accountList - archivedAccount).getOrNull()!! + val updatedAccountList = (accountList - account).getOrNull()!! coEvery { crudRepository.getAccounts(userWalletId) } returns accountList.toOption() @@ -130,8 +129,7 @@ class ArchiveCryptoPortfolioUseCaseTest { val accountList = (AccountList.empty(userWallet) + account).getOrNull()!! val accountId = account.accountId - val archivedAccount = account.copy(isArchived = true) - val updatedAccountList = (accountList - archivedAccount).getOrNull()!! + val updatedAccountList = (accountList - account).getOrNull()!! val exception = IllegalStateException("Save failed") diff --git a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/GetUnoccupiedAccountIndexUseCaseTest.kt b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/GetUnoccupiedAccountIndexUseCaseTest.kt index ec8af7f2b7..4c994aeb21 100644 --- a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/GetUnoccupiedAccountIndexUseCaseTest.kt +++ b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/GetUnoccupiedAccountIndexUseCaseTest.kt @@ -1,9 +1,9 @@ package com.tangem.domain.account.usecase import arrow.core.left -import arrow.core.right import com.google.common.truth.Truth import com.tangem.domain.account.repository.AccountsCRUDRepository +import com.tangem.domain.models.account.DerivationIndex import com.tangem.domain.models.wallet.UserWalletId import io.mockk.clearMocks import io.mockk.coEvery @@ -35,7 +35,7 @@ class GetUnoccupiedAccountIndexUseCaseTest { val actual = useCase(userWalletId = userWalletId) // Assert - val expected = 4.right() + val expected = DerivationIndex(4) Truth.assertThat(actual).isEqualTo(expected) coVerify { crudRepository.getTotalAccountsCount(userWalletId) } diff --git a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/RecoverCryptoPortfolioUseCaseTest.kt b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/RecoverCryptoPortfolioUseCaseTest.kt index 316e789754..7c8f1a847f 100644 --- a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/RecoverCryptoPortfolioUseCaseTest.kt +++ b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/RecoverCryptoPortfolioUseCaseTest.kt @@ -43,15 +43,14 @@ class RecoverCryptoPortfolioUseCaseTest { val accountList = AccountList.empty(userWallet) val archivedAccount = ArchivedAccount( accountId = account.accountId, - name = account.name, + name = account.accountName, icon = account.icon, derivationIndex = account.derivationIndex, tokensCount = 1, networksCount = 1, ) - val recoveredAccount = account.copy(isArchived = false) - val updatedAccountList = (accountList + recoveredAccount).getOrNull()!! + val updatedAccountList = (accountList + account).getOrNull()!! coEvery { crudRepository.getAccounts(userWalletId) } returns accountList.toOption() coEvery { crudRepository.getArchivedAccount(account.accountId) } returns archivedAccount.toOption() @@ -60,7 +59,7 @@ class RecoverCryptoPortfolioUseCaseTest { val actual = useCase(account.accountId) // Assert - val expected = recoveredAccount.right() + val expected = account.right() Truth.assertThat(actual).isEqualTo(expected) coVerifyOrder { @@ -173,15 +172,14 @@ class RecoverCryptoPortfolioUseCaseTest { val accountList = AccountList.empty(userWallet) val archivedAccount = ArchivedAccount( accountId = account.accountId, - name = account.name, + name = account.accountName, icon = account.icon, derivationIndex = account.derivationIndex, tokensCount = 1, networksCount = 1, ) - val recoveredAccount = account.copy(isArchived = false) - val updatedAccountList = (accountList + recoveredAccount).getOrNull()!! + val updatedAccountList = (accountList + account).getOrNull()!! val exception = IllegalStateException("Save failed") coEvery { crudRepository.getAccounts(userWalletId) } returns accountList.toOption() diff --git a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/UpdateCryptoPortfolioUseCaseTest.kt b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/UpdateCryptoPortfolioUseCaseTest.kt index d6638b5c05..f1ba896a7c 100644 --- a/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/UpdateCryptoPortfolioUseCaseTest.kt +++ b/domain/account/src/test/kotlin/com/tangem/domain/account/usecase/UpdateCryptoPortfolioUseCaseTest.kt @@ -73,7 +73,7 @@ class UpdateCryptoPortfolioUseCaseTest { value = CryptoPortfolioIcon.Icon.Star, color = CryptoPortfolioIcon.Color.CaribbeanBlue, ) - val updatedAccount = accountList.mainAccount.copy(accountIcon = newAccountIcon) + val updatedAccount = accountList.mainAccount.copy(icon = newAccountIcon) val updatedAccountList = (accountList + updatedAccount).getOrNull()!! coEvery { crudRepository.getAccounts(userWalletId = userWalletId) } returns accountList.toOption() @@ -102,7 +102,7 @@ class UpdateCryptoPortfolioUseCaseTest { value = CryptoPortfolioIcon.Icon.Star, color = CryptoPortfolioIcon.Color.CaribbeanBlue, ) - val updatedAccount = accountList.mainAccount.copy(accountName = newAccountName, accountIcon = newAccountIcon) + val updatedAccount = accountList.mainAccount.copy(accountName = newAccountName, icon = newAccountIcon) val updatedAccountList = (accountList + updatedAccount).getOrNull()!! coEvery { crudRepository.getAccounts(userWalletId = userWalletId) } returns accountList.toOption() diff --git a/domain/account/src/test/kotlin/com/tangem/domain/account/utils/AccountExt.kt b/domain/account/src/test/kotlin/com/tangem/domain/account/utils/AccountExt.kt index 597d6aa059..9f452c4145 100644 --- a/domain/account/src/test/kotlin/com/tangem/domain/account/utils/AccountExt.kt +++ b/domain/account/src/test/kotlin/com/tangem/domain/account/utils/AccountExt.kt @@ -1,7 +1,5 @@ package com.tangem.domain.account.utils -import com.tangem.domain.models.TokensGroupType -import com.tangem.domain.models.TokensSortType import com.tangem.domain.models.account.* import com.tangem.domain.models.wallet.UserWalletId import kotlin.random.Random @@ -33,13 +31,8 @@ fun createAccount( return Account.CryptoPortfolio( accountId = AccountId.forCryptoPortfolio(userWalletId = userWalletId, derivationIndex = derivationIndex), accountName = AccountName(name).getOrNull()!!, - accountIcon = icon, + icon = icon, derivationIndex = derivationIndex, - isArchived = false, - cryptoCurrencyList = Account.CryptoPortfolio.CryptoCurrencyList( - currencies = emptySet(), - sortType = TokensSortType.NONE, - groupType = TokensGroupType.NONE, - ), + cryptoCurrencies = emptySet(), ) } \ No newline at end of file diff --git a/domain/models/src/main/kotlin/com/tangem/domain/models/account/Account.kt b/domain/models/src/main/kotlin/com/tangem/domain/models/account/Account.kt index db4a5b164c..b376be0db1 100644 --- a/domain/models/src/main/kotlin/com/tangem/domain/models/account/Account.kt +++ b/domain/models/src/main/kotlin/com/tangem/domain/models/account/Account.kt @@ -1,9 +1,8 @@ package com.tangem.domain.models.account import arrow.core.Either +import arrow.core.getOrElse import arrow.core.raise.either -import com.tangem.domain.models.TokensGroupType -import com.tangem.domain.models.TokensSortType import com.tangem.domain.models.account.Account.CryptoPortfolio.Error.AccountNameError import com.tangem.domain.models.account.Account.CryptoPortfolio.Error.DerivationIndexError import com.tangem.domain.models.currency.CryptoCurrency @@ -22,7 +21,7 @@ sealed interface Account { val accountId: AccountId /** Name of the account */ - val name: AccountName + val accountName: AccountName /** The identifier of the user wallet associated with the account */ val userWalletId: UserWalletId @@ -31,21 +30,19 @@ sealed interface Account { /** * Represents a crypto portfolio account * - * @property accountId unique identifier of the account - * @property name name of the account - * @property icon icon representing the account - * @property derivationIndex index used for derivation of the account - * @property isArchived indicates whether the account is archived - * @property cryptoCurrencyList list of tokens associated with the account + * @property accountId unique identifier of the account + * @property accountName name of the account + * @property icon icon representing the account + * @property derivationIndex index used for derivation of the account + * @property cryptoCurrencies set of tokens associated with the account */ @Serializable data class CryptoPortfolio private constructor( override val accountId: AccountId, - override val name: AccountName, + override val accountName: AccountName, val icon: CryptoPortfolioIcon, val derivationIndex: DerivationIndex, - val isArchived: Boolean, - val cryptoCurrencyList: CryptoCurrencyList, + val cryptoCurrencies: Set, ) : Account { /** Indicates if the account is the main account */ @@ -54,41 +51,22 @@ sealed interface Account { /** Number of tokens in the account */ val tokensCount: Int - get() = cryptoCurrencyList.currencies.size + get() = cryptoCurrencies.size /** Number of distinct networks in the account */ val networksCount: Int - get() = cryptoCurrencyList.currencies.map(CryptoCurrency::network).distinct().size + get() = cryptoCurrencies.map(CryptoCurrency::network).distinct().size - fun copy( - accountName: AccountName = this.name, - accountIcon: CryptoPortfolioIcon = this.icon, - isArchived: Boolean = this.isArchived, - ): CryptoPortfolio { + fun copy(accountName: AccountName = this.accountName, icon: CryptoPortfolioIcon = this.icon): CryptoPortfolio { return CryptoPortfolio( accountId = this.accountId, - name = accountName, - icon = accountIcon, + accountName = accountName, + icon = icon, derivationIndex = this.derivationIndex, - isArchived = isArchived, - cryptoCurrencyList = this.cryptoCurrencyList, + cryptoCurrencies = this.cryptoCurrencies, ) } - /** - * Represents a list of tokens in the account - * - * @property currencies set of cryptocurrencies in the account - * @property sortType sorting type for the tokens - * @property groupType grouping type for the tokens - */ - @Serializable - data class CryptoCurrencyList( - val currencies: Set, - val sortType: TokensSortType, - val groupType: TokensGroupType, - ) - /** * Represents possible errors when creating a crypto portfolio account */ @@ -109,33 +87,34 @@ sealed interface Account { /** * Constructor for creating a [CryptoPortfolio] instance * - * @param accountId unique identifier of the account - * @param name name of the account - * @param accountIcon icon representing the account - * @param derivationIndex index used for derivation of the account - * @param isArchived indicates whether the account is archived - * @param cryptoCurrencyList list of tokens associated with the account + * @param accountId unique identifier of the account + * @param name name of the account + * @param icon icon representing the account + * @param derivationIndex index used for derivation of the account + * @param cryptoCurrencies set of tokens associated with the account */ - @Suppress("LongParameterList") operator fun invoke( accountId: AccountId, name: String, - accountIcon: CryptoPortfolioIcon, + icon: CryptoPortfolioIcon, derivationIndex: Int, - isArchived: Boolean, - cryptoCurrencyList: CryptoCurrencyList, + cryptoCurrencies: Set = emptySet(), ): Either { return either { - val accountName = AccountName(value = name).mapLeft(::AccountNameError).bind() - val derivationIndex = DerivationIndex(derivationIndex).mapLeft(::DerivationIndexError).bind() + val accountName = AccountName(value = name).getOrElse { + raise(AccountNameError(cause = it)) + } + + val derivationIndex = DerivationIndex(value = derivationIndex).getOrElse { + raise(DerivationIndexError(cause = it)) + } invoke( accountId = accountId, accountName = accountName, - accountIcon = accountIcon, + icon = icon, derivationIndex = derivationIndex, - isArchived = isArchived, - cryptoCurrencyList = cryptoCurrencyList, + cryptoCurrencies = cryptoCurrencies, ) } } @@ -143,38 +122,39 @@ sealed interface Account { /** * Constructor for creating a [CryptoPortfolio] instance * - * @param accountId unique identifier of the account - * @param accountName name of the account - * @param accountIcon icon representing the account - * @param derivationIndex index used for derivation of the account - * @param isArchived indicates whether the account is archived - * @param cryptoCurrencyList list of tokens associated with the account + * @param accountId unique identifier of the account + * @param accountName name of the account + * @param icon icon representing the account + * @param derivationIndex index used for derivation of the account + * @param cryptoCurrencies set of tokens associated with the account */ @Suppress("LongParameterList") operator fun invoke( accountId: AccountId, accountName: AccountName, - accountIcon: CryptoPortfolioIcon, + icon: CryptoPortfolioIcon, derivationIndex: DerivationIndex, - isArchived: Boolean, - cryptoCurrencyList: CryptoCurrencyList, + cryptoCurrencies: Set = emptySet(), ): CryptoPortfolio { return CryptoPortfolio( accountId = accountId, - name = accountName, - icon = accountIcon, + accountName = accountName, + icon = icon, derivationIndex = derivationIndex, - isArchived = isArchived, - cryptoCurrencyList = cryptoCurrencyList, + cryptoCurrencies = cryptoCurrencies, ) } /** * Creates a main account for the given user wallet ID * - * @param userWalletId the ID of the user wallet + * @param userWalletId the ID of the user wallet + * @param cryptoCurrencies set of tokens associated with the account */ - fun createMainAccount(userWalletId: UserWalletId): CryptoPortfolio { + fun createMainAccount( + userWalletId: UserWalletId, + cryptoCurrencies: Set = emptySet(), + ): CryptoPortfolio { val derivationIndex = DerivationIndex.Main return CryptoPortfolio( @@ -182,15 +162,10 @@ sealed interface Account { userWalletId = userWalletId, derivationIndex = derivationIndex, ), - name = AccountName.Main, + accountName = AccountName.Main, icon = CryptoPortfolioIcon.ofMainAccount(userWalletId), derivationIndex = derivationIndex, - isArchived = false, - cryptoCurrencyList = CryptoCurrencyList( - currencies = emptySet(), - sortType = TokensSortType.NONE, - groupType = TokensGroupType.NONE, - ), + cryptoCurrencies = cryptoCurrencies, ) } } diff --git a/domain/models/src/test/kotlin/com/tangem/domain/models/account/AccountTest.kt b/domain/models/src/test/kotlin/com/tangem/domain/models/account/AccountTest.kt index eabb287672..91baaf2a76 100644 --- a/domain/models/src/test/kotlin/com/tangem/domain/models/account/AccountTest.kt +++ b/domain/models/src/test/kotlin/com/tangem/domain/models/account/AccountTest.kt @@ -1,10 +1,7 @@ package com.tangem.domain.models.account import com.google.common.truth.Truth -import com.tangem.domain.models.TokensGroupType -import com.tangem.domain.models.TokensSortType import com.tangem.domain.models.account.Account.CryptoPortfolio -import com.tangem.domain.models.account.Account.CryptoPortfolio.CryptoCurrencyList import com.tangem.domain.models.account.Account.CryptoPortfolio.Error.AccountNameError import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.wallet.UserWalletId @@ -100,13 +97,12 @@ class AccountTest { val name = "" // Act - val actual = CryptoPortfolio( + val actual = CryptoPortfolio.invoke( accountId = mockk(), name = name, - accountIcon = mockk(), + icon = mockk(), derivationIndex = 0, - isArchived = false, - cryptoCurrencyList = mockk(), + cryptoCurrencies = emptySet(), ) .leftOrNull()!! @@ -125,14 +121,9 @@ class AccountTest { derivationIndex = derivationIndex, ), name = "Test Account", - accountIcon = CryptoPortfolioIcon.ofMainAccount(userWalletId = UserWalletId("011")), + icon = CryptoPortfolioIcon.ofMainAccount(userWalletId = UserWalletId("011")), derivationIndex = derivationIndex.value, - isArchived = false, - cryptoCurrencyList = CryptoCurrencyList( - currencies = emptySet(), - sortType = TokensSortType.NONE, - groupType = TokensGroupType.NONE, - ), + cryptoCurrencies = emptySet(), ) .getOrNull()!! @@ -157,14 +148,9 @@ class AccountTest { derivationIndex = derivationIndex, ), accountName = AccountName.Main, - accountIcon = CryptoPortfolioIcon.ofMainAccount(userWalletId), + icon = CryptoPortfolioIcon.ofMainAccount(userWalletId), derivationIndex = derivationIndex, - isArchived = false, - cryptoCurrencyList = CryptoCurrencyList( - currencies = emptySet(), - sortType = TokensSortType.NONE, - groupType = TokensGroupType.NONE, - ), + cryptoCurrencies = emptySet(), ) Truth.assertThat(actual).isEqualTo(expected) @@ -182,14 +168,9 @@ class AccountTest { return CryptoPortfolio.invoke( accountId = AccountId.forCryptoPortfolio(userWalletId = userWalletId, derivationIndex = accountIndex), name = name, - accountIcon = CryptoPortfolioIcon.ofMainAccount(userWalletId), + icon = CryptoPortfolioIcon.ofMainAccount(userWalletId), derivationIndex = derivationIndex, - isArchived = false, - cryptoCurrencyList = CryptoCurrencyList( - currencies = currencies, - sortType = TokensSortType.NONE, - groupType = TokensGroupType.NONE, - ), + cryptoCurrencies = currencies, ) .getOrNull()!! } diff --git a/features/account/impl/src/main/java/com/tangem/features/account/archived/ArchivedAccountListModel.kt b/features/account/impl/src/main/java/com/tangem/features/account/archived/ArchivedAccountListModel.kt index 3c2aed7f6b..a93cdcca2b 100644 --- a/features/account/impl/src/main/java/com/tangem/features/account/archived/ArchivedAccountListModel.kt +++ b/features/account/impl/src/main/java/com/tangem/features/account/archived/ArchivedAccountListModel.kt @@ -48,7 +48,7 @@ internal class ArchivedAccountListModel @Inject constructor( ) messageSender.send( DialogMessage( - title = stringReference(account.name.value), + title = stringReference(account.accountName.value), message = TextReference.EMPTY, firstActionBuilder = { firstAction }, secondActionBuilder = { secondAction }, diff --git a/features/account/impl/src/main/java/com/tangem/features/account/createedit/AccountCreateEditModel.kt b/features/account/impl/src/main/java/com/tangem/features/account/createedit/AccountCreateEditModel.kt index af1c7d4ed1..5c61ebc3f4 100644 --- a/features/account/impl/src/main/java/com/tangem/features/account/createedit/AccountCreateEditModel.kt +++ b/features/account/impl/src/main/java/com/tangem/features/account/createedit/AccountCreateEditModel.kt @@ -109,7 +109,7 @@ internal class AccountCreateEditModel @Inject constructor( val state = uiState.value val name = AccountName(state.account.name).getOrNull() ?: return val icon = state.account.portfolioIcon.toDomain() - val isNewName = name != params.account.name + val isNewName = name != params.account.accountName val isNewIcon = icon != params.account.portfolioIcon updateCryptoPortfolioUseCase( icon = if (isNewIcon) icon else null, @@ -143,7 +143,7 @@ internal class AccountCreateEditModel @Inject constructor( val isAvailableForConfirm = when (params) { is AccountCreateEditComponent.Params.Create -> isValidName is AccountCreateEditComponent.Params.Edit -> { - val isNewName = this.account.name != params.account.name.value + val isNewName = this.account.name != params.account.accountName.value val isNewIcon = this.account.portfolioIcon != params.account.portfolioIcon isValidName && (isNewName || isNewIcon) } diff --git a/features/account/impl/src/main/java/com/tangem/features/account/createedit/entity/AccountCreateEditUMBuilder.kt b/features/account/impl/src/main/java/com/tangem/features/account/createedit/entity/AccountCreateEditUMBuilder.kt index 654515e302..24b69681c9 100644 --- a/features/account/impl/src/main/java/com/tangem/features/account/createedit/entity/AccountCreateEditUMBuilder.kt +++ b/features/account/impl/src/main/java/com/tangem/features/account/createedit/entity/AccountCreateEditUMBuilder.kt @@ -34,7 +34,7 @@ internal class AccountCreateEditUMBuilder( onNameChange = onNameChange, ) is AccountCreateEditComponent.Params.Edit -> AccountCreateEditUM.Account( - name = params.account.name.value, + name = params.account.accountName.value, portfolioIcon = params.account.portfolioIcon.toUM(), derivationInfo = createAccountDerivationInfo( index = (params.account as Account.CryptoPortfolio).derivationIndex.value, diff --git a/features/account/impl/src/main/java/com/tangem/features/account/details/AccountDetailsModel.kt b/features/account/impl/src/main/java/com/tangem/features/account/details/AccountDetailsModel.kt index d6fc77713e..0e40b6b39d 100644 --- a/features/account/impl/src/main/java/com/tangem/features/account/details/AccountDetailsModel.kt +++ b/features/account/impl/src/main/java/com/tangem/features/account/details/AccountDetailsModel.kt @@ -74,7 +74,7 @@ internal class AccountDetailsModel @Inject constructor( private fun getInitialState(): AccountDetailsUM { return AccountDetailsUM( - accountName = params.account.name.value, + accountName = params.account.accountName.value, accountIcon = params.account.portfolioIcon.toUM(), onCloseClick = { router.pop() }, onAccountEditClick = ::onEditAccountClick,