Skip to content

fix: Update server config not working #2435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package com.mifos.core.datastore

import com.mifos.core.common.utils.ServerConfig
import com.mifos.core.common.utils.getInstanceUrl
import com.mifos.core.datastore.model.AppSettings
import com.mifos.core.datastore.model.AppTheme
import com.mifos.core.datastore.model.UserData
Expand Down Expand Up @@ -108,6 +109,8 @@ class UserPreferencesDataSource(
val token: String
get() = _userData.value.base64EncodedAuthenticationKey?.let { "Basic $it" } ?: ""

val instanceUrl: String get() = _serverConfig.value.getInstanceUrl()

fun updateUserStatus(status: Boolean) {
settings.putBoolean(USER_STATUS, status)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ interface UserPreferencesRepository {
val userInfo: Flow<UserData>
val userData: Flow<User>
val settingsInfo: Flow<AppSettings>
val serverConfig: Flow<ServerConfig>
val token: String?
val instanceUrl: String
val appTheme: StateFlow<AppTheme>
val getServerConfig: StateFlow<ServerConfig>

suspend fun updateUser(user: User): DataState<Unit>
suspend fun updateUserStatus(status: Boolean): DataState<Unit>
Expand All @@ -37,6 +38,4 @@ interface UserPreferencesRepository {
suspend fun updateUserInfo(user: UserData): DataState<Unit>

suspend fun updateTheme(theme: AppTheme): DataState<Unit>

val getServerConfig: StateFlow<ServerConfig>
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ class UserPreferencesRepositoryImpl(
override val userData: Flow<User>
get() = preferenceManager.userData

override val serverConfig: Flow<ServerConfig>
get() = preferenceManager.serverConfig

override val appTheme: StateFlow<AppTheme>
get() = preferenceManager.appTheme.stateIn(
scope = unconfinedScope,
Expand All @@ -64,6 +61,9 @@ class UserPreferencesRepositoryImpl(
override val token: String?
get() = preferenceManager.token

override val instanceUrl: String
get() = preferenceManager.instanceUrl

override suspend fun updateTheme(theme: AppTheme): DataState<Unit> {
return try {
val result = preferenceManager.updateTheme(theme)
Expand Down Expand Up @@ -94,11 +94,7 @@ class UserPreferencesRepositoryImpl(
}

override val getServerConfig: StateFlow<ServerConfig>
get() = preferenceManager.serverConfig.stateIn(
scope = unconfinedScope,
initialValue = ServerConfig.DEFAULT,
started = SharingStarted.Eagerly,
)
get() = preferenceManager.serverConfig

override suspend fun updateUser(user: User): DataState<Unit> {
return withContext(ioDispatcher) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package com.mifos.core.network.di
import com.mifos.core.common.utils.getInstanceUrl
import com.mifos.core.datastore.UserPreferencesRepository
import com.mifos.core.network.BaseApiManager
import com.mifos.core.network.BaseUrl
import com.mifos.core.network.KtorHttpClient
import com.mifos.core.network.KtorfitClient
import com.mifos.core.network.MifosInterceptor
Expand All @@ -24,7 +23,9 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.koin.core.qualifier.named
import org.koin.dsl.module
import kotlin.coroutines.EmptyCoroutineContext.get

val NetworkModule = module {
single<HttpClient>(KtorClient) {
Expand All @@ -38,10 +39,16 @@ val NetworkModule = module {
}
}

single<String>(named("baseUrl")) {
val preferencesRepository = get<UserPreferencesRepository>()
preferencesRepository.instanceUrl
}

single<KtorfitClient>(MifosClient) {

KtorfitClient.builder()
.httpClient(get(KtorClient))
.baseURL(BaseUrl().url)
.baseURL(get<String>(named("baseUrl")))
.build()
}

Expand All @@ -51,7 +58,7 @@ val NetworkModule = module {

single<Ktorfit> {
Ktorfit.Builder()
.baseUrl(BaseUrl().url)
.baseUrl(get<String>(named("baseUrl")))
.httpClient(get<HttpClient>(KtorClient))
.converterFactories(FlowConverterFactory())
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class UpdateServerConfigViewModel(
).any { it.value != null }

if (!hasAnyError) {
prefManager.logOut()
prefManager.updateServerConfig(_state.value)
_result.emit(true)
}
Expand Down