Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/java/to/bitkit/data/widgets/WeatherService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ class WeatherService @Inject constructor(
}

private fun formatFeeForDisplay(sats: Long): String {
val usdValue = currencyRepo.convertSatsToFiat(sats, USD).getOrNull()
return usdValue?.formatted.orEmpty()
val selectedFiatValue = currencyRepo.convertSatsToFiat(sats).getOrNull()
return selectedFiatValue?.formattedWithSymbol(withSpace = true).orEmpty()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ class NotifyPaymentReceivedHandler @Inject constructor(
val amountText = converted?.let {
val btcDisplay = it.bitcoinDisplay(settings.displayUnit)
if (settings.primaryDisplay == PrimaryDisplay.BITCOIN) {
"${btcDisplay.symbol} ${btcDisplay.value} (${it.symbol}${it.formatted})"
"${btcDisplay.symbol} ${btcDisplay.value} (${it.formattedWithSymbol()})"
} else {
"${it.symbol}${it.formatted} (${btcDisplay.symbol} ${btcDisplay.value})"
"${it.formattedWithSymbol()} (${btcDisplay.symbol} ${btcDisplay.value})"
}
} ?: "$BITCOIN_SYMBOL ${sats.formatToModernDisplay()}"

Expand Down
45 changes: 45 additions & 0 deletions app/src/main/java/to/bitkit/models/Currency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ data class ConvertedAmount(
val sats: Long,
val locale: Locale = Locale.getDefault(),
) {
val isSymbolSuffix: Boolean get() = currency in SUFFIX_SYMBOL_CURRENCIES

data class BitcoinDisplayComponents(
val symbol: String,
val value: String,
Expand All @@ -88,6 +90,12 @@ data class ConvertedAmount(
value = formattedValue,
)
}

fun formattedWithSymbol(withSpace: Boolean = false): String = value.formatCurrencyWithSymbol(
currencyCode = currency,
currencySymbol = symbol,
withSpace = withSpace,
)
}

fun Long.formatMoney(
Expand Down Expand Up @@ -145,5 +153,42 @@ fun BigDecimal.formatCurrency(decimalPlaces: Int = FIAT_DECIMALS, locale: Locale
return runCatching { formatter.format(this) }.getOrNull()
}

fun BigDecimal.formatCurrencyWithSymbol(
currencyCode: String,
currencySymbol: String? = null,
withSpace: Boolean = false,
decimalPlaces: Int = FIAT_DECIMALS,
): String {
val formatted = formatCurrency(decimalPlaces) ?: "0.00"
val symbol = currencySymbol
?: runCatching { java.util.Currency.getInstance(currencyCode) }.getOrNull()?.symbol
?: currencyCode
val separator = if (withSpace) " " else ""

return if (currencyCode in SUFFIX_SYMBOL_CURRENCIES) {
"$formatted$separator$symbol"
} else {
"$symbol$separator$formatted"
}
}

fun isSuffixSymbolCurrency(currencyCode: String): Boolean = currencyCode in SUFFIX_SYMBOL_CURRENCIES

private val SUFFIX_SYMBOL_CURRENCIES = setOf(
"BGN",
"CHF",
"CZK",
"DKK",
"HRK",
"HUF",
"ISK",
"NOK",
"PLN",
"RON",
"RUB",
"SEK",
"TRY",
)

/** Represent this sat value in Bitcoin BigDecimal. */
fun Long.asBtc(): BigDecimal = BigDecimal(this).divide(BigDecimal(SATS_IN_BTC), BTC_SCALE, RoundingMode.HALF_UP)
28 changes: 26 additions & 2 deletions app/src/main/java/to/bitkit/ui/components/BalanceHeaderView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ fun BalanceHeaderView(
modifier = modifier,
smallRowSymbol = if (isBitcoinPrimary) fiat.symbol else btc.symbol,
smallRowText = if (isBitcoinPrimary) fiat.formatted else btc.value,
smallRowIsSymbolSuffix = if (isBitcoinPrimary) fiat.isSymbolSuffix else false,
smallRowModifier = Modifier.testTag("$testTag-secondary"),
largeRowPrefix = prefix,
largeRowText = if (isBitcoinPrimary) btc.value else fiat.formatted,
largeRowSymbol = if (isBitcoinPrimary) btc.symbol else fiat.symbol,
largeRowIsSymbolSuffix = if (isBitcoinPrimary) false else fiat.isSymbolSuffix,
largeRowModifier = Modifier.testTag("$testTag-primary"),
showSymbol = if (isBitcoinPrimary) showBitcoinSymbol else true,
hideBalance = shouldHideBalance,
Expand All @@ -110,10 +112,12 @@ fun BalanceHeader(
modifier: Modifier = Modifier,
smallRowSymbol: String? = null,
smallRowText: String,
smallRowIsSymbolSuffix: Boolean = false,
smallRowModifier: Modifier = Modifier,
largeRowPrefix: String? = null,
largeRowText: String,
largeRowSymbol: String,
largeRowIsSymbolSuffix: Boolean = false,
largeRowModifier: Modifier = Modifier,
showSymbol: Boolean,
hideBalance: Boolean = false,
Expand All @@ -137,6 +141,7 @@ fun BalanceHeader(
SmallRow(
symbol = smallRowSymbol,
text = smallRowText,
isSymbolSuffix = smallRowIsSymbolSuffix,
hideBalance = hideBalance,
modifier = smallRowModifier,
)
Expand All @@ -151,6 +156,7 @@ fun BalanceHeader(
text = largeRowText,
symbol = largeRowSymbol,
showSymbol = showSymbol,
isSymbolSuffix = largeRowIsSymbolSuffix,
hideBalance = hideBalance,
modifier = largeRowModifier,
)
Expand Down Expand Up @@ -187,6 +193,7 @@ fun LargeRow(
symbol: String,
showSymbol: Boolean,
modifier: Modifier = Modifier,
isSymbolSuffix: Boolean = false,
hideBalance: Boolean = false,
) {
Row(
Expand All @@ -202,7 +209,7 @@ fun LargeRow(
.testTag("MoneySign")
)
}
if (showSymbol) {
if (showSymbol && !isSymbolSuffix) {
Display(
text = symbol,
color = Colors.White64,
Expand All @@ -221,6 +228,15 @@ fun LargeRow(
modifier = Modifier.testTag("MoneyText")
)
}
if (showSymbol && isSymbolSuffix) {
Display(
text = symbol,
color = Colors.White64,
modifier = Modifier
.padding(start = 8.dp)
.testTag("MoneyFiatSymbol")
)
}
}
}

Expand All @@ -229,14 +245,15 @@ private fun SmallRow(
symbol: String?,
text: String,
modifier: Modifier = Modifier,
isSymbolSuffix: Boolean = false,
hideBalance: Boolean = false,
) {
Row(
verticalAlignment = Alignment.Bottom,
horizontalArrangement = Arrangement.spacedBy(4.dp),
modifier = modifier,
) {
if (symbol != null) {
if (symbol != null && !isSymbolSuffix) {
Caption13Up(
text = symbol,
color = Colors.White64,
Expand All @@ -254,6 +271,13 @@ private fun SmallRow(
modifier = Modifier.testTag("MoneyText")
)
}
if (symbol != null && isSymbolSuffix) {
Caption13Up(
text = symbol,
color = Colors.White64,
modifier = Modifier.testTag("MoneyFiatSymbol")
)
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/to/bitkit/ui/components/Money.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ fun rememberMoneyText(
}
} else {
buildString {
if (showSymbol) append("<accent>${converted.symbol}</accent> ")
if (showSymbol && !converted.isSymbolSuffix) append("<accent>${converted.symbol}</accent> ")
append(converted.formatted)
if (showSymbol && converted.isSymbolSuffix) append("<accent>${converted.symbol}</accent>")
}
}
}
Expand Down
25 changes: 20 additions & 5 deletions app/src/main/java/to/bitkit/ui/components/NumberPadTextField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import to.bitkit.models.BITCOIN_SYMBOL
import to.bitkit.models.PrimaryDisplay
import to.bitkit.models.USD_SYMBOL
import to.bitkit.models.formatToModernDisplay
import to.bitkit.models.isSuffixSymbolCurrency
import to.bitkit.repositories.CurrencyState
import to.bitkit.ui.LocalCurrencies
import to.bitkit.ui.shared.modifiers.clickableAlpha
Expand Down Expand Up @@ -48,6 +49,8 @@ fun NumberPadTextField(
showPlaceholder = true,
satoshis = uiState.value.sats,
currencySymbol = currencies.currencySymbol,
isSymbolSuffix = currencies.primaryDisplay == PrimaryDisplay.FIAT &&
isSuffixSymbolCurrency(currencies.selectedCurrency),
showSecondaryField = showSecondaryField,
)
}
Expand All @@ -60,11 +63,14 @@ private fun MoneyAmount(
satoshis: Long,
modifier: Modifier = Modifier,
currencySymbol: String = BITCOIN_SYMBOL,
isSymbolSuffix: Boolean = false,
showPlaceholder: Boolean = true,
showSecondaryField: Boolean = true,
valueStyle: SpanStyle = SpanStyle(color = Colors.White),
placeholderStyle: SpanStyle = SpanStyle(color = Colors.White50),
) {
val symbol = if (unit == PrimaryDisplay.BITCOIN) BITCOIN_SYMBOL else currencySymbol

Column(
modifier = modifier.semantics { contentDescription = value },
horizontalAlignment = Alignment.Start
Expand All @@ -76,11 +82,13 @@ private fun MoneyAmount(
Row(
verticalAlignment = Alignment.CenterVertically,
) {
Display(
text = if (unit == PrimaryDisplay.BITCOIN) BITCOIN_SYMBOL else currencySymbol,
color = Colors.White64,
modifier = Modifier.padding(end = 6.dp)
)
if (!isSymbolSuffix) {
Display(
text = symbol,
color = Colors.White64,
modifier = Modifier.padding(end = 6.dp)
)
}
Display(
text = buildAnnotatedString {
if (value != placeholder) {
Expand All @@ -95,6 +103,13 @@ private fun MoneyAmount(
}
}
)
if (isSymbolSuffix) {
Display(
text = symbol,
color = Colors.White64,
modifier = Modifier.padding(start = 6.dp)
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ private fun RowScope.Content(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
BodyMSB(text = converted.symbol)
BodyMSB(text = if (isHidden) UiConstants.HIDE_BALANCE_SHORT else converted.formatted)
if (converted.isSymbolSuffix) {
BodyMSB(text = if (isHidden) UiConstants.HIDE_BALANCE_SHORT else converted.formatted)
BodyMSB(text = converted.symbol)
} else {
BodyMSB(text = converted.symbol)
BodyMSB(text = if (isHidden) UiConstants.HIDE_BALANCE_SHORT else converted.formatted)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ private fun AmountView(
titlePrefix = prefix,
subtitle = converted.formatted,
subtitleSymbol = converted.symbol,
isSymbolSuffix = converted.isSymbolSuffix,
hideBalance = hideBalance,
)
} else {
Expand All @@ -253,6 +254,7 @@ private fun AmountView(
titleSymbol = converted.symbol,
titlePrefix = prefix,
subtitle = btcValue,
isSymbolSuffix = converted.isSymbolSuffix,
hideBalance = hideBalance,
)
}
Expand All @@ -267,6 +269,7 @@ private fun AmountViewContent(
modifier: Modifier = Modifier,
titleSymbol: String? = null,
subtitleSymbol: String? = null,
isSymbolSuffix: Boolean = false,
hideBalance: Boolean = false,
) {
Column(
Expand All @@ -280,7 +283,7 @@ private fun AmountViewContent(
horizontalArrangement = Arrangement.spacedBy(1.dp),
) {
BodyM(text = titlePrefix, color = Colors.White64)
if (titleSymbol != null) {
if (titleSymbol != null && !isSymbolSuffix) {
BodyMSB(text = titleSymbol, color = Colors.White64)
}
Spacer(modifier = Modifier.width(2.dp))
Expand All @@ -291,14 +294,17 @@ private fun AmountViewContent(
) { isHidden ->
BodyMSB(text = if (isHidden) UiConstants.HIDE_BALANCE_SHORT else title)
}
if (titleSymbol != null && isSymbolSuffix) {
BodyMSB(text = titleSymbol, color = Colors.White64)
}
}

// Subtitle row with static symbol
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(3.dp),
) {
if (subtitleSymbol != null) {
if (subtitleSymbol != null && !isSymbolSuffix) {
CaptionB(text = subtitleSymbol, color = Colors.White64)
}
AnimatedContent(
Expand All @@ -311,6 +317,9 @@ private fun AmountViewContent(
color = Colors.White64,
)
}
if (subtitleSymbol != null && isSymbolSuffix) {
CaptionB(text = subtitleSymbol, color = Colors.White64)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ fun ReceiveConfirmScreen(

val networkFeeFormatted = remember(entry.networkFeeSat) {
currency.convert(entry.networkFeeSat)
?.let { converted -> "${converted.symbol}${converted.formatted}" }
?.let { converted -> converted.formattedWithSymbol() }
?: entry.networkFeeSat.toString()
}

val serviceFeeFormatted = remember(entry.serviceFeeSat) {
currency.convert(entry.serviceFeeSat)
?.let { converted -> "${converted.symbol}${converted.formatted}" }
?.let { converted -> converted.formattedWithSymbol() }
?: entry.serviceFeeSat.toString()
}

Expand All @@ -84,7 +84,7 @@ fun ReceiveConfirmScreen(
val btcComponents = converted.bitcoinDisplay(displayUnit)
"${btcComponents.symbol} ${btcComponents.value}"
} else {
"${converted.symbol} ${converted.formatted}"
converted.formattedWithSymbol()
}
} ?: sats.toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private fun UtxoRow(
currency.convert(sats = amount)?.let { converted ->
val btcValue = converted.bitcoinDisplay(displayUnit).value
BodyMSB(text = btcValue)
BodySSB(text = "${converted.symbol} ${converted.formatted}", color = Colors.White64)
BodySSB(text = converted.formattedWithSymbol(), color = Colors.White64)
}
}

Expand Down
Loading
Loading