Updated on 2026-08-14
This commit is contained in:
parent
d197fae012
commit
bc80eed141
6 changed files with 116 additions and 2 deletions
|
|
@ -30,12 +30,12 @@ data class AccountStatusList(
|
|||
val groupType: TokensGroupType,
|
||||
) {
|
||||
|
||||
val mainAccount: AccountStatus
|
||||
val mainAccount: AccountStatus.CryptoPortfolio
|
||||
get() = accountStatuses.first { accountStatus ->
|
||||
when (accountStatus) {
|
||||
is AccountStatus.CryptoPortfolio -> accountStatus.account.isMainAccount
|
||||
}
|
||||
}
|
||||
} as AccountStatus.CryptoPortfolio
|
||||
|
||||
fun flattenCurrencies(): List<CryptoCurrencyStatus> = accountStatuses
|
||||
.map { accountStatus -> accountStatus.flattenCurrencies() }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.tangem.domain.account.status.di
|
||||
|
||||
import com.tangem.domain.account.status.producer.DefaultSingleAccountStatusProducer
|
||||
import com.tangem.domain.account.status.producer.SingleAccountStatusProducer
|
||||
import com.tangem.domain.account.status.supplier.SingleAccountStatusSupplier
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal interface SingleAccountStatusSupplierModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindSingleAccountStatusProducerFactory(
|
||||
impl: DefaultSingleAccountStatusProducer.Factory,
|
||||
): SingleAccountStatusProducer.Factory
|
||||
|
||||
companion object {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSingleAccountStatusSupplier(
|
||||
factory: SingleAccountStatusProducer.Factory,
|
||||
): SingleAccountStatusSupplier {
|
||||
return object : SingleAccountStatusSupplier(
|
||||
factory = factory,
|
||||
keyCreator = { "single_account_status_${it.accountId.value}" },
|
||||
) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.tangem.domain.account.status.producer
|
||||
|
||||
import arrow.core.Option
|
||||
import arrow.core.none
|
||||
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
|
||||
import com.tangem.domain.models.account.AccountStatus
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.mapNotNull
|
||||
|
||||
/**
|
||||
* Default implementation of [SingleAccountStatusProducer].
|
||||
*
|
||||
* @param params Parameters required to produce the account status.
|
||||
* @param singleAccountStatusListSupplier Supplier to fetch the list of account statuses.
|
||||
* @param dispatchers Coroutine dispatcher provider for managing threading.
|
||||
*/
|
||||
internal class DefaultSingleAccountStatusProducer @AssistedInject constructor(
|
||||
@Assisted val params: SingleAccountStatusProducer.Params,
|
||||
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) : SingleAccountStatusProducer {
|
||||
|
||||
override val fallback: Option<AccountStatus> get() = none()
|
||||
|
||||
override fun produce(): Flow<AccountStatus> {
|
||||
return singleAccountStatusListSupplier(userWalletId = params.accountId.userWalletId)
|
||||
.mapNotNull { accountStatusList ->
|
||||
accountStatusList.accountStatuses.firstOrNull {
|
||||
it.account.accountId == params.accountId
|
||||
}
|
||||
}
|
||||
.flowOn(dispatchers.default)
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : SingleAccountStatusProducer.Factory {
|
||||
override fun create(params: SingleAccountStatusProducer.Params): DefaultSingleAccountStatusProducer
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.tangem.domain.account.status.producer
|
||||
|
||||
import com.tangem.domain.core.flow.FlowProducer
|
||||
import com.tangem.domain.models.account.AccountId
|
||||
import com.tangem.domain.models.account.AccountStatus
|
||||
|
||||
/**
|
||||
* Producer that provides a single [AccountStatus] for a specific account identifier.
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
interface SingleAccountStatusProducer : FlowProducer<AccountStatus> {
|
||||
|
||||
data class Params(val accountId: AccountId)
|
||||
|
||||
interface Factory : FlowProducer.Factory<Params, SingleAccountStatusProducer>
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.tangem.domain.account.status.supplier
|
||||
|
||||
import com.tangem.domain.account.status.producer.SingleAccountStatusProducer
|
||||
import com.tangem.domain.core.flow.FlowCachingSupplier
|
||||
import com.tangem.domain.models.account.AccountStatus
|
||||
|
||||
/**
|
||||
* Supplier that provides a single [AccountStatus] for a specific account identifier.
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
abstract class SingleAccountStatusSupplier(
|
||||
override val factory: SingleAccountStatusProducer.Factory,
|
||||
override val keyCreator: (SingleAccountStatusProducer.Params) -> String,
|
||||
) : FlowCachingSupplier<SingleAccountStatusProducer, SingleAccountStatusProducer.Params, AccountStatus>()
|
||||
|
|
@ -3,6 +3,7 @@ package com.tangem.feature.wallet.presentation.account
|
|||
import com.tangem.core.decompose.di.ModelScoped
|
||||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
|
||||
import com.tangem.domain.account.status.supplier.SingleAccountStatusSupplier
|
||||
import com.tangem.domain.account.usecase.IsAccountsModeEnabledUseCase
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -12,4 +13,5 @@ internal class AccountDependencies @Inject constructor(
|
|||
val isAccountsModeEnabledUseCase: IsAccountsModeEnabledUseCase,
|
||||
val expandedAccountsHolder: ExpandedAccountsHolder,
|
||||
val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
|
||||
val singleAccountStatusSupplier: SingleAccountStatusSupplier,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue