Updated on 2026-08-14
This commit is contained in:
parent
17008240b9
commit
cb23c1dea3
12 changed files with 43 additions and 11 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -9,5 +9,7 @@ interface StakingYieldsStore {
|
|||
|
||||
suspend fun getSync(): List<YieldDTO>
|
||||
|
||||
suspend fun getSyncWithTimeout(): List<YieldDTO>?
|
||||
|
||||
suspend fun store(items: List<YieldDTO>)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue