Updated on 2026-08-14
This commit is contained in:
parent
cf182832db
commit
ae979f60cd
11 changed files with 110 additions and 65 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.domain.settings.repositories
|
||||
|
||||
import com.tangem.domain.settings.usercountry.models.UserCountry
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
interface SettingsRepository {
|
||||
|
|
@ -39,6 +40,8 @@ interface SettingsRepository {
|
|||
|
||||
suspend fun getUserCountryCodeSync(): UserCountry?
|
||||
|
||||
fun getUserCountryCode(): StateFlow<UserCountry?>
|
||||
|
||||
suspend fun fetchUserCountryCode()
|
||||
|
||||
suspend fun setGoogleServicesAvailability(value: Boolean)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import arrow.core.raise.ensureNotNull
|
|||
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||
import com.tangem.domain.settings.usercountry.models.UserCountry
|
||||
import com.tangem.domain.settings.usercountry.models.UserCountryError
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
/**
|
||||
* Get user country code use case
|
||||
|
|
@ -19,7 +21,17 @@ class GetUserCountryUseCase(
|
|||
private val settingsRepository: SettingsRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(): Either<UserCountryError, UserCountry> {
|
||||
operator fun invoke(): Flow<Either<UserCountryError, UserCountry>> {
|
||||
return settingsRepository.getUserCountryCode().map { userCountryCode ->
|
||||
either {
|
||||
ensureNotNull(userCountryCode) { UserCountryError.NotSetup }
|
||||
|
||||
userCountryCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun invokeSync(): Either<UserCountryError, UserCountry> {
|
||||
return either {
|
||||
val userCountryCode = catch(
|
||||
block = { settingsRepository.getUserCountryCodeSync() },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue