Updated on 2026-08-14

This commit is contained in:
Tangem 2025-04-21 15:03:17 +03:00
parent 17008240b9
commit cb23c1dea3
12 changed files with 43 additions and 11 deletions

View file

@ -17,6 +17,7 @@ dependencies {
implementation(projects.domain.legacy)
implementation(projects.domain.models)
implementation(projects.domain.staking.models)
implementation(projects.domain.tokens.models)
implementation(projects.domain.wallets)
implementation(projects.domain.wallets.models)

View file

@ -1,11 +1,11 @@
package com.tangem.common.test.data.staking
import com.tangem.data.staking.store.YieldsBalancesStore.StakingID
import com.tangem.datasource.api.stakekit.models.request.Address
import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO
import com.tangem.datasource.api.stakekit.models.response.model.NetworkTypeDTO
import com.tangem.datasource.api.stakekit.models.response.model.TokenDTO
import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO
import com.tangem.domain.staking.model.StakingID
import java.math.BigDecimal
/**

View file

@ -4,6 +4,8 @@ import androidx.datastore.core.DataStore
import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.withTimeoutOrNull
import kotlin.time.Duration.Companion.seconds
internal class DefaultStakingYieldsStore(
private val dataStore: DataStore<List<YieldDTO>>,
@ -17,9 +19,18 @@ internal class DefaultStakingYieldsStore(
return dataStore.data.firstOrNull().orEmpty()
}
override suspend fun getSyncWithTimeout(): List<YieldDTO>? {
return withTimeoutOrNull(timeout = YIELDS_WAITING_TIMEOUT, block = { get().firstOrNull() })
}
override suspend fun store(items: List<YieldDTO>) {
dataStore.updateData { _ ->
items
}
}
private companion object {
val YIELDS_WAITING_TIMEOUT = 15.seconds
}
}

View file

@ -9,5 +9,7 @@ interface StakingYieldsStore {
suspend fun getSync(): List<YieldDTO>
suspend fun getSyncWithTimeout(): List<YieldDTO>?
suspend fun store(items: List<YieldDTO>)
}

View file

@ -1,7 +1,7 @@
package com.tangem.data.staking.single
import com.tangem.data.staking.store.YieldsBalancesStore.StakingID
import com.tangem.data.staking.utils.StakingIdFactory
import com.tangem.domain.staking.model.StakingID
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.multi.MultiYieldBalanceProducer
import com.tangem.domain.staking.multi.MultiYieldBalanceSupplier

View file

@ -1,11 +1,11 @@
package com.tangem.data.staking.store
import androidx.datastore.core.DataStore
import com.tangem.data.staking.store.YieldsBalancesStore.StakingID
import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO
import com.tangem.datasource.local.datastore.RuntimeSharedStore
import com.tangem.datasource.local.token.converter.YieldBalanceConverter
import com.tangem.domain.models.StatusSource
import com.tangem.domain.staking.model.StakingID
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider

View file

@ -1,6 +1,7 @@
package com.tangem.data.staking.store
import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO
import com.tangem.domain.staking.model.StakingID
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
@ -26,6 +27,4 @@ interface YieldsBalancesStore {
/** Store error by [userWalletId] and [stakingId] */
suspend fun storeError(userWalletId: UserWalletId, stakingId: StakingID)
data class StakingID(val integrationId: String, val address: String)
}

View file

@ -3,7 +3,7 @@ package com.tangem.data.staking.utils
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchainsdk.utils.toCoinId
import com.tangem.blockchainsdk.utils.toMigratedCoinId
import com.tangem.data.staking.store.YieldsBalancesStore.StakingID
import com.tangem.domain.staking.model.StakingID
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.walletmanager.WalletManagersFacade
@ -31,12 +31,25 @@ internal class StakingIdFactory @Inject constructor(
}
}
suspend fun createForDefault(
userWalletId: UserWalletId,
currencyId: CryptoCurrency.ID,
network: Network,
): StakingID? {
val address = walletManagersFacade.getDefaultAddress(userWalletId = userWalletId, network = network)
val integrationId = createIntegrationId(currencyId)
if (address == null || integrationId == null) return null
return StakingID(integrationId = integrationId, address = address)
}
fun createIntegrationId(currencyId: CryptoCurrency.ID): String? {
val integrationKey = with(currencyId) { rawNetworkId.plus(rawCurrencyId) }
return integrationIdMap[integrationKey]
}
@Suppress("UnusedPrivateMember")
@Suppress("UnusedPrivateMember", "unused")
companion object {
private const val TON_INTEGRATION_ID = "ton-ton-chorus-one-pools-staking"

View file

@ -5,6 +5,7 @@ import com.tangem.common.test.data.staking.MockYieldBalanceWrapperDTOFactory
import com.tangem.common.test.utils.getEmittedValues
import com.tangem.data.staking.store.YieldsBalancesStore
import com.tangem.data.staking.toDomain
import com.tangem.domain.staking.model.StakingID
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.multi.MultiYieldBalanceProducer
import com.tangem.domain.wallets.models.UserWalletId
@ -182,7 +183,7 @@ internal class DefaultMultiYieldBalanceProducerTest {
private companion object {
val tonId = MockYieldBalanceWrapperDTOFactory.defaultStakingId
val solanaId = YieldsBalancesStore.StakingID(
val solanaId = StakingID(
integrationId = "solana-sol-native-multivalidator-staking",
address = "0x1",
)

View file

@ -5,9 +5,9 @@ import com.tangem.blockchain.common.Blockchain
import com.tangem.common.test.data.staking.MockYieldBalanceWrapperDTOFactory
import com.tangem.common.test.domain.token.MockCryptoCurrencyFactory
import com.tangem.common.test.utils.getEmittedValues
import com.tangem.data.staking.store.YieldsBalancesStore
import com.tangem.data.staking.toDomain
import com.tangem.data.staking.utils.StakingIdFactory
import com.tangem.domain.staking.model.StakingID
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.multi.MultiYieldBalanceProducer
import com.tangem.domain.staking.multi.MultiYieldBalanceSupplier
@ -229,7 +229,7 @@ internal class DefaultSingleYieldBalanceProducerTest {
val ton = mocks.createCoin(Blockchain.TON)
val tonId = MockYieldBalanceWrapperDTOFactory.defaultStakingId
val solanaId = YieldsBalancesStore.StakingID(
val solanaId = StakingID(
integrationId = "solana-sol-native-multivalidator-staking",
address = "0x1",
)

View file

@ -7,6 +7,7 @@ import com.tangem.data.staking.toDomain
import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO
import com.tangem.datasource.local.datastore.RuntimeSharedStore
import com.tangem.domain.models.StatusSource
import com.tangem.domain.staking.model.StakingID
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider
@ -179,7 +180,7 @@ internal class YieldsBalancesStoreUpdateMethodsTest {
val stakingIds = setOf(
stakingId,
YieldsBalancesStore.StakingID(
StakingID(
integrationId = "solana-sol-native-multivalidator-staking",
address = "0x1",
),

View file

@ -0,0 +1,4 @@
package com.tangem.domain.staking.model
// TODO: make part of YieldBalance in the future
data class StakingID(val integrationId: String, val address: String)