Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Account Tab Decimal Formatting Added(detekt issue fixed)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamim-emon committed Oct 6, 2024
1 parent 6ade007 commit fbf5635
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.legacy.IvyWalletComponentPreview
import com.ivy.legacy.utils.toDecimalFormat
import com.ivy.legacy.utils.toDecimalFormatWithFraction
import kotlinx.coroutines.launch

@Deprecated("Old design system. Use `:ivy-design` and Material3")
Expand Down Expand Up @@ -78,7 +79,7 @@ fun BalanceRowMini(
)
}

@SuppressLint("CoroutineCreationDuringComposition", "DefaultLocale")
@SuppressLint("CoroutineCreationDuringComposition")
@Composable
fun BalanceRow(
currency: String,
Expand All @@ -95,7 +96,7 @@ fun BalanceRow(
val context = LocalContext.current
val scope = rememberCoroutineScope()
var formattedBalance by remember {
mutableStateOf(String.format("%.2f", balance))
mutableStateOf(balance.toDecimalFormatWithFraction())
}
scope.launch {
formattedBalance = balance.toDecimalFormat(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.legacy.utils.format
import com.ivy.legacy.utils.toDecimalFormat
import com.ivy.legacy.utils.toDecimalFormatWithFraction
import kotlinx.coroutines.launch

@Deprecated("Old design system. Use `:ivy-design` and Material3")
Expand Down Expand Up @@ -72,7 +73,7 @@ fun AmountCurrencyB1Row(
}
}

@SuppressLint("ComposeContentEmitterReturningValues", "CoroutineCreationDuringComposition", "DefaultLocale")
@SuppressLint("ComposeContentEmitterReturningValues", "CoroutineCreationDuringComposition")
@Composable
fun AmountCurrencyB1(
amount: Double,
Expand All @@ -83,7 +84,7 @@ fun AmountCurrencyB1(
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var formattedAmount by remember { mutableStateOf(String.format("%.2f", amount)) }
var formattedAmount by remember { mutableStateOf(amount.toDecimalFormatWithFraction()) }
scope.launch {
formattedAmount = amount.toDecimalFormat(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.ivy.wallet.domain.data.IvyCurrency
import dagger.hilt.EntryPoints
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.text.NumberFormat
import java.util.Locale
import kotlin.math.abs
import kotlin.math.log10
import kotlin.math.truncate
Expand Down Expand Up @@ -206,6 +208,16 @@ suspend fun Double.toDecimalFormat(context: Context): String {
return useCase.format(this)
}

fun Double.toDecimalFormatWithFraction(fraction: Int = 2): String {
val defaultLocale: Locale = Locale.getDefault()

// Create a NumberFormat instance for the current locale
val numberFormat: NumberFormat = NumberFormat.getNumberInstance(defaultLocale)
numberFormat.minimumFractionDigits = fraction
numberFormat.maximumFractionDigits = fraction
return numberFormat.format(this)
}

/**
toInt on numbers in the range (-1.0, 0.0) (exclusive of boundaries) will produce a positive int 0
So, this function append negative sign in that case
Expand Down

0 comments on commit fbf5635

Please sign in to comment.