Updated on 2026-08-14
This commit is contained in:
parent
4d73b7725e
commit
d8be65f5f7
41 changed files with 983 additions and 767 deletions
|
|
@ -46,5 +46,27 @@ data class CurrenciesResponse(val currencies: List<Currency>) {
|
|||
}
|
||||
|
||||
data class GeoResponse(
|
||||
val code: String
|
||||
) : TangemTechResponse
|
||||
val code: String,
|
||||
) : TangemTechResponse
|
||||
|
||||
data class UserTokensResponse(
|
||||
val version: Int = 0,
|
||||
val group: String = "",
|
||||
val sort: String = "",
|
||||
val tokens: List<TokenResponse> = emptyList(),
|
||||
) : TangemTechResponse
|
||||
|
||||
data class TokenResponse(
|
||||
val id: String,
|
||||
val networkId: String,
|
||||
val derivationPath: String,
|
||||
val name: String,
|
||||
val symbol: String,
|
||||
val decimals: Int,
|
||||
val contractAddress: String?,
|
||||
) : TangemTechResponse
|
||||
|
||||
data class TangemTechError(
|
||||
val code: Int,
|
||||
val description: String,
|
||||
)
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
package com.tangem.network.api.tangemTech
|
||||
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.PUT
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
|
||||
/**
|
||||
|
|
@ -29,4 +32,10 @@ interface TangemTechApi {
|
|||
|
||||
@GET("geo")
|
||||
suspend fun geo(): GeoResponse
|
||||
|
||||
@GET("user-tokens/{user-id}")
|
||||
suspend fun getUserTokens(@Path(value = "user-id") userId: String): UserTokensResponse
|
||||
|
||||
@PUT("user-tokens/{user-id}")
|
||||
suspend fun putUserTokens(@Path(value = "user-id") userId: String, @Body userTokens: UserTokensResponse)
|
||||
}
|
||||
|
|
@ -13,18 +13,16 @@ import kotlinx.coroutines.withContext
|
|||
*/
|
||||
class TangemTechService {
|
||||
private val headerInterceptors = mutableListOf<AddHeaderInterceptor>(
|
||||
CacheControlHttpInterceptor(cacheMaxAge)
|
||||
CacheControlHttpInterceptor(cacheMaxAge),
|
||||
)
|
||||
|
||||
private var api: TangemTechApi = createApi()
|
||||
|
||||
suspend fun coins(
|
||||
contractAddress: String? = null,
|
||||
networkIds: String? = null,
|
||||
active: Boolean? = null,
|
||||
searchText: String? = null,
|
||||
offset: Int? = null,
|
||||
limit: Int? = null
|
||||
limit: Int? = null,
|
||||
): Result<CoinsResponse> = withContext(Dispatchers.IO) {
|
||||
performRequest {
|
||||
api.coins(
|
||||
|
|
@ -33,14 +31,14 @@ class TangemTechService {
|
|||
active = active,
|
||||
searchText = searchText,
|
||||
offset = offset,
|
||||
limit = limit
|
||||
limit = limit,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun rates(
|
||||
currency: String,
|
||||
ids: List<String>
|
||||
ids: List<String>,
|
||||
): Result<RatesResponse> = withContext(Dispatchers.IO) {
|
||||
performRequest {
|
||||
api.rates(currency.lowercase(), ids.joinToString(","))
|
||||
|
|
@ -55,6 +53,15 @@ class TangemTechService {
|
|||
performRequest { api.currencies() }
|
||||
}
|
||||
|
||||
suspend fun getUserTokens(userId: String): Result<UserTokensResponse> = withContext(Dispatchers.IO) {
|
||||
performRequest { api.getUserTokens(userId) }
|
||||
}
|
||||
|
||||
suspend fun putUserTokens(userId: String, userTokens: UserTokensResponse): Result<Unit> =
|
||||
withContext(Dispatchers.IO) {
|
||||
performRequest { api.putUserTokens(userId, userTokens) }
|
||||
}
|
||||
|
||||
fun addHeaderInterceptors(interceptors: List<AddHeaderInterceptor>) {
|
||||
headerInterceptors.removeAll(interceptors)
|
||||
headerInterceptors.addAll(interceptors)
|
||||
|
|
@ -65,7 +72,7 @@ class TangemTechService {
|
|||
val retrofit = createRetrofitInstance(
|
||||
baseUrl = baseUrl,
|
||||
interceptors = headerInterceptors.toList(),
|
||||
// logEnabled = true,
|
||||
logEnabled = true,
|
||||
)
|
||||
return retrofit.create(TangemTechApi::class.java)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue