diff --git a/app/src/main/java/com/goldenraven/padawanwallet/ui/wallet/WalletRootScreen.kt b/app/src/main/java/com/goldenraven/padawanwallet/ui/wallet/WalletRootScreen.kt index ade080f6..e070bc2c 100644 --- a/app/src/main/java/com/goldenraven/padawanwallet/ui/wallet/WalletRootScreen.kt +++ b/app/src/main/java/com/goldenraven/padawanwallet/ui/wallet/WalletRootScreen.kt @@ -154,7 +154,8 @@ fun BalanceBox( CurrencyToggleText(currencyToggleState = currencyToggleState, text = CurrencyType.SATS) } } - val balanceDisplay: String = if (currencyToggleState.value) balance.toString() else balance.formatInBtc() + var balanceDisplay: String = if (currencyToggleState.value) balance.toString() else balance.formatInBtc() + balanceDisplay = formatCurrency(balanceDisplay) val currencyDisplay: String = if (currencyToggleState.value) CurrencyType.SATS.toString().lowercase() else CurrencyType.BTC.toString().lowercase() Text( text = balanceDisplay, @@ -217,6 +218,18 @@ fun BalanceBox( } } +fun formatCurrency(amount: String): String { + val regex = "(\\d)(?=(\\d{3})+\$)".toRegex() + val dotIdx = amount.indexOf('.') + return if (dotIdx == -1) { + amount.replace(regex, "\$1,") + } else { + val num = amount.substring(0, dotIdx).replace(regex, "\$1,") + val dec = amount.substring(dotIdx+1).replace(regex, "\$1 ") + "$num.$dec" + } +} + @Composable fun SendReceive(navController: NavHostController) { Row(