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

Commit

Permalink
fix-issue-2963 (#2998)
Browse files Browse the repository at this point in the history
* Moving away from `legacy.Transaction`

* Code cleanup

* Fix incorrect account balance

* Fix `TransactionEntity.toDomain` function

* Applied requested changes.
  • Loading branch information
michalguspiel authored Feb 27, 2024
1 parent 9a500de commit c1381e5
Show file tree
Hide file tree
Showing 27 changed files with 396 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import com.ivy.data.model.Expense
import com.ivy.data.model.Income
import com.ivy.data.model.Transaction
import com.ivy.data.model.Transfer
import com.ivy.data.model.getAccountId
import com.ivy.data.model.getValue
import com.ivy.data.temp.migration.getAccountId
import com.ivy.data.temp.migration.getValue
import com.ivy.base.ComposeViewModel
import com.ivy.frp.sumOfSuspend
import com.ivy.legacy.data.model.FromToTimeRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ class EditTransactionViewModel @Inject constructor(

private fun onPayPlannedPayment() {
viewModelScope.launch {
plannedPaymentsLogic.payOrGet(
plannedPaymentsLogic.payOrGetLegacy(
transaction = loadedTransaction(),
syncTransaction = false
) { paidTransaction ->
Expand Down
6 changes: 3 additions & 3 deletions screen/home/src/main/java/com/ivy/home/HomeState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.ivy.base.legacy.TransactionHistoryItem
import com.ivy.home.customerjourney.CustomerJourneyCardModel
import com.ivy.legacy.data.AppBaseData
import com.ivy.legacy.data.BufferInfo
import com.ivy.legacy.data.DueSection
import com.ivy.legacy.data.LegacyDueSection
import com.ivy.legacy.data.model.TimePeriod
import com.ivy.wallet.domain.pure.data.IncomeExpensePair
import kotlinx.collections.immutable.ImmutableList
Expand All @@ -27,8 +27,8 @@ data class HomeState(

val buffer: BufferInfo,

val upcoming: DueSection,
val overdue: DueSection,
val upcoming: LegacyDueSection,
val overdue: LegacyDueSection,

val customerJourneyCards: ImmutableList<CustomerJourneyCardModel>,
val hideBalance: Boolean,
Expand Down
11 changes: 6 additions & 5 deletions screen/home/src/main/java/com/ivy/home/HomeTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.ivy.home.customerjourney.CustomerJourney
import com.ivy.home.customerjourney.CustomerJourneyCardModel
import com.ivy.legacy.data.AppBaseData
import com.ivy.legacy.data.BufferInfo
import com.ivy.legacy.data.DueSection
import com.ivy.legacy.data.LegacyDueSection
import com.ivy.legacy.data.model.MainTab
import com.ivy.legacy.data.model.TimePeriod
import com.ivy.legacy.ivyWalletCtx
Expand Down Expand Up @@ -271,6 +271,7 @@ private fun BoxWithConstraintsScope.UI(
}
}

@Suppress("LongParameterList")
@ExperimentalAnimationApi
@Composable
fun HomeLazyColumn(
Expand All @@ -282,8 +283,8 @@ fun HomeLazyColumn(

baseData: AppBaseData,

upcoming: DueSection,
overdue: DueSection,
upcoming: LegacyDueSection,
overdue: LegacyDueSection,
balance: BigDecimal,
stats: IncomeExpensePair,
history: ImmutableList<TransactionHistoryItem>,
Expand Down Expand Up @@ -399,12 +400,12 @@ private fun BoxWithConstraintsScope.PreviewHomeTab() {
customerJourneyCards = persistentListOf(),
history = persistentListOf(),
stats = IncomeExpensePair.zero(),
upcoming = DueSection(
upcoming = LegacyDueSection(
trns = persistentListOf(),
stats = IncomeExpensePair.zero(),
expanded = false,
),
overdue = DueSection(
overdue = LegacyDueSection(
trns = persistentListOf(),
stats = IncomeExpensePair.zero(),
expanded = false,
Expand Down
28 changes: 10 additions & 18 deletions screen/home/src/main/java/com/ivy/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.ivy.home.customerjourney.CustomerJourneyCardsProvider
import com.ivy.legacy.IvyWalletCtx
import com.ivy.legacy.data.AppBaseData
import com.ivy.legacy.data.BufferInfo
import com.ivy.legacy.data.DueSection
import com.ivy.legacy.data.LegacyDueSection
import com.ivy.legacy.data.model.MainTab
import com.ivy.legacy.data.model.TimePeriod
import com.ivy.legacy.data.model.toCloseTimeRange
Expand Down Expand Up @@ -105,14 +105,14 @@ class HomeViewModel @Inject constructor(
)
)
private val upcoming = mutableStateOf(
DueSection(
LegacyDueSection(
trns = persistentListOf(),
stats = IncomeExpensePair.zero(),
expanded = false,
)
)
private val overdue = mutableStateOf(
DueSection(
LegacyDueSection(
trns = persistentListOf(),
stats = IncomeExpensePair.zero(),
expanded = false,
Expand Down Expand Up @@ -189,12 +189,12 @@ class HomeViewModel @Inject constructor(
}

@Composable
private fun getUpcoming(): DueSection {
private fun getUpcoming(): LegacyDueSection {
return upcoming.value
}

@Composable
private fun getOverdue(): DueSection {
private fun getOverdue(): LegacyDueSection {
return overdue.value
}

Expand Down Expand Up @@ -353,7 +353,7 @@ class HomeViewModel @Inject constructor(
): Unit = suspend {
UpcomingAct.Input(baseCurrency = input.first, range = input.second)
} then upcomingAct then { result ->
upcoming.value = DueSection(
upcoming.value = LegacyDueSection(
trns = with(transactionMapper) {
result.upcomingTrns.map {
it.toEntity().toDomain()
Expand All @@ -365,7 +365,7 @@ class HomeViewModel @Inject constructor(
} then {
OverdueAct.Input(baseCurrency = input.first, toRange = input.second.to)
} then overdueAct thenInvokeAfter { result ->
overdue.value = DueSection(
overdue.value = LegacyDueSection(
trns = with(transactionMapper) {
result.overdueTrns.map {
it.toEntity().toDomain()
Expand Down Expand Up @@ -452,7 +452,7 @@ class HomeViewModel @Inject constructor(
}

private suspend fun payOrGetPlanned(transaction: Transaction) {
plannedPaymentsLogic.payOrGet(
plannedPaymentsLogic.payOrGetLegacy(
transaction = transaction,
skipTransaction = false
) {
Expand All @@ -461,7 +461,7 @@ class HomeViewModel @Inject constructor(
}

private suspend fun skipPlanned(transaction: Transaction) {
plannedPaymentsLogic.payOrGet(
plannedPaymentsLogic.payOrGetLegacy(
transaction = transaction,
skipTransaction = true
) {
Expand All @@ -470,15 +470,7 @@ class HomeViewModel @Inject constructor(
}

private suspend fun skipAllPlanned(transactions: List<Transaction>) {
// transactions.forEach {
// plannedPaymentsLogic.payOrGet(
// transaction = it,
// skipTransaction = true
// ){
// reload()
// }
// }
plannedPaymentsLogic.payOrGet(
plannedPaymentsLogic.payOrGetLegacy(
transactions = transactions,
skipTransaction = true
) {
Expand Down
22 changes: 13 additions & 9 deletions screen/reports/src/main/java/com/ivy/reports/ReportScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.legacy.IvyWalletPreview
import com.ivy.legacy.data.AppBaseData
import com.ivy.legacy.data.DueSection
import com.ivy.legacy.data.LegacyDueSection
import com.ivy.legacy.datamodel.Account
import com.ivy.legacy.datamodel.Category
import com.ivy.legacy.datamodel.temp.toDomain
Expand Down Expand Up @@ -90,10 +90,6 @@ private fun BoxWithConstraintsScope.UI(
val transactionMapper = TransactionMapper()
val legacyTransactions =
with(transactionMapper) { state.transactions.map { it.toEntity().toDomain() } }
val legacyUpcomingTransactions =
with(transactionMapper) { state.upcomingTransactions.map { it.toEntity().toDomain() } }
val legacyOverdueTransactions =
with(transactionMapper) { state.overdueTransactions.map { it.toEntity().toDomain() } }
val nav = navigation()
val context = LocalContext.current

Expand Down Expand Up @@ -230,8 +226,12 @@ private fun BoxWithConstraintsScope.UI(
accounts = state.accounts,
),

upcoming = DueSection(
trns = legacyUpcomingTransactions.toImmutableList(),
upcoming = LegacyDueSection(
trns = with(transactionMapper) {
state.upcomingTransactions.map {
it.toEntity().toDomain()
}.toImmutableList()
},
stats = IncomeExpensePair(
income = state.upcomingIncome.toBigDecimal(),
expense = state.upcomingExpenses.toBigDecimal()
Expand All @@ -243,8 +243,12 @@ private fun BoxWithConstraintsScope.UI(
onEventHandler.invoke(ReportScreenEvent.OnUpcomingExpanded(upcomingExpanded = it))
},

overdue = DueSection(
trns = legacyOverdueTransactions.toImmutableList(),
overdue = LegacyDueSection(
trns = with(transactionMapper) {
state.overdueTransactions.map {
it.toEntity().toDomain()
}.toImmutableList()
},
stats = IncomeExpensePair(
income = state.overdueIncome.toBigDecimal(),
expense = state.overdueExpenses.toBigDecimal()
Expand Down
25 changes: 9 additions & 16 deletions screen/reports/src/main/java/com/ivy/reports/ReportViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import com.ivy.data.model.Expense
import com.ivy.data.model.Income
import com.ivy.data.model.Transaction
import com.ivy.data.model.Transfer
import com.ivy.data.model.getTransactionType
import com.ivy.data.model.getValue
import com.ivy.data.temp.migration.getTransactionType
import com.ivy.data.temp.migration.getValue
import com.ivy.data.repository.TransactionRepository
import com.ivy.data.repository.mapper.TransactionMapper
import com.ivy.base.ComposeViewModel
Expand All @@ -25,7 +25,6 @@ import com.ivy.frp.filterSuspend
import com.ivy.legacy.IvyWalletCtx
import com.ivy.legacy.datamodel.Account
import com.ivy.legacy.datamodel.Category
import com.ivy.legacy.datamodel.temp.toDomain
import com.ivy.legacy.utils.formatNicelyWithTime
import com.ivy.legacy.utils.scopedIOThread
import com.ivy.legacy.utils.timeNowUTC
Expand Down Expand Up @@ -432,9 +431,7 @@ class ReportViewModel @Inject constructor(
private suspend fun payOrGet(transaction: Transaction) {
uiThread {
plannedPaymentsLogic.payOrGet(
transaction = with(transactionMapper) {
transaction.toEntity().toDomain()
}
transaction = transaction
) {
start()
setFilter(filter.value)
Expand All @@ -445,7 +442,7 @@ class ReportViewModel @Inject constructor(
@Deprecated("Uses legacy Transaction")
private suspend fun payOrGetLegacy(transaction: com.ivy.base.legacy.Transaction) {
uiThread {
plannedPaymentsLogic.payOrGet(transaction = transaction) {
plannedPaymentsLogic.payOrGetLegacy(transaction = transaction) {
start()
setFilter(filter.value)
}
Expand All @@ -467,7 +464,7 @@ class ReportViewModel @Inject constructor(
private suspend fun skipTransaction(transaction: Transaction) {
uiThread {
plannedPaymentsLogic.payOrGet(
transaction = with(transactionMapper) { transaction.toEntity().toDomain() },
transaction = transaction,
skipTransaction = true
) {
start()
Expand All @@ -479,7 +476,7 @@ class ReportViewModel @Inject constructor(
@Deprecated("Uses legacy Transaction")
private suspend fun skipTransactionLegacy(transaction: com.ivy.base.legacy.Transaction) {
uiThread {
plannedPaymentsLogic.payOrGet(
plannedPaymentsLogic.payOrGetLegacy(
transaction = transaction,
skipTransaction = true
) {
Expand All @@ -492,11 +489,7 @@ class ReportViewModel @Inject constructor(
private suspend fun skipTransactions(transactions: List<Transaction>) {
uiThread {
plannedPaymentsLogic.payOrGet(
transactions = with(transactionMapper) {
transactions.map {
it.toEntity().toDomain()
}
},
transactions = transactions,
skipTransaction = true
) {
start()
Expand All @@ -508,7 +501,7 @@ class ReportViewModel @Inject constructor(
@Deprecated("Uses legacy Transaction")
private suspend fun skipTransactionsLegacy(transactions: List<com.ivy.base.legacy.Transaction>) {
uiThread {
plannedPaymentsLogic.payOrGet(
plannedPaymentsLogic.payOrGetLegacy(
transactions = transactions,
skipTransaction = true
) {
Expand All @@ -517,4 +510,4 @@ class ReportViewModel @Inject constructor(
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.legacy.Constants
import com.ivy.legacy.data.AppBaseData
import com.ivy.legacy.data.DueSection
import com.ivy.legacy.data.model.TimePeriod
import com.ivy.legacy.datamodel.Account
import com.ivy.legacy.datamodel.Category
Expand All @@ -58,6 +57,7 @@ import com.ivy.legacy.utils.horizontalSwipeListener
import com.ivy.legacy.utils.rememberSwipeListenerState
import com.ivy.legacy.utils.setStatusBarDarkTextCompat
import com.ivy.design.utils.thenIf
import com.ivy.legacy.data.LegacyDueSection
import com.ivy.legacy.utils.rememberInteractionSource
import com.ivy.navigation.EditTransactionScreen
import com.ivy.navigation.IvyPreview
Expand Down Expand Up @@ -376,7 +376,7 @@ private fun BoxWithConstraintsScope.UI(
accounts,
categories
),
upcoming = DueSection(
upcoming = LegacyDueSection(
trns = upcoming,
stats = IncomeExpensePair(
income = upcomingIncome.toBigDecimal(),
Expand All @@ -386,7 +386,7 @@ private fun BoxWithConstraintsScope.UI(
),
setUpcomingExpanded = setUpcomingExpanded,

overdue = DueSection(
overdue = LegacyDueSection(
trns = overdue,
stats = IncomeExpensePair(
income = overdueIncome.toBigDecimal(),
Expand Down
Loading

0 comments on commit c1381e5

Please sign in to comment.