Updated on 2026-08-14

This commit is contained in:
Tangem 2024-10-25 17:49:53 +03:00
parent dab5fb51b6
commit 967d5520a1
37 changed files with 452 additions and 408 deletions

View file

@ -3,7 +3,8 @@ package com.tangem.datasource.api.stakekit
import com.tangem.datasource.api.common.response.ApiResponse
import com.tangem.datasource.api.stakekit.models.request.*
import com.tangem.datasource.api.stakekit.models.response.EnabledYieldsResponse
import com.tangem.datasource.api.stakekit.models.response.EnterActionResponse
import com.tangem.datasource.api.stakekit.models.response.ActionDTO
import com.tangem.datasource.api.stakekit.models.response.GetActionsResponse
import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO
import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO
import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingGasEstimateDTO
@ -35,14 +36,23 @@ interface StakeKitApi {
@Body body: YieldBalanceRequestBody,
): ApiResponse<List<BalanceDTO>>
@GET("actions")
suspend fun getActions(
@Query("walletAddress") walletAddress: String,
@Query("network") network: String,
@Query("status") status: String,
@Query("sort") sort: String = "createdAtDesc",
@Query("limit") limit: Int = 50,
): ApiResponse<GetActionsResponse>
@POST("actions/enter")
suspend fun createEnterAction(@Body body: ActionRequestBody): ApiResponse<EnterActionResponse>
suspend fun createEnterAction(@Body body: ActionRequestBody): ApiResponse<ActionDTO>
@POST("actions/exit")
suspend fun createExitAction(@Body body: ActionRequestBody): ApiResponse<EnterActionResponse>
suspend fun createExitAction(@Body body: ActionRequestBody): ApiResponse<ActionDTO>
@POST("actions/pending")
suspend fun createPendingAction(@Body body: PendingActionRequestBody): ApiResponse<EnterActionResponse>
suspend fun createPendingAction(@Body body: PendingActionRequestBody): ApiResponse<ActionDTO>
@POST("actions/enter/estimate-gas")
suspend fun estimateGasOnEnter(@Body body: ActionRequestBody): ApiResponse<StakingGasEstimateDTO>

View file

@ -9,7 +9,7 @@ import org.joda.time.DateTime
import java.math.BigDecimal
@JsonClass(generateAdapter = true)
data class EnterActionResponse(
data class ActionDTO(
@Json(name = "id")
val id: String,
@Json(name = "integrationId")

View file

@ -0,0 +1,16 @@
package com.tangem.datasource.api.stakekit.models.response
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class GetActionsResponse(
@Json(name = "data")
val data: List<ActionDTO>,
@Json(name = "hasNextPage")
val hasNextPage: Boolean,
@Json(name = "limit")
val limit: Int,
@Json(name = "page")
val page: Int,
)

View file

@ -1,8 +1,9 @@
package com.tangem.datasource.di
import com.tangem.datasource.local.datastore.RuntimeDataStore
import com.tangem.datasource.local.token.*
import com.tangem.datasource.local.token.DefaultStakingBalanceStore
import com.tangem.datasource.local.token.StakingBalanceStore
import com.tangem.datasource.local.token.DefaultStakingYieldsStore
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@ -11,11 +12,23 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
internal object StakingBalanceStoreModule {
internal object StakingStoreModule {
@Provides
@Singleton
fun provideStakingTokensStore(): StakingYieldsStore {
return DefaultStakingYieldsStore()
}
@Provides
@Singleton
fun provideStakingBalanceStore(): StakingBalanceStore {
return DefaultStakingBalanceStore(dataStore = RuntimeDataStore())
}
@Provides
@Singleton
fun provideStakingActionsStore(): StakingActionsStore {
return DefaultStakingActionsStore(dataStore = RuntimeDataStore())
}
}

View file

@ -1,20 +0,0 @@
package com.tangem.datasource.di
import com.tangem.datasource.local.token.DefaultStakingYieldsStore
import com.tangem.datasource.local.token.StakingYieldsStore
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
internal object StakingTokensStoreModule {
@Provides
@Singleton
fun provideStakingTokensStore(): StakingYieldsStore {
return DefaultStakingYieldsStore()
}
}

View file

@ -0,0 +1,34 @@
package com.tangem.datasource.local.token
import com.tangem.datasource.local.datastore.core.StringKeyDataStore
import com.tangem.domain.staking.model.stakekit.action.StakingAction
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
internal class DefaultStakingActionsStore(
private val dataStore: StringKeyDataStore<List<StakingAction>>,
) : StakingActionsStore {
private val mutex = Mutex()
override fun get(userWalletId: UserWalletId, cryptoCurrencyId: CryptoCurrency.ID): Flow<List<StakingAction>> {
return dataStore.get(composeKey(userWalletId, cryptoCurrencyId))
}
override suspend fun store(
userWalletId: UserWalletId,
cryptoCurrencyId: CryptoCurrency.ID,
items: List<StakingAction>,
) {
mutex.withLock {
dataStore.store(composeKey(userWalletId, cryptoCurrencyId), items)
}
}
private fun composeKey(userWalletId: UserWalletId, cryptoCurrencyId: CryptoCurrency.ID): String {
return userWalletId.stringValue + cryptoCurrencyId.value
}
}

View file

@ -4,13 +4,13 @@ import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO
internal class DefaultStakingYieldsStore : StakingYieldsStore {
private var yields = mutableListOf<YieldDTO>()
private var yields = listOf<YieldDTO>()
override fun get(): List<YieldDTO> {
return yields
}
override fun store(items: List<YieldDTO>) {
yields = items.toMutableList()
yields = items
}
}

View file

@ -0,0 +1,13 @@
package com.tangem.datasource.local.token
import com.tangem.domain.staking.model.stakekit.action.StakingAction
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
interface StakingActionsStore {
fun get(userWalletId: UserWalletId, cryptoCurrencyId: CryptoCurrency.ID): Flow<List<StakingAction>>
suspend fun store(userWalletId: UserWalletId, cryptoCurrencyId: CryptoCurrency.ID, items: List<StakingAction>)
}