Updated on 2026-08-14
This commit is contained in:
parent
71507af6c3
commit
589805424e
9 changed files with 129 additions and 66 deletions
|
|
@ -41,8 +41,8 @@ data class AccountList private constructor(
|
|||
get() = accounts.first { it is Account.CryptoPortfolio && it.isMainAccount } as Account.CryptoPortfolio
|
||||
|
||||
/** Returns true if more accounts can be added (the maximum number of accounts has not been reached) */
|
||||
val canAddMoreAccounts: Boolean
|
||||
get() = accounts.size < MAX_ACCOUNTS_COUNT
|
||||
val canAddMoreCryptoAccounts: Boolean
|
||||
get() = accounts.filterIsInstance<Account.CryptoPortfolio>().size < MAX_CRYPTO_PORTFOLIO_ACCOUNTS_COUNT
|
||||
|
||||
/** Returns the number of active accounts in the list */
|
||||
val activeAccounts: Int
|
||||
|
|
@ -151,6 +151,11 @@ data class AccountList private constructor(
|
|||
override fun toString(): String = "$tag: The number of accounts must not exceed 20"
|
||||
}
|
||||
|
||||
data object ExceedsMaxPaymentAccountsCount : Error {
|
||||
override fun toString(): String =
|
||||
"$tag: The number of payment accounts must not exceed $MAX_PAYMENT_ACCOUNTS_COUNT"
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data object DuplicateAccountIds : Error {
|
||||
override fun toString(): String = "$tag: Account list contains duplicate account IDs"
|
||||
|
|
@ -169,7 +174,8 @@ data class AccountList private constructor(
|
|||
|
||||
companion object {
|
||||
|
||||
const val MAX_ACCOUNTS_COUNT = 20
|
||||
const val MAX_PAYMENT_ACCOUNTS_COUNT = 1
|
||||
const val MAX_CRYPTO_PORTFOLIO_ACCOUNTS_COUNT = 20
|
||||
const val MAX_ARCHIVED_ACCOUNTS_COUNT = 1000
|
||||
private const val MAX_MAIN_ACCOUNTS_COUNT = 1
|
||||
|
||||
|
|
@ -191,7 +197,11 @@ data class AccountList private constructor(
|
|||
): Either<Error, AccountList> = either {
|
||||
ensure(accounts.isNotEmpty()) { Error.EmptyAccountsList }
|
||||
|
||||
ensure(accounts.size <= MAX_ACCOUNTS_COUNT) { Error.ExceedsMaxAccountsCount }
|
||||
val paymentAccounts = accounts.filterIsInstance<Account.Payment>()
|
||||
ensure(paymentAccounts.size <= MAX_PAYMENT_ACCOUNTS_COUNT) { Error.ExceedsMaxPaymentAccountsCount }
|
||||
|
||||
val cryptoAccounts = accounts.filterIsInstance<Account.CryptoPortfolio>()
|
||||
ensure(cryptoAccounts.size <= MAX_CRYPTO_PORTFOLIO_ACCOUNTS_COUNT) { Error.ExceedsMaxAccountsCount }
|
||||
|
||||
val mainAccountsCount = accounts.mainAccountsCount()
|
||||
ensure(mainAccountsCount == MAX_MAIN_ACCOUNTS_COUNT) {
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ internal class AccountListTest {
|
|||
val fullAccountList = MockAccounts.fullAccountList
|
||||
|
||||
// Act & Assert
|
||||
Truth.assertThat(accountList.canAddMoreAccounts).isTrue()
|
||||
Truth.assertThat(fullAccountList.canAddMoreAccounts).isFalse()
|
||||
Truth.assertThat(accountList.canAddMoreCryptoAccounts).isTrue()
|
||||
Truth.assertThat(fullAccountList.canAddMoreCryptoAccounts).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class RecoverCryptoPortfolioUseCase(
|
|||
|
||||
val accountList = getAccountList(userWalletId = accountId.userWalletId)
|
||||
|
||||
ensure(accountList.canAddMoreAccounts) {
|
||||
ensure(accountList.canAddMoreCryptoAccounts) {
|
||||
raise(Error.AccountListRequirementsNotMet(cause = AccountList.Error.ExceedsMaxAccountsCount))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue