Skip to content

Commit

Permalink
[#1315] Provide Locale to MonetarySeparators API
Browse files Browse the repository at this point in the history
Closes #1315
  • Loading branch information
HonzaR authored Jan 8, 2024
1 parent 68cfd21 commit 685ae66
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- `TransactionOverview.txIdString()` to provide a readable transaction ID to SDK-consuming apps
- `MonetarySeparators.current(locale: Locale? = null)` now accepts `Locale` on input to force separators locale. If
no value is provided, the default one is used.

### Removed
- `LightWalletEndpointExt` and its functions and variables were removed from the SDK's public APIs entirely. It's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import cash.z.ecc.android.sdk.model.ZecSendExt
import cash.z.ecc.android.sdk.model.ZecString
import cash.z.ecc.android.sdk.model.ZecStringExt
import cash.z.ecc.android.sdk.model.toZecString
import java.util.Locale

@Preview(name = "Send")
@Composable
Expand Down Expand Up @@ -112,7 +113,7 @@ private fun SendMainContent(
onSend: (ZecSend) -> Unit
) {
val context = LocalContext.current
val monetarySeparators = MonetarySeparators.current()
val monetarySeparators = MonetarySeparators.current(locale = Locale.US)
val allowedCharacters = ZecString.allowedCharacters(monetarySeparators)

var amountZecString by rememberSaveable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ data class MonetarySeparators(val grouping: Char, val decimal: Char) {

companion object {
/**
* @param locale Preferred Locale for the returned monetary separators. If Locale is not provided, the
* default one will be used.
*
* @return The current localized monetary separators. Do not cache this value, as it
* can change if the system Locale changes.
*/
fun current(): MonetarySeparators {
val decimalFormatSymbols = DecimalFormatSymbols.getInstance()
fun current(locale: Locale? = null): MonetarySeparators {
val decimalFormatSymbols =
locale?.let {
DecimalFormatSymbols.getInstance(locale)
} ?: DecimalFormatSymbols.getInstance()

return MonetarySeparators(
decimalFormatSymbols.groupingSeparator,
Expand Down Expand Up @@ -83,7 +89,6 @@ fun Zatoshi.Companion.fromZecString(
}
val localizedPattern = "#${monetarySeparators.grouping}##0${monetarySeparators.decimal}0#"

// TODO [#321]: https://github.com/zcash/secant-android-wallet/issues/321
val decimalFormat =
DecimalFormat(localizedPattern, symbols).apply {
isParseBigDecimal = true
Expand Down

0 comments on commit 685ae66

Please sign in to comment.