Updated on 2026-08-14

This commit is contained in:
Tangem 2023-11-09 14:42:49 +02:00
parent 26b3c3d576
commit 95f66c8798
18 changed files with 89 additions and 64 deletions

View file

@ -6,7 +6,6 @@ import com.tangem.datasource.api.express.models.request.PairsRequestBody
import com.tangem.datasource.api.express.models.response.*
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.Query
import java.math.BigDecimal
@ -15,12 +14,10 @@ import java.math.BigDecimal
* Interface of Tangem Express API (new swap mechanism)
*/
@Suppress("LongParameterList")
interface ExpressApi {
interface TangemExpressApi {
@POST("assets")
suspend fun getAssets(
@Body body: AssetsRequestBody,
): ApiResponse<List<Asset>>
suspend fun getAssets(@Body body: AssetsRequestBody): ApiResponse<List<Asset>>
@POST("pairs")
suspend fun getPairs(@Body body: PairsRequestBody): ApiResponse<List<SwapPair>>

View file

@ -0,0 +1,5 @@
package com.tangem.datasource.api.express.models
object TangemExpressValues {
const val EMPTY_CONTRACT_ADDRESS_VALUE = "0"
}

View file

@ -3,5 +3,6 @@ package com.tangem.datasource.api.express.models.request
import com.squareup.moshi.Json
data class AssetsRequestBody(
@Json(name = "filter") val filter: List<LeastTokenInfo>?,
@Json(name = "tokensList") val tokensList: List<LeastTokenInfo>?,
@Json(name = "onlyActive") val onlyActive: Boolean,
)

View file

@ -106,7 +106,7 @@ internal class ConfigManagerImpl @Inject constructor() : ConfigManager {
swapReferrerAccount = configValues.swapReferrerAccount,
walletConnectProjectId = configValues.walletConnectProjectId,
tangemComAuthorization = configValues.tangemComAuthorization,
tangemExpressApiKey = configValues.tangemExpressApiKey
tangemExpressApiKey = configValues.tangemExpressApiKey,
)
}
}

View file

@ -19,5 +19,5 @@ data class Config(
val swapReferrerAccount: SwapReferrerAccount? = null,
val walletConnectProjectId: String = "",
val tangemComAuthorization: String? = null,
val tangemExpressApiKey: String = ""
val tangemExpressApiKey: String = "",
)

View file

@ -1,8 +1,8 @@
package com.tangem.datasource.di
import com.tangem.datasource.local.datastore.RuntimeDataStore
import com.tangem.datasource.local.token.DefaultUserMarketCoinsStore
import com.tangem.datasource.local.token.UserMarketCoinsStore
import com.tangem.datasource.local.token.DefaultAssetsStore
import com.tangem.datasource.local.token.AssetsStore
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@ -11,11 +11,11 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
internal object MarketCoinsStoreModule {
internal object AssetsStoreModule {
@Provides
@Singleton
fun provideUserMarketCoinsStore(): UserMarketCoinsStore {
return DefaultUserMarketCoinsStore(dataStore = RuntimeDataStore())
fun provideAssetsStore(): AssetsStore {
return DefaultAssetsStore(dataStore = RuntimeDataStore())
}
}

View file

@ -3,10 +3,9 @@ package com.tangem.datasource.di
import android.content.Context
import com.squareup.moshi.Moshi
import com.tangem.datasource.api.common.response.ApiResponseCallAdapterFactory
import com.tangem.datasource.api.express.ExpressApi
import com.tangem.datasource.api.express.TangemExpressApi
import com.tangem.datasource.api.promotion.PromotionApi
import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.utils.RequestHeader
import com.tangem.datasource.utils.RequestHeader.*
import com.tangem.datasource.utils.addHeaders
import com.tangem.datasource.utils.addLoggers
@ -33,8 +32,7 @@ class NetworkModule {
@NetworkMoshi moshi: Moshi,
@ApplicationContext context: Context,
expressAuthProvider: ExpressAuthProvider,
): ExpressApi {
): TangemExpressApi {
return Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(ApiResponseCallAdapterFactory.create())
@ -46,7 +44,7 @@ class NetworkModule {
.build(),
)
.build()
.create(ExpressApi::class.java)
.create(TangemExpressApi::class.java)
}
@Provides

View file

@ -0,0 +1,11 @@
package com.tangem.datasource.local.token
import com.tangem.datasource.api.express.models.response.Asset
import com.tangem.domain.wallets.models.UserWalletId
interface AssetsStore {
suspend fun getSyncOrNull(userWalletId: UserWalletId): List<Asset>?
suspend fun store(userWalletId: UserWalletId, item: List<Asset>)
}

View file

@ -1,18 +1,18 @@
package com.tangem.datasource.local.token
import com.tangem.datasource.api.tangemTech.models.CoinsResponse
import com.tangem.datasource.api.express.models.response.Asset
import com.tangem.datasource.local.datastore.core.StringKeyDataStore
import com.tangem.domain.wallets.models.UserWalletId
internal class DefaultUserMarketCoinsStore(
private val dataStore: StringKeyDataStore<CoinsResponse>,
) : UserMarketCoinsStore {
internal class DefaultAssetsStore(
private val dataStore: StringKeyDataStore<List<Asset>>,
) : AssetsStore {
override suspend fun getSyncOrNull(userWalletId: UserWalletId): CoinsResponse? {
override suspend fun getSyncOrNull(userWalletId: UserWalletId): List<Asset>? {
return dataStore.getSyncOrNull(userWalletId.stringValue)
}
override suspend fun store(userWalletId: UserWalletId, item: CoinsResponse) {
override suspend fun store(userWalletId: UserWalletId, item: List<Asset>) {
dataStore.store(userWalletId.stringValue, item)
}
}

View file

@ -1,11 +0,0 @@
package com.tangem.datasource.local.token
import com.tangem.datasource.api.tangemTech.models.CoinsResponse
import com.tangem.domain.wallets.models.UserWalletId
interface UserMarketCoinsStore {
suspend fun getSyncOrNull(userWalletId: UserWalletId): CoinsResponse?
suspend fun store(userWalletId: UserWalletId, item: CoinsResponse)
}

View file

@ -20,9 +20,9 @@ sealed class RequestHeader(vararg pairs: Pair<String, () -> String>) {
"card_public_key" to { authProvider.getCardPublicKey() },
)
class Express(expressAuthProvider: ExpressAuthProvider): RequestHeader(
class Express(expressAuthProvider: ExpressAuthProvider) : RequestHeader(
"api-key" to { expressAuthProvider.getApiKey() },
"user-id" to { expressAuthProvider.getUserId() },
"session-id" to { expressAuthProvider.getSessionId() }
"session-id" to { expressAuthProvider.getSessionId() },
)
}