Updated on 2026-08-14
This commit is contained in:
parent
2ffe05e93a
commit
f2b49df651
9 changed files with 53 additions and 27 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package com.tangem.datasource.api.common.config
|
||||
|
||||
typealias ApiConfigs = Set<@JvmSuppressWildcards ApiConfig>
|
||||
|
||||
/**
|
||||
* Api config
|
||||
*
|
||||
|
|
@ -36,8 +38,5 @@ sealed class ApiConfig {
|
|||
internal const val MOCKED_BUILD_TYPE = "mocked"
|
||||
internal const val EXTERNAL_BUILD_TYPE = "external"
|
||||
internal const val RELEASE_BUILD_TYPE = "release"
|
||||
|
||||
/** All api configs */
|
||||
fun values() = listOf(Express(), TangemTech())
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.datasource.api.common.config.managers
|
||||
|
||||
import com.tangem.datasource.api.common.config.ApiConfig
|
||||
import com.tangem.datasource.api.common.config.ApiConfigs
|
||||
import com.tangem.datasource.api.common.config.ApiEnvironment
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
|
|
@ -12,17 +13,19 @@ import kotlinx.coroutines.flow.*
|
|||
/**
|
||||
* Implementation of [ApiConfigsManager] in DEV environment
|
||||
*
|
||||
* @param apiConfigs api configs
|
||||
* @property appPreferencesStore app preferences store
|
||||
* @property dispatchers coroutine dispatcher provider
|
||||
*/
|
||||
internal class DevApiConfigsManager(
|
||||
apiConfigs: ApiConfigs,
|
||||
private val appPreferencesStore: AppPreferencesStore,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) : MutableApiConfigsManager {
|
||||
|
||||
override val configs: Flow<Map<ApiConfig, ApiEnvironment>> get() = _apiConfigs
|
||||
|
||||
private val _apiConfigs = MutableStateFlow(value = ApiConfig.values().associateWith { it.defaultEnvironment })
|
||||
private val _apiConfigs = MutableStateFlow(value = apiConfigs.associateWith { it.defaultEnvironment })
|
||||
|
||||
override suspend fun initialize() {
|
||||
// We can't use appPreferencesStore.getObjectMap as base flow,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
package com.tangem.datasource.api.common.config.managers
|
||||
|
||||
import com.tangem.datasource.api.common.config.ApiConfig
|
||||
import com.tangem.datasource.api.common.config.ApiConfigs
|
||||
|
||||
/** Implementation of [ApiConfigsManager] in PROD environment */
|
||||
internal class ProdApiConfigsManager : ApiConfigsManager {
|
||||
/**
|
||||
* Implementation of [ApiConfigsManager] in PROD environment
|
||||
*
|
||||
* @property apiConfigs api configs
|
||||
*/
|
||||
internal class ProdApiConfigsManager(
|
||||
private val apiConfigs: ApiConfigs,
|
||||
) : ApiConfigsManager {
|
||||
|
||||
override fun getBaseUrl(id: ApiConfig.ID): String {
|
||||
val config = ApiConfig.values().firstOrNull { it.id == id }
|
||||
val config = apiConfigs.firstOrNull { it.id == id }
|
||||
?: error("Api config with id [$id] not found. Check ApiConfig implementations")
|
||||
|
||||
return config.environments[config.defaultEnvironment]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.tangem.datasource.di
|
||||
|
||||
import com.tangem.datasource.api.common.config.ApiConfig
|
||||
import com.tangem.datasource.api.common.config.Express
|
||||
import com.tangem.datasource.api.common.config.TangemTech
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import dagger.multibindings.IntoSet
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal object ApiConfigsModule {
|
||||
|
||||
@Provides
|
||||
@IntoSet
|
||||
fun provideExpressConfig(): ApiConfig = Express()
|
||||
|
||||
@Provides
|
||||
@IntoSet
|
||||
fun provideTangemTechConfig(): ApiConfig = TangemTech()
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import com.squareup.moshi.Moshi
|
||||
import com.tangem.datasource.BuildConfig
|
||||
import com.tangem.datasource.api.common.config.ApiConfig
|
||||
import com.tangem.datasource.api.common.config.ApiConfigs
|
||||
import com.tangem.datasource.api.common.config.managers.ApiConfigsManager
|
||||
import com.tangem.datasource.api.common.config.managers.DevApiConfigsManager
|
||||
import com.tangem.datasource.api.common.config.managers.ProdApiConfigsManager
|
||||
|
|
@ -42,13 +43,14 @@ class NetworkModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun provideApiConfigManager(
|
||||
apiConfigs: ApiConfigs,
|
||||
appPreferencesStore: AppPreferencesStore,
|
||||
dispatchers: CoroutineDispatcherProvider,
|
||||
): ApiConfigsManager {
|
||||
return if (BuildConfig.TESTER_MENU_ENABLED) {
|
||||
DevApiConfigsManager(appPreferencesStore, dispatchers)
|
||||
DevApiConfigsManager(apiConfigs, appPreferencesStore, dispatchers)
|
||||
} else {
|
||||
ProdApiConfigsManager()
|
||||
ProdApiConfigsManager(apiConfigs)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue