Skip to content

Commit 7dc6e9b

Browse files
authored
Merge pull request #206 from code-payments/chore/localize-partial-exchange-messages-in-provided-currency
fix(currency): format partial exchange messages in provided currency
2 parents 54a5fde + 3b69147 commit 7dc6e9b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

api/src/main/java/com/getcode/utils/FormatUtils.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.getcode.utils
22

3+
import com.getcode.model.CurrencyCode
34
import com.getcode.model.Kin
45
import java.text.NumberFormat
56
import java.util.*
@@ -21,4 +22,11 @@ object FormatUtils {
2122
fun formatCurrency(value: Double, locale: Locale): String =
2223
NumberFormat.getCurrencyInstance(locale).format(value)
2324

25+
fun formatCurrency(value: Double, currencyCode: CurrencyCode): String {
26+
val locale = NumberFormat.getAvailableLocales().firstOrNull {
27+
NumberFormat.getCurrencyInstance(it).currency?.currencyCode == currencyCode.name
28+
} ?: Locale.getDefault()
29+
30+
return formatCurrency(value, locale)
31+
}
2432
}

app/src/main/java/com/getcode/ui/components/chat/utils/LocalizedText.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal fun MessageContent.localizedText(resources: ResourceHelper, currencyUti
3232

3333
is GenericAmount.Partial -> {
3434
Timber.d("partial")
35-
FormatUtils.formatCurrency(kinAmount.fiat.amount, Locale.getDefault()).let {
35+
FormatUtils.formatCurrency(kinAmount.fiat.amount, kinAmount.currencyCode).let {
3636
"$it ${resources.getString(R.string.core_ofKin)}"
3737
}
3838
}
@@ -85,7 +85,7 @@ internal val MessageContent.localizedText: String
8585
}
8686

8787
is GenericAmount.Partial -> {
88-
FormatUtils.formatCurrency(kinAmount.fiat.amount, Locale.getDefault()).let {
88+
FormatUtils.formatCurrency(kinAmount.fiat.amount, kinAmount.currencyCode).let {
8989
"$it ${context.getString(R.string.core_ofKin)}"
9090
}
9191
}

0 commit comments

Comments
 (0)