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(Paparazzi snaps updated)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamim-emon committed Oct 6, 2024
1 parent 040b94f commit d801d81
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 3 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.
3 changes: 3 additions & 0 deletions shared/ui/core/src/main/java/com/ivy/ui/FormatMoneyUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ class FormatMoneyUseCaseImpl @Inject constructor(
false -> withoutDecimalFormatter.format(value)
}
}

override fun formatWithDecimalPlaces(value: Double): String = withDecimalFormatter.format(value)
}

interface FormatMoneyUseCase {
suspend fun format(value: Double): String
fun formatWithDecimalPlaces(value: Double): String
}
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.toDecimalFormatWithDecimalPlaces
import kotlinx.coroutines.launch

@Deprecated("Old design system. Use `:ivy-design` and Material3")
Expand Down Expand Up @@ -95,7 +96,7 @@ fun BalanceRow(
val context = LocalContext.current
val scope = rememberCoroutineScope()
var formattedBalance by remember {
mutableStateOf("$balance")
mutableStateOf(balance.toDecimalFormatWithDecimalPlaces(context))
}
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.toDecimalFormatWithDecimalPlaces
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")
@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("$amount") }
var formattedAmount by remember { mutableStateOf(amount.toDecimalFormatWithDecimalPlaces(context)) }
scope.launch {
formattedAmount = amount.toDecimalFormat(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ suspend fun Double.toDecimalFormat(context: Context): String {
return useCase.format(this)
}

fun Double.toDecimalFormatWithDecimalPlaces(context: Context): String {
val appContext = context.applicationContext ?: error("Application Context Not Found")
val entryPoint =
EntryPoints.get(appContext, FormatMoneyUseCaseImpl.FormatMoneyUseCaseEntryPoint::class.java)
val useCase = entryPoint.FormatMoneyUseCase()
return useCase.formatWithDecimalPlaces(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 d801d81

Please sign in to comment.