Updated on 2026-08-14
This commit is contained in:
parent
c43f3b8059
commit
3cd6e47a5d
10 changed files with 254 additions and 225 deletions
|
|
@ -0,0 +1,31 @@
|
|||
package com.tangem.feature.tester.presentation.environments.utils
|
||||
|
||||
import com.tangem.datasource.api.common.config.ApiEnvironment
|
||||
import com.tangem.datasource.api.common.config.ApiEnvironmentConfig
|
||||
|
||||
/**
|
||||
* Comparator for [ApiEnvironmentConfig] based on the priority of [ApiEnvironment].
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal object ApiEnvironmentComparator : Comparator<ApiEnvironmentConfig> {
|
||||
|
||||
private val apiEnvironmentPriorityMap = ApiEnvironment.entries.associateWith {
|
||||
when (it) {
|
||||
ApiEnvironment.DEV -> 0
|
||||
ApiEnvironment.STAGE -> 1
|
||||
ApiEnvironment.PROD -> 2
|
||||
}
|
||||
}
|
||||
|
||||
override fun compare(o1: ApiEnvironmentConfig, o2: ApiEnvironmentConfig): Int {
|
||||
val priority1: Int = getPriority(environment = o1.environment)
|
||||
val priority2: Int = getPriority(environment = o2.environment)
|
||||
|
||||
return priority1.compareTo(priority2)
|
||||
}
|
||||
|
||||
private fun getPriority(environment: ApiEnvironment): Int {
|
||||
return apiEnvironmentPriorityMap[environment] ?: error("Unknown environment: $environment")
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import com.tangem.domain.card.repository.CardSdkConfigRepository
|
|||
import com.tangem.feature.tester.impl.BuildConfig
|
||||
import com.tangem.feature.tester.impl.R
|
||||
import com.tangem.feature.tester.presentation.environments.state.EnvironmentTogglesScreenUM
|
||||
import com.tangem.feature.tester.presentation.environments.utils.ApiEnvironmentComparator
|
||||
import com.tangem.feature.tester.presentation.navigation.InnerTesterRouter
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.collections.immutable.ImmutableSet
|
||||
|
|
@ -76,6 +77,7 @@ internal class EnvironmentsTogglesViewModel @Inject constructor(
|
|||
url = config.environmentConfigs.firstOrNull { it.environment == currentEnvironment }?.baseUrl
|
||||
?: error("Current environment's url isn't found"),
|
||||
environments = config.environmentConfigs
|
||||
.sortedWith(ApiEnvironmentComparator)
|
||||
.map { environmentConfig -> environmentConfig.environment.name }
|
||||
.toImmutableSet(),
|
||||
)
|
||||
|
|
@ -96,22 +98,22 @@ internal class EnvironmentsTogglesViewModel @Inject constructor(
|
|||
viewModelScope.launch {
|
||||
val environment = ApiEnvironment.valueOf(name)
|
||||
|
||||
handleIfAttestationConfig(id = id, environment = environment)
|
||||
if (id == ApiConfig.ID.TangemTech.name) {
|
||||
handleTangemTechConfig(environment = environment)
|
||||
}
|
||||
|
||||
mutableApiConfigsManager.changeEnvironment(id = id, environment = environment)
|
||||
}
|
||||
}
|
||||
|
||||
/** Special logic for [ApiConfig.ID.Attestation] */
|
||||
private fun handleIfAttestationConfig(id: String, environment: ApiEnvironment) {
|
||||
if (id == ApiConfig.ID.Attestation.name) {
|
||||
cardSdkConfigRepository.setTangemApiProdEnvFlag(
|
||||
flag = when (environment) {
|
||||
ApiEnvironment.PROD -> true
|
||||
ApiEnvironment.DEV -> false
|
||||
else -> false
|
||||
},
|
||||
)
|
||||
}
|
||||
/** Special logic for [ApiConfig.ID.TangemTech] */
|
||||
private fun handleTangemTechConfig(environment: ApiEnvironment) {
|
||||
cardSdkConfigRepository.setTangemApiProdEnvFlag(
|
||||
flag = when (environment) {
|
||||
ApiEnvironment.PROD -> true
|
||||
ApiEnvironment.DEV -> false
|
||||
ApiEnvironment.STAGE -> false
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue