From 813844e25f684ec9ec061fe748f09fcf516ff244 Mon Sep 17 00:00:00 2001 From: itsPronay Date: Fri, 11 Jul 2025 01:16:02 +0600 Subject: [PATCH 1/8] fixed: update server config not working --- .../core/datastore/UserPreferencesRepository.kt | 3 +-- .../core/datastore/UserPreferencesRepositoryImpl.kt | 12 ++++-------- .../kotlin/com/mifos/core/network/KtorfitClient.kt | 1 + .../com/mifos/core/network/di/NetworkModule.kt | 2 ++ .../com/mifos/feature/auth/login/LoginViewModel.kt | 1 + .../updateServer/UpdateServerConfigViewModel.kt | 3 +++ 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt index 1ed6bf2db7f..2e4beab5e86 100644 --- a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt +++ b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt @@ -22,9 +22,9 @@ interface UserPreferencesRepository { val userInfo: Flow val userData: Flow val settingsInfo: Flow - val serverConfig: Flow val token: String? val appTheme: StateFlow + val getServerConfig: StateFlow suspend fun updateUser(user: User): DataState suspend fun updateUserStatus(status: Boolean): DataState @@ -38,5 +38,4 @@ interface UserPreferencesRepository { suspend fun updateTheme(theme: AppTheme): DataState - val getServerConfig: StateFlow } diff --git a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt index 03502528354..93a07087e20 100644 --- a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt +++ b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt @@ -9,6 +9,7 @@ */ package com.mifos.core.datastore +import co.touchlab.kermit.Logger import com.mifos.core.common.utils.DataState import com.mifos.core.common.utils.ServerConfig import com.mifos.core.datastore.model.AppSettings @@ -17,10 +18,12 @@ import com.mifos.core.datastore.model.UserData import com.mifos.core.model.objects.users.User import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.launch import kotlinx.coroutines.withContext class UserPreferencesRepositoryImpl( @@ -40,9 +43,6 @@ class UserPreferencesRepositoryImpl( override val userData: Flow get() = preferenceManager.userData - override val serverConfig: Flow - get() = preferenceManager.serverConfig - override val appTheme: StateFlow get() = preferenceManager.appTheme.stateIn( scope = unconfinedScope, @@ -94,11 +94,7 @@ class UserPreferencesRepositoryImpl( } override val getServerConfig: StateFlow - get() = preferenceManager.serverConfig.stateIn( - scope = unconfinedScope, - initialValue = ServerConfig.DEFAULT, - started = SharingStarted.Eagerly, - ) + get() = preferenceManager.serverConfig override suspend fun updateUser(user: User): DataState { return withContext(ioDispatcher) { diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/KtorfitClient.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/KtorfitClient.kt index 63e9a32e376..08b1de1a152 100644 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/KtorfitClient.kt +++ b/core/network/src/commonMain/kotlin/com/mifos/core/network/KtorfitClient.kt @@ -21,6 +21,7 @@ class KtorfitClient( private lateinit var httpClient: HttpClient fun baseURL(baseURL: String): Builder { + this.baseURL = baseURL return this } diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt index 6dc889a0264..40ba6a5c3b3 100644 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt +++ b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt @@ -9,6 +9,7 @@ */ package com.mifos.core.network.di +import co.touchlab.kermit.Logger import com.mifos.core.common.utils.getInstanceUrl import com.mifos.core.datastore.UserPreferencesRepository import com.mifos.core.network.BaseApiManager @@ -63,6 +64,7 @@ val NetworkModule = module { CoroutineScope(Dispatchers.Default).launch { val user = prefManager.userData.first() val serverConfig = prefManager.getServerConfig.first() + Logger.e("serverConfigPro $serverConfig") baseManager.createService( user.username ?: "", user.password ?: "", diff --git a/feature/auth/src/commonMain/kotlin/com/mifos/feature/auth/login/LoginViewModel.kt b/feature/auth/src/commonMain/kotlin/com/mifos/feature/auth/login/LoginViewModel.kt index f7d138676b3..3d64a8b7dcf 100644 --- a/feature/auth/src/commonMain/kotlin/com/mifos/feature/auth/login/LoginViewModel.kt +++ b/feature/auth/src/commonMain/kotlin/com/mifos/feature/auth/login/LoginViewModel.kt @@ -23,6 +23,7 @@ import com.mifos.core.domain.useCases.PasswordValidationUseCase import com.mifos.core.domain.useCases.UsernameValidationUseCase import com.mifos.core.model.objects.users.User import com.mifos.core.network.model.PostAuthenticationResponse +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow diff --git a/feature/settings/src/commonMain/kotlin/com/mifos/feature/settings/updateServer/UpdateServerConfigViewModel.kt b/feature/settings/src/commonMain/kotlin/com/mifos/feature/settings/updateServer/UpdateServerConfigViewModel.kt index 06db9d52b9c..f2b9bbd7fe1 100644 --- a/feature/settings/src/commonMain/kotlin/com/mifos/feature/settings/updateServer/UpdateServerConfigViewModel.kt +++ b/feature/settings/src/commonMain/kotlin/com/mifos/feature/settings/updateServer/UpdateServerConfigViewModel.kt @@ -14,9 +14,11 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.snapshotFlow import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import co.touchlab.kermit.Logger import com.mifos.core.common.utils.ServerConfig import com.mifos.core.datastore.UserPreferencesRepository import com.mifos.core.domain.useCases.ServerConfigValidatorUseCase +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.asSharedFlow @@ -119,6 +121,7 @@ class UpdateServerConfigViewModel( ).any { it.value != null } if (!hasAnyError) { + prefManager.logOut() prefManager.updateServerConfig(_state.value) _result.emit(true) } From e20dcf8760f26a04172a49abab93614c17aa53b1 Mon Sep 17 00:00:00 2001 From: itsPronay Date: Fri, 11 Jul 2025 02:36:21 +0600 Subject: [PATCH 2/8] update --- .../kotlin/com/mifos/core/network/BaseUrl.kt | 28 ------------------- .../mifos/core/network/di/NetworkModule.kt | 22 ++++++++++++--- 2 files changed, 18 insertions(+), 32 deletions(-) delete mode 100644 core/network/src/commonMain/kotlin/com/mifos/core/network/BaseUrl.kt diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/BaseUrl.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/BaseUrl.kt deleted file mode 100644 index 02d082f3f46..00000000000 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/BaseUrl.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.core.network - -class BaseUrl { - val url: String - get() = PROTOCOL_HTTPS + API_ENDPOINT + API_PATH - - val defaultBaseUrl: String - get() = PROTOCOL_HTTPS + API_ENDPOINT - - fun getUrl(endpoint: String): String { - return endpoint + API_PATH - } - - companion object { - const val API_ENDPOINT = "tt.mifos.community" - const val API_PATH = "/fineract-provider/api/v1/" - const val PROTOCOL_HTTPS = "https://" - } -} diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt index 40ba6a5c3b3..9ffb53e9c7e 100644 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt +++ b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt @@ -13,7 +13,6 @@ import co.touchlab.kermit.Logger 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 @@ -25,6 +24,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import org.koin.dsl.module val NetworkModule = module { @@ -40,9 +40,16 @@ val NetworkModule = module { } single(MifosClient) { + val preferencesRepository = get() + + val serverConfigUrl = runBlocking { + val serverConfig = preferencesRepository.getServerConfig.first() + serverConfig.getInstanceUrl() + } + KtorfitClient.builder() .httpClient(get(KtorClient)) - .baseURL(BaseUrl().url) + .baseURL(serverConfigUrl) .build() } @@ -51,8 +58,15 @@ val NetworkModule = module { single { BaseApiManager(get(), get()) } single { + val preferencesRepository = get() + + val serverConfigUrl = runBlocking { + val serverConfig = preferencesRepository.getServerConfig.first() + serverConfig.getInstanceUrl() + } + Ktorfit.Builder() - .baseUrl(BaseUrl().url) + .baseUrl(serverConfigUrl) .httpClient(get(KtorClient)) .converterFactories(FlowConverterFactory()) .build() @@ -75,4 +89,4 @@ val NetworkModule = module { } baseManager } -} +} \ No newline at end of file From 1be76c34fe93e3ddeea1e07ad1c7a8810e3d1ede Mon Sep 17 00:00:00 2001 From: itsPronay Date: Fri, 11 Jul 2025 02:39:25 +0600 Subject: [PATCH 3/8] updated --- .../com/mifos/core/datastore/UserPreferencesRepository.kt | 1 - .../com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt | 3 --- .../commonMain/kotlin/com/mifos/core/network/KtorfitClient.kt | 1 - .../kotlin/com/mifos/core/network/di/NetworkModule.kt | 4 +--- .../kotlin/com/mifos/feature/auth/login/LoginViewModel.kt | 1 - .../settings/updateServer/UpdateServerConfigViewModel.kt | 2 -- 6 files changed, 1 insertion(+), 11 deletions(-) diff --git a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt index 2e4beab5e86..9b525ef4434 100644 --- a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt +++ b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt @@ -37,5 +37,4 @@ interface UserPreferencesRepository { suspend fun updateUserInfo(user: UserData): DataState suspend fun updateTheme(theme: AppTheme): DataState - } diff --git a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt index 93a07087e20..ff91374beb0 100644 --- a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt +++ b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt @@ -9,7 +9,6 @@ */ package com.mifos.core.datastore -import co.touchlab.kermit.Logger import com.mifos.core.common.utils.DataState import com.mifos.core.common.utils.ServerConfig import com.mifos.core.datastore.model.AppSettings @@ -18,12 +17,10 @@ import com.mifos.core.datastore.model.UserData import com.mifos.core.model.objects.users.User import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.stateIn -import kotlinx.coroutines.launch import kotlinx.coroutines.withContext class UserPreferencesRepositoryImpl( diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/KtorfitClient.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/KtorfitClient.kt index 08b1de1a152..63e9a32e376 100644 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/KtorfitClient.kt +++ b/core/network/src/commonMain/kotlin/com/mifos/core/network/KtorfitClient.kt @@ -21,7 +21,6 @@ class KtorfitClient( private lateinit var httpClient: HttpClient fun baseURL(baseURL: String): Builder { - this.baseURL = baseURL return this } diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt index 9ffb53e9c7e..8b28fec6067 100644 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt +++ b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt @@ -9,7 +9,6 @@ */ package com.mifos.core.network.di -import co.touchlab.kermit.Logger import com.mifos.core.common.utils.getInstanceUrl import com.mifos.core.datastore.UserPreferencesRepository import com.mifos.core.network.BaseApiManager @@ -78,7 +77,6 @@ val NetworkModule = module { CoroutineScope(Dispatchers.Default).launch { val user = prefManager.userData.first() val serverConfig = prefManager.getServerConfig.first() - Logger.e("serverConfigPro $serverConfig") baseManager.createService( user.username ?: "", user.password ?: "", @@ -89,4 +87,4 @@ val NetworkModule = module { } baseManager } -} \ No newline at end of file +} diff --git a/feature/auth/src/commonMain/kotlin/com/mifos/feature/auth/login/LoginViewModel.kt b/feature/auth/src/commonMain/kotlin/com/mifos/feature/auth/login/LoginViewModel.kt index 3d64a8b7dcf..f7d138676b3 100644 --- a/feature/auth/src/commonMain/kotlin/com/mifos/feature/auth/login/LoginViewModel.kt +++ b/feature/auth/src/commonMain/kotlin/com/mifos/feature/auth/login/LoginViewModel.kt @@ -23,7 +23,6 @@ import com.mifos.core.domain.useCases.PasswordValidationUseCase import com.mifos.core.domain.useCases.UsernameValidationUseCase import com.mifos.core.model.objects.users.User import com.mifos.core.network.model.PostAuthenticationResponse -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow diff --git a/feature/settings/src/commonMain/kotlin/com/mifos/feature/settings/updateServer/UpdateServerConfigViewModel.kt b/feature/settings/src/commonMain/kotlin/com/mifos/feature/settings/updateServer/UpdateServerConfigViewModel.kt index f2b9bbd7fe1..a9c1643990d 100644 --- a/feature/settings/src/commonMain/kotlin/com/mifos/feature/settings/updateServer/UpdateServerConfigViewModel.kt +++ b/feature/settings/src/commonMain/kotlin/com/mifos/feature/settings/updateServer/UpdateServerConfigViewModel.kt @@ -14,11 +14,9 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.snapshotFlow import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import co.touchlab.kermit.Logger import com.mifos.core.common.utils.ServerConfig import com.mifos.core.datastore.UserPreferencesRepository import com.mifos.core.domain.useCases.ServerConfigValidatorUseCase -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.asSharedFlow From e9c8dfeedc027fe7e8a96e3ab0ed698fe8919dba Mon Sep 17 00:00:00 2001 From: itsPronay Date: Fri, 11 Jul 2025 03:04:26 +0600 Subject: [PATCH 4/8] updated --- .../mifos/core/network/di/NetworkModule.kt | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt index 8b28fec6067..d52d5f62ebf 100644 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt +++ b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt @@ -24,7 +24,9 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +import org.koin.core.qualifier.named import org.koin.dsl.module +import kotlin.coroutines.EmptyCoroutineContext.get val NetworkModule = module { single(KtorClient) { @@ -38,17 +40,18 @@ val NetworkModule = module { } } - single(MifosClient) { + single(named("baseUrl")) { val preferencesRepository = get() - - val serverConfigUrl = runBlocking { - val serverConfig = preferencesRepository.getServerConfig.first() - serverConfig.getInstanceUrl() + runBlocking { + preferencesRepository.getServerConfig.first().getInstanceUrl() } + } + + single(MifosClient) { KtorfitClient.builder() .httpClient(get(KtorClient)) - .baseURL(serverConfigUrl) + .baseURL(get(named("baseUrl"))) .build() } @@ -57,15 +60,8 @@ val NetworkModule = module { single { BaseApiManager(get(), get()) } single { - val preferencesRepository = get() - - val serverConfigUrl = runBlocking { - val serverConfig = preferencesRepository.getServerConfig.first() - serverConfig.getInstanceUrl() - } - Ktorfit.Builder() - .baseUrl(serverConfigUrl) + .baseUrl(get(named("baseUrl"))) .httpClient(get(KtorClient)) .converterFactories(FlowConverterFactory()) .build() From 75b298186ff60b8fd256c3230ddb0767fb3258f5 Mon Sep 17 00:00:00 2001 From: itsPronay Date: Mon, 14 Jul 2025 20:41:00 +0600 Subject: [PATCH 5/8] update --- .../com/mifos/core/datastore/UserPreferencesDataSource.kt | 3 +++ .../com/mifos/core/datastore/UserPreferencesRepository.kt | 1 + .../mifos/core/datastore/UserPreferencesRepositoryImpl.kt | 3 +++ .../kotlin/com/mifos/core/network/di/NetworkModule.kt | 5 +---- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt index 7fb4717c8e7..eeae850e65c 100644 --- a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt @@ -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 @@ -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) } diff --git a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt index 9b525ef4434..220b3bf5600 100644 --- a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt +++ b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepository.kt @@ -23,6 +23,7 @@ interface UserPreferencesRepository { val userData: Flow val settingsInfo: Flow val token: String? + val instanceUrl: String val appTheme: StateFlow val getServerConfig: StateFlow diff --git a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt index ff91374beb0..c6340c3d188 100644 --- a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt +++ b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesRepositoryImpl.kt @@ -61,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 { return try { val result = preferenceManager.updateTheme(theme) diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt index d52d5f62ebf..62fd8a531d7 100644 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt +++ b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt @@ -23,7 +23,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import org.koin.core.qualifier.named import org.koin.dsl.module import kotlin.coroutines.EmptyCoroutineContext.get @@ -42,9 +41,7 @@ val NetworkModule = module { single(named("baseUrl")) { val preferencesRepository = get() - runBlocking { - preferencesRepository.getServerConfig.first().getInstanceUrl() - } + preferencesRepository.instanceUrl } single(MifosClient) { From 9b9bf19ff7fd362cb536a1cc67608393dae460d5 Mon Sep 17 00:00:00 2001 From: itsPronay Date: Wed, 16 Jul 2025 15:04:53 +0600 Subject: [PATCH 6/8] prefmanager clearInfo fix --- .../com/mifos/core/datastore/UserPreferencesDataSource.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt index eeae850e65c..1520f2abc37 100644 --- a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt @@ -145,7 +145,7 @@ class UserPreferencesDataSource( suspend fun clearInfo() { withContext(dispatcher) { - settings.clear() + settings.remove(AUTH_USER) } } From 9b4bea063daba52b2d13bb176d3dbf97e1f28446 Mon Sep 17 00:00:00 2001 From: itsPronay Date: Wed, 16 Jul 2025 15:10:41 +0600 Subject: [PATCH 7/8] added qualifier --- .../kotlin/com/mifos/core/network/di/NetworkModule.kt | 8 +++----- .../kotlin/com/mifos/core/network/di/Qualifier.kt | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt index 62fd8a531d7..346c02d4816 100644 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt +++ b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/NetworkModule.kt @@ -23,7 +23,6 @@ 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 @@ -39,16 +38,15 @@ val NetworkModule = module { } } - single(named("baseUrl")) { + single(BaseUrl) { val preferencesRepository = get() preferencesRepository.instanceUrl } single(MifosClient) { - KtorfitClient.builder() .httpClient(get(KtorClient)) - .baseURL(get(named("baseUrl"))) + .baseURL(get(BaseUrl)) .build() } @@ -58,7 +56,7 @@ val NetworkModule = module { single { Ktorfit.Builder() - .baseUrl(get(named("baseUrl"))) + .baseUrl(get(BaseUrl)) .httpClient(get(KtorClient)) .converterFactories(FlowConverterFactory()) .build() diff --git a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/Qualifier.kt b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/Qualifier.kt index 3b2c2f82517..5a63744d26d 100644 --- a/core/network/src/commonMain/kotlin/com/mifos/core/network/di/Qualifier.kt +++ b/core/network/src/commonMain/kotlin/com/mifos/core/network/di/Qualifier.kt @@ -13,3 +13,4 @@ import org.koin.core.qualifier.named val MifosClient = named("MifosClient") val KtorClient = named("KtorClient") +val BaseUrl = named("baseUrl") From 069665b08197085f1754f8a0c0d21b80af3db307 Mon Sep 17 00:00:00 2001 From: itsPronay Date: Wed, 16 Jul 2025 18:43:47 +0600 Subject: [PATCH 8/8] update --- .../core/datastore/UserPreferencesDataSource.kt | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt index 1520f2abc37..000c53dd79f 100644 --- a/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/com/mifos/core/datastore/UserPreferencesDataSource.kt @@ -31,8 +31,6 @@ private const val USER_DATA = "userData" private const val AUTH_USER = "user_details" private const val SERVER_CONFIG_KEY = "server_config" private const val USER_STATUS = "user_status" -private const val AUTH_USERNAME = "auth_username" -private const val AUTH_PASSWORD = "auth_password" private const val APP_SETTINGS = "appSettings" @OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) @@ -93,16 +91,6 @@ class UserPreferencesDataSource( val userStatus: Boolean get() = settings.getBoolean(USER_STATUS, false) - var usernamePassword: Pair - get() = Pair( - settings.getString(AUTH_USERNAME, "") ?: "", - settings.getString(AUTH_PASSWORD, "") ?: "", - ) - set(value) { - settings.putString(AUTH_USERNAME, value.first) - settings.putString(AUTH_PASSWORD, value.second) - } - val isAuthenticated: Boolean get() = _userData.value.isAuthenticated @@ -145,7 +133,7 @@ class UserPreferencesDataSource( suspend fun clearInfo() { withContext(dispatcher) { - settings.remove(AUTH_USER) + settings.putAuth(User()) } }