-
Notifications
You must be signed in to change notification settings - Fork 775
arabic number pad fix ,shifted from native numbers to standard US num… #2804
arabic number pad fix ,shifted from native numbers to standard US num… #2804
Conversation
Hi @ILIYANGERMANOV, I need some help! With the above change, it will fix the number system when using Arabic or any right-to-left language. However, |
@@ -131,7 +132,7 @@ fun shouldShortAmount(amount: Double): Boolean { | |||
} | |||
|
|||
fun formatInt(number: Int): String { | |||
return DecimalFormat("#,###,###,###").format(number) | |||
return DecimalFormat("#,###,###,###", DecimalFormatSymbols(Locale.US)).format(number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cna you verify if this breaks:
- entering amounts in US, IN, Arabic
- Import/export CSV backup
- Import/export Backup JSON
- Import old backup CSV (previous Ivy version)
- Import old backup JSON zip
I'm concerned that this PR risks breaking this and everything using those functions.
We must add a backup logic unit tests with top priority (not part of this PR but a good issue to help us be safe)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree! I saw this under legacy code. This was a bit of a hack. It needs a proper solution. This depends on two questions:
(1.) Are we dealing with right-to-left language separators, which are ',' instead of '.'? If users of that country don't need their native numbers when dealing with calculations, I guess it should be completely removed, and only the US standard number formatter should be used.
(2.) In this part, we are directly manipulating data from the UI, which forces us to handle things according to the UI. I believe the best way to handle this would be for the UI not to be aware of the operations we are performing. It should be in some repository, and, if needed, can be injected anywhere in a centralized system. This way, the whole app will be in sync, instead of using extension functions. This is a really important part of the app.
Number Pad for input
@Composable
fun AmountInput(
currency: String,
amount: String,
decimalCountMax: Int = 2,
setAmount: (String) -> Unit,
) {
var firstInput by remember { mutableStateOf(true) }
AmountKeyboard(
forCalculator = false,
onNumberPressed = {
if (firstInput) {
setAmount(it)
firstInput = false
} else {
val formattedAmount = formatInputAmount(
currency = currency,
amount = amount,
newSymbol = it,
decimalCountMax = decimalCountMax
)
if (formattedAmount != null) {
setAmount(formattedAmount)
}
}
},
onDecimalPoint = {
if (firstInput) {
setAmount("0${localDecimalSeparator()}")
firstInput = false
} else {
val newlyEnteredString = if (amount.isEmpty()) {
"0${localDecimalSeparator()}"
} else {
"$amount${localDecimalSeparator()}"
}
if (newlyEnteredString.amountToDoubleOrNull() != null) {
setAmount(newlyEnteredString)
}
}
},
onBackspace = {
if (firstInput) {
setAmount("")
firstInput = false
} else {
if (amount.isNotEmpty()) {
val formattedNumber = formatNumber(amount.dropLast(1))
setAmount(formattedNumber ?: "")
}
}
}
)
}
My suggestion might be overkill or might not be perfect. I would love to hear from you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need to centralize it and we started such efforts with out architecture and :ivy-data
. I don't have much context on this task so apply the solution that makes the most sense to you. My only requirement is to not break the existing legacy code. Critical features:
- numpad on all Locales
- backups
If this change can't be applied safely my suggestion would be to postpone this task and focus migrating the app to the new architecture and adding tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move on to other tasks for now. I'm still relatively new to the source code, and there are backups involved. Once we gain more confidence in the architecture and I become more familiar with the code, we can revisit this task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍 This task is complex to implement even if you're familiar cuz of the shitty legacy code 😄 Apologies for it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries! We will migrate it slowly.
…ber system
Pull Request (PR) Checklist
Please check if your pull request fulfills the following requirements:
main
branch.bug_fix.webm
What's changed?
Describe with a few bullets what's new:
Risk Factors
What may go wrong if we merge your PR?
In what cases your code won't work?
This may be a future issue! I'm not sure if Ivy Wallet will use numbers for these strings. It uses native right-to-left language numbers

Does this PR closes any GitHub Issues?
Check Ivy Wallet Issues.
Troubleshooting CI failures
If you see any of the PR checks failing (❌) go to Actions and find it there. Or simply click "Details" next to the failed check and explore the logs to see why it has failed.
Detekt
Detekt is a static code analyzer for Kotlin that we use to enforce code readibility and good practices.
To run Detekt locally:
If the Detekt errors are caused by a legacy code, you can suppress them using a basline.
Detekt baseline (not recommended)
Lint
We use the standard Android Lint plus Slack's compose-lints as an addition to enforce proper Compose usage.
To run Lint locally:
If the Lint errors are caused by a legacy code, you can suppress them using a basline.
Lint baseline (not recommended)
Unit tests
If this job is failing this means that your changes break an existing unit test. You must identify the failing tests and fix your code.
To run the Unit tests locally: