Updated on 2026-08-14
This commit is contained in:
parent
dfa8619c13
commit
c49d680508
10 changed files with 52 additions and 33 deletions
|
|
@ -17,7 +17,7 @@ internal object StakingStoreModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun provideStakingTokensStore(): StakingYieldsStore {
|
||||
return DefaultStakingYieldsStore()
|
||||
return DefaultStakingYieldsStore(dataStore = RuntimeDataStore())
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
|||
|
|
@ -1,16 +1,32 @@
|
|||
package com.tangem.datasource.local.token
|
||||
|
||||
import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO
|
||||
import com.tangem.datasource.local.datastore.core.StringKeyDataStore
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
|
||||
internal class DefaultStakingYieldsStore : StakingYieldsStore {
|
||||
internal class DefaultStakingYieldsStore(
|
||||
private val dataStore: StringKeyDataStore<List<YieldDTO>>,
|
||||
) : StakingYieldsStore {
|
||||
|
||||
private var yields = listOf<YieldDTO>()
|
||||
private val mutex = Mutex()
|
||||
|
||||
override fun get(): List<YieldDTO> {
|
||||
return yields
|
||||
override fun get(): Flow<List<YieldDTO>> {
|
||||
return dataStore.get(KEY)
|
||||
}
|
||||
|
||||
override fun store(items: List<YieldDTO>) {
|
||||
yields = items
|
||||
override suspend fun getSync(): List<YieldDTO> {
|
||||
return dataStore.getSyncOrNull(KEY) ?: emptyList()
|
||||
}
|
||||
|
||||
override suspend fun store(items: List<YieldDTO>) {
|
||||
mutex.withLock {
|
||||
dataStore.store(KEY, items)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY = "DefaultStakingYieldsStore"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
package com.tangem.datasource.local.token
|
||||
|
||||
import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface StakingYieldsStore {
|
||||
|
||||
fun get(): List<YieldDTO>
|
||||
fun get(): Flow<List<YieldDTO>>
|
||||
|
||||
fun store(items: List<YieldDTO>)
|
||||
suspend fun getSync(): List<YieldDTO>
|
||||
|
||||
suspend fun store(items: List<YieldDTO>)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue