Skip to content

Commit 47aeaf9

Browse files
committed
chore(settings): update user "region" to reflect balance currency
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent c46d817 commit 47aeaf9

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

apps/flipcash/shared/currency-selection/core/src/main/kotlin/com/flipcash/app/currency/PreferredCurrencyController.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.datastore.preferences.core.stringPreferencesKey
1010
import androidx.datastore.preferences.core.stringSetPreferencesKey
1111
import androidx.datastore.preferences.preferencesDataStoreFile
1212
import com.flipcash.app.core.money.RegionSelectionKind
13+
import com.flipcash.services.controllers.SettingsController
1314
import com.flipcash.services.user.UserManager
1415
import com.getcode.opencode.exchange.Exchange
1516
import com.getcode.opencode.model.financial.Currency
@@ -36,6 +37,7 @@ class PreferredCurrencyController @Inject constructor(
3637
private val locale: LocaleHelper,
3738
private val userManager: UserManager,
3839
private val exchange: Exchange,
40+
private val settingsController: SettingsController,
3941
) {
4042
companion object {
4143
fun initializedKeyForUser(userIdentifier: String) =
@@ -140,6 +142,7 @@ class PreferredCurrencyController @Inject constructor(
140142
val code = CurrencyCode.tryValueOf(currency.code)
141143
if (code != null) {
142144
exchange.setPreferredBalanceCurrency(code)
145+
settingsController.update()
143146
}
144147
}
145148
}

services/flipcash/src/main/kotlin/com/flipcash/services/controllers/SettingsController.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,31 @@ package com.flipcash.services.controllers
22

33
import com.flipcash.services.repository.SettingsRepository
44
import com.flipcash.services.user.UserManager
5+
import com.getcode.opencode.exchange.Exchange
56
import com.getcode.util.locale.LocaleHelper
7+
import com.getcode.utils.trace
68
import javax.inject.Inject
79

810
class SettingsController @Inject constructor(
911
private val repository: SettingsRepository,
1012
private val localeHelper: LocaleHelper,
1113
private val userManager: UserManager,
14+
private val exchange: Exchange,
1215
) {
1316
suspend fun update(): Result<Unit> {
1417
val locale = localeHelper.getLanguageTag()
15-
val region = localeHelper.getDefaultCurrencyName()
16-
17-
println("locale=$locale, region=$region")
18+
val currencyRegion = exchange.balanceRate.currency
1819
val owner = userManager.accountCluster?.authority?.keyPair
1920
?: return Result.failure(Throwable("No account cluster in UserManager"))
2021

21-
return repository.update(locale, region, owner)
22+
trace(
23+
tag = "Settings",
24+
message = "Updating settings",
25+
metadata = {
26+
"locale" to locale
27+
"region" to currencyRegion.name
28+
}
29+
)
30+
return repository.update(locale, currencyRegion.name, owner)
2231
}
2332
}

0 commit comments

Comments
 (0)