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 sc update+ preview is…
Browse files Browse the repository at this point in the history
…sue fixed)
  • Loading branch information
shamim-emon committed Oct 7, 2024
1 parent 24bdfee commit d672bda
Show file tree
Hide file tree
Showing 21 changed files with 8 additions and 42 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.
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.
7 changes: 0 additions & 7 deletions shared/ui/core/src/main/java/com/ivy/ui/FormatMoneyUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,4 @@ class FormatMoneyUseCase(
false -> withoutDecimalFormatter.format(value)
}
}

fun format(value: Double, showDecimalPoint: Boolean): String {
return when (showDecimalPoint) {
true -> withDecimalFormatter.format(value)
false -> withoutDecimalFormatter.format(value)
}
}
}
20 changes: 0 additions & 20 deletions shared/ui/core/src/test/java/com/ivy/ui/FormatMoneyUseCaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,4 @@ class FormatMoneyUseCaseTest {
// then
result shouldBe testCase.expectedOutput
}

@Test
fun `validate decimal formatting when showDecimalPoint is passed as parameter`(
@TestParameter testCase: MoneyFormatterTestCase
) {
// given
val context = mockk<Context>()
every { features.showDecimalNumber } returns mockk { coEvery { isEnabled(any()) } returns testCase.showDecimal }
every { devicePreferences.locale() } returns testCase.locale
formatMoneyUseCase = FormatMoneyUseCase(features, devicePreferences, context)

// when
val result = formatMoneyUseCase.format(
value = testCase.amount,
showDecimalPoint = testCase.showDecimal
)

// then
result shouldBe testCase.expectedOutput
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import androidx.compose.ui.unit.sp
import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.legacy.IvyWalletComponentPreview
import com.ivy.legacy.utils.toDecimalFormatAsync
import com.ivy.legacy.utils.format
import com.ivy.legacy.utils.toDecimalFormat

@Deprecated("Old design system. Use `:ivy-design` and Material3")
@Composable
Expand Down Expand Up @@ -93,10 +94,10 @@ fun BalanceRow(
) {
val context = LocalContext.current
var formattedBalance by remember {
mutableStateOf("$balance")
mutableStateOf(balance.format(2))
}
LaunchedEffect(balance) {
formattedBalance = balance.toDecimalFormatAsync(context = context)
formattedBalance = balance.toDecimalFormat(context = context)
}
Column(
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.ui.unit.dp
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.toDecimalFormatAsync
import com.ivy.legacy.utils.toDecimalFormat

@Deprecated("Old design system. Use `:ivy-design` and Material3")
@Composable
Expand Down Expand Up @@ -81,9 +81,9 @@ fun AmountCurrencyB1(
hideIncome: Boolean = false
) {
val context = LocalContext.current
var formattedAmount by remember { mutableStateOf("$amount") }
var formattedAmount by remember { mutableStateOf(amount.format(2)) }
LaunchedEffect(amount) {
formattedAmount = amount.toDecimalFormatAsync(context)
formattedAmount = amount.toDecimalFormat(context)
}
val text = if (hideIncome) {
"****"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,14 @@ fun formatInputAmount(
return null
}

suspend fun Double.toDecimalFormatAsync(context: Context): String {
suspend fun Double.toDecimalFormat(context: Context): String {
val appContext = context.applicationContext ?: error("Application Context Not Found")
val entryPoint =
EntryPoints.get(appContext, FormatMoneyUseCase.FormatMoneyUseCaseEntryPoint::class.java)
val useCase = entryPoint.FormatMoneyUseCase()
return useCase.format(value = this)
}

fun Double.toDecimalFormatSync(context: Context, showDecimalPoint: Boolean = true): String {
val appContext = context.applicationContext ?: error("Application Context Not Found")
val entryPoint =
EntryPoints.get(appContext, FormatMoneyUseCase.FormatMoneyUseCaseEntryPoint::class.java)
val useCase = entryPoint.FormatMoneyUseCase()
return useCase.format(value = this, showDecimalPoint = showDecimalPoint)
}

/**
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 d672bda

Please sign in to comment.