Updated on 2026-08-14
This commit is contained in:
parent
03aa966c1d
commit
80ac1d02c0
26 changed files with 421 additions and 2 deletions
1
domain/tokens/.gitignore
vendored
Normal file
1
domain/tokens/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
10
domain/tokens/build.gradle.kts
Normal file
10
domain/tokens/build.gradle.kts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
plugins {
|
||||
alias(deps.plugins.kotlin.jvm)
|
||||
id("configuration")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.domain.core)
|
||||
implementation(projects.domain.wallets.models)
|
||||
implementation(projects.core.utils)
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// TODO: [REDACTED_JIRA]
|
||||
@file:Suppress("unused", "unused_parameter")
|
||||
|
||||
package com.tangem.domain.tokens
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.left
|
||||
import com.tangem.domain.tokens.error.TokensError
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.domain.tokens.repository.NetworksRepository
|
||||
import com.tangem.domain.tokens.repository.QuotesRepository
|
||||
import com.tangem.domain.tokens.repository.TokensRepository
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
|
||||
class GetTokenListUseCase(
|
||||
private val tokensRepository: TokensRepository,
|
||||
private val quotesRepository: QuotesRepository,
|
||||
private val networksRepository: NetworksRepository,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) {
|
||||
|
||||
operator fun invoke(userWalletId: UserWalletId, refresh: Boolean = true): Flow<Either<TokensError, TokenList>> {
|
||||
return flowOf(TokensError.EmptyTokens.left())
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package com.tangem.domain.tokens.error
|
||||
|
||||
sealed class TokensError {
|
||||
|
||||
object EmptyTokens : TokensError()
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.domain.tokens.model
|
||||
|
||||
data class Network(
|
||||
val id: ID,
|
||||
val name: String,
|
||||
) {
|
||||
|
||||
@JvmInline
|
||||
value class ID(val value: String)
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.tangem.domain.tokens.model
|
||||
|
||||
import arrow.core.NonEmptySet
|
||||
|
||||
data class NetworkGroup(
|
||||
val networkId: Network.ID,
|
||||
val name: String,
|
||||
val tokens: NonEmptySet<TokenStatus>,
|
||||
)
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.tangem.domain.tokens.model
|
||||
|
||||
import java.math.BigDecimal
|
||||
|
||||
data class NetworkStatus(
|
||||
val networkId: Network.ID,
|
||||
val value: Status,
|
||||
) {
|
||||
|
||||
sealed class Status {
|
||||
open val amounts: Map<Token.ID, BigDecimal>? = null
|
||||
}
|
||||
|
||||
object Unreachable : Status()
|
||||
|
||||
object MissedDerivation : Status()
|
||||
|
||||
data class TransactionInProgress(override val amounts: Map<Token.ID, BigDecimal>) : Status()
|
||||
|
||||
data class Verified(override val amounts: Map<Token.ID, BigDecimal>) : Status()
|
||||
|
||||
data class NoAccount(val amountToCreateAccount: BigDecimal) : Status()
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.tangem.domain.tokens.model
|
||||
|
||||
import java.math.BigDecimal
|
||||
|
||||
data class Quote(
|
||||
val tokenId: Token.ID,
|
||||
val fiatRate: BigDecimal,
|
||||
val priceChange: BigDecimal,
|
||||
)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.tangem.domain.tokens.model
|
||||
|
||||
data class Token(
|
||||
val id: ID,
|
||||
val networkId: Network.ID,
|
||||
val name: String,
|
||||
val symbol: String,
|
||||
val isCustom: Boolean,
|
||||
val isCoin: Boolean,
|
||||
) {
|
||||
|
||||
@JvmInline
|
||||
value class ID(val value: String)
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.tangem.domain.tokens.model
|
||||
|
||||
import arrow.core.NonEmptySet
|
||||
import java.math.BigDecimal
|
||||
|
||||
sealed class TokenList {
|
||||
open val totalFiatBalance: FiatBalance = FiatBalance.Loading
|
||||
open val sortedBy: SortType = SortType.NONE
|
||||
|
||||
data class GroupedByNetwork(
|
||||
val groups: NonEmptySet<NetworkGroup>,
|
||||
override val totalFiatBalance: FiatBalance,
|
||||
override val sortedBy: SortType,
|
||||
) : TokenList()
|
||||
|
||||
data class Ungrouped(
|
||||
val tokens: NonEmptySet<TokenStatus>,
|
||||
override val totalFiatBalance: FiatBalance,
|
||||
override val sortedBy: SortType,
|
||||
) : TokenList()
|
||||
|
||||
object NotInitialized : TokenList()
|
||||
|
||||
enum class SortType {
|
||||
NONE, BALANCE,
|
||||
}
|
||||
|
||||
sealed class FiatBalance {
|
||||
object Loading : FiatBalance()
|
||||
|
||||
object Failed : FiatBalance()
|
||||
|
||||
data class Loaded(
|
||||
val amount: BigDecimal,
|
||||
val isAllAmountsSummarized: Boolean,
|
||||
) : FiatBalance()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.tangem.domain.tokens.model
|
||||
|
||||
import java.math.BigDecimal
|
||||
|
||||
data class TokenStatus(
|
||||
val id: Token.ID,
|
||||
val networkId: Network.ID,
|
||||
val name: String,
|
||||
val symbol: String,
|
||||
val isCoin: Boolean,
|
||||
val value: Status,
|
||||
) {
|
||||
|
||||
sealed class Status {
|
||||
open val amount: BigDecimal? = null
|
||||
open val fiatAmount: BigDecimal? = null
|
||||
open val priceChange: BigDecimal? = null
|
||||
open val hasTransactionsInProgress: Boolean = false
|
||||
}
|
||||
|
||||
object Loading : Status()
|
||||
|
||||
object Unreachable : Status()
|
||||
|
||||
object MissedDerivation : Status()
|
||||
|
||||
object NoAccount : Status()
|
||||
|
||||
data class Loaded(
|
||||
override val amount: BigDecimal,
|
||||
override val fiatAmount: BigDecimal,
|
||||
override val priceChange: BigDecimal,
|
||||
override val hasTransactionsInProgress: Boolean,
|
||||
) : Status()
|
||||
|
||||
data class Custom(
|
||||
override val amount: BigDecimal,
|
||||
override val fiatAmount: BigDecimal?,
|
||||
override val priceChange: BigDecimal?,
|
||||
override val hasTransactionsInProgress: Boolean,
|
||||
) : Status()
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.tangem.domain.tokens.repository
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.tokens.error.TokensError
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
import com.tangem.domain.tokens.model.NetworkStatus
|
||||
import com.tangem.domain.tokens.model.Token
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
// FIXME: Use Raise as context instead of Effect when context receivers become stable
|
||||
// [REDACTED_JIRA]
|
||||
|
||||
/**
|
||||
* Repository for everything related to the blockchain networks
|
||||
* */
|
||||
interface NetworksRepository {
|
||||
|
||||
fun getNetworks(networksIds: Set<Network.ID>): Either<TokensError, Set<Network>>
|
||||
|
||||
fun getNetworkStatuses(
|
||||
userWalletId: UserWalletId,
|
||||
networks: Map<Network.ID, Set<Token.ID>>,
|
||||
refresh: Boolean,
|
||||
): Flow<Either<TokensError, Set<NetworkStatus>>>
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.tangem.domain.tokens.repository
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.tokens.error.TokensError
|
||||
import com.tangem.domain.tokens.model.Quote
|
||||
import com.tangem.domain.tokens.model.Token
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
// FIXME: Use Raise as context instead of Effect when context receivers become stable
|
||||
// [REDACTED_JIRA]
|
||||
|
||||
/**
|
||||
* Repository for everything related to the quotes of tokens
|
||||
* */
|
||||
interface QuotesRepository {
|
||||
|
||||
fun getQuotes(tokensIds: Set<Token.ID>, refresh: Boolean): Flow<Either<TokensError, Set<Quote>>>
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.tangem.domain.tokens.repository
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.tokens.error.TokensError
|
||||
import com.tangem.domain.tokens.model.Token
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
// FIXME: Use Raise as context instead of Effect when context receivers become stable
|
||||
// [REDACTED_JIRA]
|
||||
|
||||
/**
|
||||
* Repository for everything related to the tokens of user wallet
|
||||
* */
|
||||
interface TokensRepository {
|
||||
|
||||
suspend fun sortTokens(
|
||||
userWalletId: UserWalletId,
|
||||
sortedTokensIds: Set<Token.ID>,
|
||||
isGrouped: Boolean,
|
||||
isSortedByBalance: Boolean,
|
||||
): Either<TokensError, Unit>
|
||||
|
||||
fun getTokens(userWalletId: UserWalletId, refresh: Boolean): Flow<Either<TokensError, Set<Token>>>
|
||||
|
||||
fun isTokensGrouped(userWalletId: UserWalletId): Flow<Either<TokensError, Boolean>>
|
||||
|
||||
fun isTokensSortedByBalance(userWalletId: UserWalletId): Flow<Either<TokensError, Boolean>>
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue