Updated on 2026-08-14
This commit is contained in:
parent
fae450669c
commit
b6fad30af9
17 changed files with 126 additions and 159 deletions
|
|
@ -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<Account>,
|
||||
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<Account>,
|
||||
totalAccounts: Int,
|
||||
sortType: TokensSortType = TokensSortType.NONE,
|
||||
groupType: TokensGroupType = TokensGroupType.NONE,
|
||||
): Either<Error, AccountList> = 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<CryptoCurrency> = 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,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Error>.saveAccounts(accountList: AccountList) {
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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) }
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
)
|
||||
}
|
||||
|
|
@ -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<CryptoCurrency>,
|
||||
) : 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<CryptoCurrency>,
|
||||
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<CryptoCurrency> = emptySet(),
|
||||
): Either<Error, CryptoPortfolio> {
|
||||
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<CryptoCurrency> = 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<CryptoCurrency> = 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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()!!
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue