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

Commit

Permalink
Fix transaction type parsing when there's bad chars
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Apr 17, 2023
1 parent aef99c3 commit e86cb60
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseFields.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ fun parseTransactionType(
}

return tryParse {
with(value) {
val cleaned = value.filter { it.isLetterOrDigit() || it == '+' || it == '-' }
with(cleaned) {
when {
tryMeta(metadata.expense) -> TransactionType.EXPENSE
tryMeta(metadata.income) -> TransactionType.INCOME
tryMeta(metadata.transfer ?: "") -> TransactionType.TRANSFER
value.contains("income", ignoreCase = true) -> TransactionType.INCOME
value.contains("expense", ignoreCase = true) -> TransactionType.EXPENSE
value.contains("transfer", ignoreCase = true) -> TransactionType.TRANSFER
value.toDoubleOrNull()?.let { it > 0 } == true -> TransactionType.INCOME
value.toDoubleOrNull()?.let { it < 0 } == true -> TransactionType.EXPENSE
cleaned.contains("income", ignoreCase = true) -> TransactionType.INCOME
cleaned.contains("expense", ignoreCase = true) -> TransactionType.EXPENSE
cleaned.contains("transfer", ignoreCase = true) -> TransactionType.TRANSFER
cleaned.toDoubleOrNull()?.let { it > 0 } == true -> TransactionType.INCOME
cleaned.toDoubleOrNull()?.let { it < 0 } == true -> TransactionType.EXPENSE
else -> null
}
}
Expand Down

0 comments on commit e86cb60

Please sign in to comment.