fix: Handle No Accounts in Home and Serializable Error in Transactions (#1938)

This commit is contained in:
JILAKARA REVANTH KUMAR 2025-09-16 17:43:37 +05:30 committed by GitHub
parent cd710437b2
commit b218d3fa33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 23 deletions

View File

@ -15,7 +15,7 @@ import kotlinx.serialization.Serializable
data class TransactionsEntity(
val id: Long,
val transactionType: TransactionType,
val entryType: String,
val entryType: String? = null,
val accountId: Long,
val accountNo: String,
val date: List<Int>,

View File

@ -204,7 +204,7 @@ fun TransactionItem(
blue = 0f,
)
else -> KptTheme.colorScheme.scrim
else -> KptTheme.colorScheme.onSurface
},
textAlign = TextAlign.End,
),

View File

@ -33,5 +33,6 @@
<string name="feature_home_account_success">Account marked as default</string>
<string name="feature_home_account_error">Error marking account as default</string>
<string name="feature_home_no_account">"No accounts found"</string>
<string name="feature_home_account_number">A/c No: %1$s</string>
</resources>

View File

@ -82,11 +82,13 @@ import kotlinx.coroutines.launch
import mobile_wallet.feature.home.generated.resources.Res
import mobile_wallet.feature.home.generated.resources.arrow_backward
import mobile_wallet.feature.home.generated.resources.coin_image
import mobile_wallet.feature.home.generated.resources.feature_home_account_number
import mobile_wallet.feature.home.generated.resources.feature_home_account_type
import mobile_wallet.feature.home.generated.resources.feature_home_arrow_up
import mobile_wallet.feature.home.generated.resources.feature_home_coin_image
import mobile_wallet.feature.home.generated.resources.feature_home_desc
import mobile_wallet.feature.home.generated.resources.feature_home_mark_default
import mobile_wallet.feature.home.generated.resources.feature_home_no_account
import mobile_wallet.feature.home.generated.resources.feature_home_request
import mobile_wallet.feature.home.generated.resources.feature_home_request_money
import mobile_wallet.feature.home.generated.resources.feature_home_send
@ -117,6 +119,7 @@ import org.mifospay.core.model.savingsaccount.Currency
import org.mifospay.core.model.savingsaccount.Status
import org.mifospay.core.model.savingsaccount.Transaction
import org.mifospay.core.model.savingsaccount.TransactionType
import org.mifospay.core.ui.EmptyContentScreen
import org.mifospay.core.ui.ErrorScreenContent
import org.mifospay.core.ui.MifosDivider
import org.mifospay.core.ui.MifosProgressIndicator
@ -249,6 +252,14 @@ fun HomeScreenContent(
},
)
}
ViewState.NoAccounts -> {
EmptyContentScreen(
title = stringResource(Res.string.feature_home_no_account),
subTitle = "",
modifier = Modifier.fillMaxSize(),
)
}
}
}
}
@ -761,7 +772,7 @@ private fun HomeTransactionHistoryCard(
)
}
Text(
text = selectedAccount,
text = stringResource(Res.string.feature_home_account_number, selectedAccount),
style = KptTheme.typography.bodySmall,
)
}

View File

@ -10,7 +10,6 @@
package org.mifospay.feature.home
import androidx.lifecycle.viewModelScope
import co.touchlab.kermit.Logger
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.update
@ -68,7 +67,19 @@ class HomeViewModel(
}
is DataState.Success -> {
if (result.data.isEmpty()) {
mutableStateFlow.update {
it.copy(
isRefreshing = false,
accounts = emptyList(),
accountsWithTransactions = emptyMap(),
viewState = ViewState.NoAccounts,
)
}
} else {
val selected = result.data.firstOrNull()
if (selected != null) {
mutableStateFlow.update {
it.copy(
isRefreshing = false,
@ -79,6 +90,8 @@ class HomeViewModel(
currentSelectedAccount = selected,
)
}
}
if (state.defaultAccountId == null && selected != null) {
sendAction(HomeAction.MarkAsDefault(selected.id, selected.number))
}
@ -90,6 +103,7 @@ class HomeViewModel(
}
}
}
}
private var loadTransactionsJob: Job? = null
@ -104,9 +118,6 @@ class HomeViewModel(
}
applyFilter()
} else {
Logger.e("Revanth") {
account.toString()
}
// cancel the previous job if it's still active
loadTransactionsJob?.cancel()
@ -352,6 +363,8 @@ sealed interface ViewState {
data class Error(val message: StringResource) : ViewState
data object Content : ViewState
data object NoAccounts : ViewState
}
sealed interface HomeEvent {