Updated on 2026-08-14
This commit is contained in:
parent
bd699c5bd9
commit
ef5d0fec78
40 changed files with 600 additions and 642 deletions
|
|
@ -22,6 +22,7 @@ dependencies {
|
|||
implementation(deps.kotlin.datetime)
|
||||
implementation(deps.kotlin.serialization)
|
||||
implementation(deps.jodatime)
|
||||
implementation(deps.timber)
|
||||
|
||||
implementation(projects.domain.legacy)
|
||||
implementation(projects.domain.walletManager) // TODO refactor to use from data module
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
package com.tangem.domain.staking.single
|
||||
|
||||
import com.tangem.core.analytics.api.AnalyticsExceptionHandler
|
||||
import com.tangem.core.analytics.models.ExceptionAnalyticsEvent
|
||||
import com.tangem.domain.core.flow.FlowProducer
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.models.staking.StakingBalance
|
||||
import com.tangem.domain.models.staking.StakingID
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.utils.extensions.indexOfFirstOrNull
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Producer of staking balance for selected wallet [UserWalletId]
|
||||
|
|
@ -28,4 +32,43 @@ interface SingleStakingBalanceProducer : FlowProducer<StakingBalance> {
|
|||
}
|
||||
|
||||
interface Factory : FlowProducer.Factory<Params, SingleStakingBalanceProducer>
|
||||
|
||||
companion object {
|
||||
|
||||
fun selectStakingBalance(
|
||||
currentStakingId: StakingID,
|
||||
currentBalances: List<StakingBalance>,
|
||||
analyticsExceptionHandler: AnalyticsExceptionHandler,
|
||||
): StakingBalance? {
|
||||
return if (currentBalances.size > 1) {
|
||||
analyticsExceptionHandler.sendException(
|
||||
event = ExceptionAnalyticsEvent(
|
||||
exception = IllegalStateException("Multiple balances found for staking ID"),
|
||||
params = mapOf(
|
||||
"stakingId" to currentStakingId.toString(),
|
||||
"balances" to currentBalances.joinToString(",") { it.toString() },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
Timber.e(
|
||||
"Multiple balances found for staking ID $currentStakingId:\n%s",
|
||||
currentBalances.joinToString("\n"),
|
||||
)
|
||||
|
||||
val dataIndex = currentBalances.indexOfFirstOrNull { it is StakingBalance.Data }
|
||||
|
||||
if (dataIndex != null) {
|
||||
currentBalances[dataIndex]
|
||||
} else {
|
||||
currentBalances.first()
|
||||
}
|
||||
} else {
|
||||
val balance = currentBalances.firstOrNull() ?: return null
|
||||
|
||||
Timber.i("Staking balance found for $currentStakingId:\n$balance")
|
||||
balance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue