From 23aac9041cf96a3ce517bc55b3ac8ce8173f0081 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 1 Aug 2023 14:31:41 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../tangem/data/tokens/mock/MockNetworks.kt | 2 + .../mapper/GetWalletTokenErrorMappers.kt | 1 + .../error/mapper/TokenListErrorMappers.kt | 1 + .../domain/tokens/model/CryptoCurrency.kt | 26 ++++++++++ .../tokens/model/CryptoCurrencyStatus.kt | 47 +++++++++++++++++++ .../com/tangem/domain/tokens/model/Network.kt | 13 +++++ .../domain/tokens/model/NetworkGroup.kt | 8 ++++ .../domain/tokens/model/NetworkStatus.kt | 39 ++++++++++++--- .../com/tangem/domain/tokens/model/Quote.kt | 7 +++ .../tangem/domain/tokens/model/TokenList.kt | 42 +++++++++++++++++ .../CurrenciesStatusesOperations.kt | 4 ++ .../operations/CurrencyStatusOperations.kt | 41 ++++++++-------- .../tokens/repository/NetworksRepository.kt | 14 ++++++ .../tokens/repository/QuotesRepository.kt | 7 +++ .../tokens/repository/TokensRepository.kt | 34 ++++++++++++++ .../tangem/domain/tokens/mock/MockNetworks.kt | 3 ++ 16 files changed, 263 insertions(+), 26 deletions(-) diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/mock/MockNetworks.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/mock/MockNetworks.kt index af85a6322b..12256c2120 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/mock/MockNetworks.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/mock/MockNetworks.kt @@ -32,6 +32,7 @@ internal object MockNetworks { MockTokens.token2.id to BigDecimal("42.2"), MockTokens.token3.id to BigDecimal("1000000000.5"), ), + hasTransactionsInProgress = false, ), ) @@ -49,6 +50,7 @@ internal object MockNetworks { MockTokens.token9.id to BigDecimal.TEN, MockTokens.token10.id to BigDecimal.TEN, ), + hasTransactionsInProgress = false, ), ) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/GetWalletTokenErrorMappers.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/GetWalletTokenErrorMappers.kt index 1252251389..e129b9fc6f 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/GetWalletTokenErrorMappers.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/GetWalletTokenErrorMappers.kt @@ -9,6 +9,7 @@ internal fun CurrenciesStatusesOperations.Error.mapToTokenError(): TokenError { is CurrenciesStatusesOperations.Error.EmptyNetworksStatuses, is CurrenciesStatusesOperations.Error.EmptyQuotes, is CurrenciesStatusesOperations.Error.EmptyCurrencies, + is CurrenciesStatusesOperations.Error.UnableToCreateCurrencyStatus, -> TokenError.UnableToCreateToken } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/TokenListErrorMappers.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/TokenListErrorMappers.kt index 9b24b82737..4796f50063 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/TokenListErrorMappers.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/TokenListErrorMappers.kt @@ -10,6 +10,7 @@ internal fun CurrenciesStatusesOperations.Error.mapToTokenListError(): TokenList is CurrenciesStatusesOperations.Error.EmptyNetworksStatuses, is CurrenciesStatusesOperations.Error.EmptyQuotes, is CurrenciesStatusesOperations.Error.EmptyCurrencies, + is CurrenciesStatusesOperations.Error.UnableToCreateCurrencyStatus, -> TokenListError.EmptyTokens } } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/CryptoCurrency.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/CryptoCurrency.kt index 891d75986e..504e7ef421 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/CryptoCurrency.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/CryptoCurrency.kt @@ -1,5 +1,17 @@ package com.tangem.domain.tokens.model +/** + * Represents a generic cryptocurrency. + * + * @property id Unique identifier for the cryptocurrency. + * @property networkId Identifier for the network to which the cryptocurrency belongs. + * @property name Human-readable name of the cryptocurrency. + * @property symbol Symbol of the cryptocurrency. + * @property decimals Number of decimal places used by the cryptocurrency. + * @property iconUrl Optional URL of the cryptocurrency icon. `null` if not found. + * @property derivationPath Optional path used for key derivation. `null` if the wallet does not support the + * [HD Wallet](https://coinsutra.com/hd-wallets-deterministic-wallet/) feature. + */ sealed class CryptoCurrency { abstract val id: ID @@ -10,6 +22,9 @@ sealed class CryptoCurrency { abstract val iconUrl: String? abstract val derivationPath: String? + /** + * Represents a native coin in the blockchain network. + */ data class Coin( override val id: ID, override val networkId: Network.ID, @@ -25,6 +40,12 @@ sealed class CryptoCurrency { } } + /** + * Represents a token in the blockchain network, typically a non-native asset. + * + * @property contractAddress Address of the contract managing the token. + * @property isCustom Indicates whether the token is a custom user-added token or not. + */ data class Token( override val id: ID, override val networkId: Network.ID, @@ -43,6 +64,11 @@ sealed class CryptoCurrency { } } + /** + * Value class for uniquely identifying a cryptocurrency. + * + * @property value The unique identifier value. + */ @JvmInline value class ID(val value: String) { diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt index f67fc23e5a..a735f3ed06 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt @@ -2,27 +2,64 @@ package com.tangem.domain.tokens.model import java.math.BigDecimal +/** + * Represents the status of a cryptocurrency asset within a network. + * + * This class encapsulates the details of a specific cryptocurrency, either a coin or token, + * along with its current status within the blockchain network. The status can include various states + * like Loading, Unreachable, Loaded, etc. + * + * @property currency The details of the cryptocurrency asset, including its type, name, symbol, and other properties. + * @property value The current status of the cryptocurrency, reflecting its state within the network. + */ data class CryptoCurrencyStatus( val currency: CryptoCurrency, val value: Status, ) { + /** + * Represents the various states a token can have, encapsulating different information based on the state. + */ sealed class Status { + + /** The amount of the token. */ open val amount: BigDecimal? = null + + /** The fiat equivalent of the token's amount. */ open val fiatAmount: BigDecimal? = null + + /** The exchange rate used for converting the token amount to fiat. */ open val fiatRate: BigDecimal? = null + + /** The change in price of the token. */ open val priceChange: BigDecimal? = null + + /** Indicates if there are any transactions in progress related to the token. */ open val hasTransactionsInProgress: Boolean = false } + /** Represents the Loading state of a token, typically while fetching its details. */ object Loading : Status() + /** Represents a state where the token is not reachable. */ object Unreachable : Status() + /** Represents a state where the token's derivation is missed. */ object MissedDerivation : Status() + /** Represents a state where there is no account associated with the token. */ object NoAccount : Status() + /** + * Represents a Loaded state of a token with complete information. + * + * @property amount The amount of the token. + * @property fiatAmount The fiat equivalent of the token's amount. + * @property fiatRate The exchange rate used for converting the token amount to fiat. + * @property priceChange The change in price of the token. + * @property hasTransactionsInProgress Indicates if there are any transactions in progress related to the token + * network. + */ data class Loaded( override val amount: BigDecimal, override val fiatAmount: BigDecimal, @@ -31,6 +68,16 @@ data class CryptoCurrencyStatus( override val hasTransactionsInProgress: Boolean, ) : Status() + /** + * Represents a Custom state of a token, typically used for user-defined tokens. + * + * @property amount The amount of the token. + * @property fiatAmount The fiat equivalent of the token's amount (optional). + * @property fiatRate The exchange rate used for converting the token amount to fiat (optional). + * @property priceChange The change in price of the token (optional). + * @property hasTransactionsInProgress Indicates if there are any transactions in progress related to the token + * network. + */ data class Custom( override val amount: BigDecimal, override val fiatAmount: BigDecimal?, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/Network.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/Network.kt index f7bd4500c2..402ae364eb 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/Network.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/Network.kt @@ -1,5 +1,13 @@ package com.tangem.domain.tokens.model +/** + * Represents a blockchain network, identified by a unique ID and a human-readable name. + * + * @property id The unique identifier of the network, encapsulated as an inline value class. + * @property name The human-readable name of the network, such as "Ethereum" or "Bitcoin". + * + * @throws IllegalArgumentException If the name or ID is blank. + */ data class Network( val id: ID, val name: String, @@ -9,6 +17,11 @@ data class Network( require(name.isNotBlank()) { "Network name must not be blank" } } + /** + * Represents a unique identifier for a network. + * + * @property value The string value of the network ID. + */ @JvmInline value class ID(val value: String) { diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/NetworkGroup.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/NetworkGroup.kt index 51d03a899e..b244d7252f 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/NetworkGroup.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/NetworkGroup.kt @@ -1,5 +1,13 @@ package com.tangem.domain.tokens.model +/** + * Represents a group of cryptocurrencies associated with a specific network. + * + * This class encapsulates a collection of cryptocurrency statuses, all of which are part of the same blockchain network. + * + * @property network The blockchain network associated with the group. + * @property currencies A set of cryptocurrency statuses that belong to the network. + */ data class NetworkGroup( val network: Network, val currencies: Set, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/NetworkStatus.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/NetworkStatus.kt index f76108f535..454480611c 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/NetworkStatus.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/NetworkStatus.kt @@ -2,22 +2,49 @@ package com.tangem.domain.tokens.model import java.math.BigDecimal +/** + * Represents the status of a specific blockchain network. + * + * @property networkId The unique identifier of the network for which the status is provided. + * @property value The specific status value, represented as a sealed class to encapsulate the various possible states of the network. + */ data class NetworkStatus( val networkId: Network.ID, val value: Status, ) { - sealed class Status { - open val amounts: Map? = null - } + /** + * Represents the various possible statuses of a network. + * + * This sealed class includes different states like unreachable, missed derivation, verified, and no account. + */ + sealed class Status + /** + * Represents the state where the network is unreachable. + */ object Unreachable : Status() + /** + * Represents the state where a derivation has been missed. + */ object MissedDerivation : Status() - data class TransactionInProgress(override val amounts: Map) : Status() - - data class Verified(override val amounts: Map) : Status() + /** + * Represents the verified state of the network, including the amounts associated with different cryptocurrencies and whether there are transactions in progress. + * + * @property amounts A map containing the amounts associated with different cryptocurrencies within the network. + * @property hasTransactionsInProgress A boolean indicating whether there are transactions in progress within the network. + */ + data class Verified( + val amounts: Map, + val hasTransactionsInProgress: Boolean, + ) : Status() + /** + * Represents the state where there is no account, and an amount is required to create one. + * + * @property amountToCreateAccount The amount required to create an account within the network. + */ data class NoAccount(val amountToCreateAccount: BigDecimal) : Status() } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/Quote.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/Quote.kt index 192c196537..7247a75ed2 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/Quote.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/Quote.kt @@ -2,6 +2,13 @@ package com.tangem.domain.tokens.model import java.math.BigDecimal +/** + * Represents a financial quote for a specific cryptocurrency, including its fiat exchange rate and price change. + * + * @property currencyId The unique identifier of the cryptocurrency for which the quote is provided. + * @property fiatRate The current fiat exchange rate for the cryptocurrency. + * @property priceChange The price change for the cryptocurrency. + */ data class Quote( val currencyId: CryptoCurrency.ID, val fiatRate: BigDecimal, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenList.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenList.kt index f19f35bef2..55327b82da 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenList.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenList.kt @@ -2,33 +2,75 @@ package com.tangem.domain.tokens.model import java.math.BigDecimal +/** + * Represents a list of cryptocurrency tokens, which can be grouped by network or ungrouped. + * + * The tokens can be represented in two forms: either grouped by the network or as an ungrouped collection. + * Additional details like the total fiat balance and the sorting type can be associated with the list. + * + * @property totalFiatBalance The total fiat balance across all tokens, which could be in a loading state, failed, or loaded with a specific amount. + * @property sortedBy The criteria used for sorting the tokens. + */ sealed class TokenList { open val totalFiatBalance: FiatBalance = FiatBalance.Loading open val sortedBy: SortType = SortType.NONE + /** + * Represents tokens that are grouped by their network. + * + * @property groups A set of network groups containing tokens. + * @property totalFiatBalance The total fiat balance across all groups. + * @property sortedBy The criteria used for sorting the tokens within the groups. + */ data class GroupedByNetwork( val groups: Set, override val totalFiatBalance: FiatBalance, override val sortedBy: SortType, ) : TokenList() + /** + * Represents tokens that are not grouped by any specific criteria. + * + * @property currencies A set of cryptocurrency statuses. + * @property totalFiatBalance The total fiat balance across all currencies. + * @property sortedBy The criteria used for sorting the currencies. + */ data class Ungrouped( val currencies: Set, override val totalFiatBalance: FiatBalance, override val sortedBy: SortType, ) : TokenList() + /** Represents a state where the token list is not initialized. */ object NotInitialized : TokenList() + /** Defines the possible sorting criteria for the tokens. */ enum class SortType { NONE, BALANCE, } + /** + * Represents the possible states of the fiat balance, including loading, failure, or a loaded amount. + */ sealed class FiatBalance { + /** + * Represents the loading state of the fiat balance. + * This state indicates that the fiat balance is currently being retrieved or calculated. + */ object Loading : FiatBalance() + /** + * Represents the failure state of the fiat balance. + * This state indicates that an attempt to retrieve or calculate the fiat balance has failed. + */ object Failed : FiatBalance() + /** + * Represents the successfully loaded state of the fiat balance. + * + * @property amount The loaded fiat balance amount. + * @property isAllAmountsSummarized Indicates whether the amount includes a summary of all underlying amounts. + */ data class Loaded( val amount: BigDecimal, val isAllAmountsSummarized: Boolean, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt index e64237f1a3..41b8fbae2e 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt @@ -101,6 +101,8 @@ internal class CurrenciesStatusesOperations( quote = quote, networkStatus = networkStatus, dispatchers = dispatchers, + raise = this, + transformError = { Error.UnableToCreateCurrencyStatus }, ) return currencyStatusOperations.createTokenStatus() @@ -161,6 +163,8 @@ internal class CurrenciesStatusesOperations( object EmptyNetworksStatuses : Error() + object UnableToCreateCurrencyStatus : Error() + data class DataError(val cause: Throwable) : Error() } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt index a48964936b..50f348f3d3 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt @@ -1,5 +1,8 @@ package com.tangem.domain.tokens.operations +import arrow.core.raise.Raise +import arrow.core.raise.ensureNotNull +import com.tangem.domain.core.raise.DelegatedRaise import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.NetworkStatus @@ -8,18 +11,17 @@ import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.withContext import java.math.BigDecimal -internal class CurrencyStatusOperations( +internal class CurrencyStatusOperations( private val currency: CryptoCurrency, private val quote: Quote?, private val networkStatus: NetworkStatus?, private val dispatchers: CoroutineDispatcherProvider, -) { + raise: Raise, + transformError: (Error) -> OtherError, +) : DelegatedRaise(raise, transformError) { suspend fun createTokenStatus(): CryptoCurrencyStatus = withContext(dispatchers.default) { - CryptoCurrencyStatus( - currency = currency, - value = createStatus(), - ) + CryptoCurrencyStatus(currency, createStatus()) } private fun createStatus(): CryptoCurrencyStatus.Status { @@ -28,23 +30,22 @@ internal class CurrencyStatusOperations( is NetworkStatus.MissedDerivation -> CryptoCurrencyStatus.MissedDerivation is NetworkStatus.Unreachable -> CryptoCurrencyStatus.Unreachable is NetworkStatus.NoAccount -> CryptoCurrencyStatus.NoAccount - is NetworkStatus.TransactionInProgress, - is NetworkStatus.Verified, - -> createStatus( - amount = getTokenAmount(), - hasTransactionsInProgress = status is NetworkStatus.TransactionInProgress, - ) + is NetworkStatus.Verified -> createStatus(status) } } - private fun createStatus(amount: BigDecimal, hasTransactionsInProgress: Boolean): CryptoCurrencyStatus.Status { + private fun createStatus(status: NetworkStatus.Verified): CryptoCurrencyStatus.Status { + val amount = ensureNotNull(status.amounts[currency.id]) { + Error.UnableToFindAmount(currency.id) + } + return when { currency is CryptoCurrency.Token && currency.isCustom -> CryptoCurrencyStatus.Custom( amount = amount, fiatAmount = calculateFiatAmountOrNull(amount, quote?.fiatRate), fiatRate = quote?.fiatRate, priceChange = quote?.priceChange, - hasTransactionsInProgress = hasTransactionsInProgress, + hasTransactionsInProgress = status.hasTransactionsInProgress, ) quote == null -> CryptoCurrencyStatus.Loading else -> CryptoCurrencyStatus.Loaded( @@ -52,16 +53,11 @@ internal class CurrencyStatusOperations( fiatAmount = calculateFiatAmount(amount, quote.fiatRate), fiatRate = quote.fiatRate, priceChange = quote.priceChange, - hasTransactionsInProgress = hasTransactionsInProgress, + hasTransactionsInProgress = status.hasTransactionsInProgress, ) } } - private fun getTokenAmount(): BigDecimal { - val amount = networkStatus?.value?.amounts?.get(currency.id) - return amount ?: error("Incorrect network status: $networkStatus") - } - private fun calculateFiatAmountOrNull(amount: BigDecimal, fiatRate: BigDecimal?): BigDecimal? { if (fiatRate == null) return null @@ -71,4 +67,9 @@ internal class CurrencyStatusOperations( private fun calculateFiatAmount(amount: BigDecimal, fiatRate: BigDecimal): BigDecimal { return amount * fiatRate } + + sealed class Error { + + data class UnableToFindAmount(val currencyId: CryptoCurrency.ID) : Error() + } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt index 36af396bbe..dfb3a25ef1 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt @@ -11,8 +11,22 @@ import kotlinx.coroutines.flow.Flow * */ interface NetworksRepository { + /** + * Retrieves the details of the specified blockchain networks, identified by their unique IDs. + * + * @param networksIds The unique identifiers of the networks to be retrieved. + * @return A set of [Network] objects corresponding to the specified network IDs. + */ fun getNetworks(networksIds: Set): Set + /** + * Retrieves the statuses of specified blockchain networks for a specific user wallet. + * + * @param userWalletId The unique identifier of the user wallet. + * @param networks A map of network IDs to sets of cryptocurrency IDs, representing the networks for which statuses are to be retrieved. + * @param refresh A boolean flag indicating whether the data should be refreshed. + * @return A [Flow] emitting a set of [NetworkStatus] objects corresponding to the specified networks. + */ fun getNetworkStatuses( userWalletId: UserWalletId, networks: Map>, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/QuotesRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/QuotesRepository.kt index d1aaef5ae1..1c783ce342 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/QuotesRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/QuotesRepository.kt @@ -9,5 +9,12 @@ import kotlinx.coroutines.flow.Flow * */ interface QuotesRepository { + /** + * Retrieves the quotes for a set of specified cryptocurrencies, identified by their unique IDs. + * + * @param tokensIds The unique identifiers of the cryptocurrencies for which quotes are to be retrieved. + * @param refresh A boolean flag indicating whether the data should be refreshed. + * @return A [Flow] emitting a set of quotes corresponding to the specified cryptocurrencies. + */ fun getQuotes(tokensIds: Set, refresh: Boolean): Flow> } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/TokensRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/TokensRepository.kt index f999803031..865c5fc4da 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/TokensRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/TokensRepository.kt @@ -9,6 +9,15 @@ import kotlinx.coroutines.flow.Flow * */ interface TokensRepository { + /** + * Saves the given set of cryptocurrencies, along with the preferences for grouping and sorting, for a specific + * multi-currency user wallet. + * + * @param userWalletId The unique identifier of the user wallet. + * @param currencies The set of cryptocurrencies to be saved. + * @param isGroupedByNetwork A boolean flag indicating whether the tokens should be grouped by network. + * @param isSortedByBalance A boolean flag indicating whether the tokens should be sorted by balance. + */ suspend fun saveTokens( userWalletId: UserWalletId, currencies: Set, @@ -16,11 +25,36 @@ interface TokensRepository { isSortedByBalance: Boolean, ) + /** + * Retrieves the primary cryptocurrency for a specific single-currency user wallet. + * + * @param userWalletId The unique identifier of the user wallet. + * @return The primary cryptocurrency associated with the user wallet. + */ suspend fun getPrimaryCurrency(userWalletId: UserWalletId): CryptoCurrency + /** + * Retrieves the set of cryptocurrencies within a multi-currency wallet. + * + * @param userWalletId The unique identifier of the user wallet. + * @param refresh A boolean flag indicating whether the data should be refreshed. + * @return A [Flow] emitting the set of cryptocurrencies associated with the user wallet. + */ fun getMultiCurrencyWalletCurrencies(userWalletId: UserWalletId, refresh: Boolean): Flow> + /** + * Determines whether the tokens within a specific multi-currency user wallet are grouped. + * + * @param userWalletId The unique identifier of the user wallet. + * @return A [Flow] emitting a boolean value indicating whether the tokens are grouped. + */ fun isTokensGrouped(userWalletId: UserWalletId): Flow + /** + * Determines whether the tokens within a specific multi-currency user wallet are sorted by balance. + * + * @param userWalletId The unique identifier of the user wallet. + * @return A [Flow] emitting a boolean value indicating whether the tokens are sorted by balance. + */ fun isTokensSortedByBalance(userWalletId: UserWalletId): Flow } \ No newline at end of file diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockNetworks.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockNetworks.kt index 03ad43ba70..a2194499b2 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockNetworks.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockNetworks.kt @@ -55,6 +55,7 @@ internal object MockNetworks { MockTokens.token2.id to BigDecimal.TEN, MockTokens.token3.id to BigDecimal.TEN, ), + hasTransactionsInProgress = false, ), ) @@ -66,6 +67,7 @@ internal object MockNetworks { MockTokens.token5.id to BigDecimal.TEN, MockTokens.token6.id to BigDecimal.TEN, ), + hasTransactionsInProgress = false, ), ) @@ -78,6 +80,7 @@ internal object MockNetworks { MockTokens.token9.id to BigDecimal.TEN, MockTokens.token10.id to BigDecimal.TEN, ), + hasTransactionsInProgress = false, ), )