Updated on 2026-08-14
This commit is contained in:
parent
fc0295bf33
commit
d9320f8c2a
25 changed files with 369 additions and 89 deletions
|
|
@ -8,10 +8,13 @@ import com.squareup.moshi.Moshi
|
|||
import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO
|
||||
import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO
|
||||
import com.tangem.datasource.local.datastore.RuntimeDataStore
|
||||
import com.tangem.datasource.local.token.DefaultP2PEthPoolVaultsStore
|
||||
import com.tangem.datasource.local.token.DefaultStakingActionsStore
|
||||
import com.tangem.datasource.local.token.DefaultStakingYieldsStore
|
||||
import com.tangem.datasource.local.token.P2PEthPoolVaultsStore
|
||||
import com.tangem.datasource.local.token.StakingActionsStore
|
||||
import com.tangem.datasource.local.token.StakingYieldsStore
|
||||
import com.tangem.domain.staking.model.ethpool.P2PEthPoolVault
|
||||
import com.tangem.datasource.utils.MoshiDataStoreSerializer
|
||||
import com.tangem.datasource.utils.listTypes
|
||||
import com.tangem.datasource.utils.mapWithStringKeyTypes
|
||||
|
|
@ -73,4 +76,24 @@ internal object StakingStoreModule {
|
|||
fun provideStakingActionsStore(): StakingActionsStore {
|
||||
return DefaultStakingActionsStore(dataStore = RuntimeDataStore())
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideP2PEthPoolVaultsStore(
|
||||
@NetworkMoshi moshi: Moshi,
|
||||
@ApplicationContext context: Context,
|
||||
dispatchers: CoroutineDispatcherProvider,
|
||||
): P2PEthPoolVaultsStore {
|
||||
return DefaultP2PEthPoolVaultsStore(
|
||||
dataStore = DataStoreFactory.create(
|
||||
serializer = MoshiDataStoreSerializer(
|
||||
moshi = moshi,
|
||||
types = listTypes<P2PEthPoolVault>(),
|
||||
defaultValue = emptyList(),
|
||||
),
|
||||
produceFile = { context.dataStoreFile(fileName = "p2p_eth_pool_vaults") },
|
||||
scope = CoroutineScope(context = dispatchers.io + SupervisorJob()),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.tangem.datasource.local.token
|
||||
|
||||
import androidx.datastore.core.DataStore
|
||||
import com.tangem.domain.staking.model.ethpool.P2PEthPoolVault
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
|
||||
internal class DefaultP2PEthPoolVaultsStore(
|
||||
private val dataStore: DataStore<List<P2PEthPoolVault>>,
|
||||
) : P2PEthPoolVaultsStore {
|
||||
|
||||
override fun get(): Flow<List<P2PEthPoolVault>> {
|
||||
return dataStore.data
|
||||
}
|
||||
|
||||
override suspend fun getSync(): List<P2PEthPoolVault> {
|
||||
return dataStore.data.firstOrNull().orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun store(vaults: List<P2PEthPoolVault>) {
|
||||
dataStore.updateData { vaults }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.tangem.datasource.local.token
|
||||
|
||||
import com.tangem.domain.staking.model.ethpool.P2PEthPoolVault
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Store for P2P Ethereum pooled staking vaults
|
||||
* (similar to StakingYieldsStore for StakeKit yields)
|
||||
*
|
||||
* Vault is ETH-specific concept for pooled staking.
|
||||
* For other blockchains, P2P may use different structures.
|
||||
*/
|
||||
interface P2PEthPoolVaultsStore {
|
||||
|
||||
/**
|
||||
* Get all stored vaults as Flow
|
||||
*/
|
||||
fun get(): Flow<List<P2PEthPoolVault>>
|
||||
|
||||
/**
|
||||
* Get all stored vaults synchronously
|
||||
*/
|
||||
suspend fun getSync(): List<P2PEthPoolVault>
|
||||
|
||||
/**
|
||||
* Store vaults from P2P API
|
||||
*/
|
||||
suspend fun store(vaults: List<P2PEthPoolVault>)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue