android-client icon indicating copy to clipboard operation
android-client copied to clipboard

refactor(loan): centralize loan status mapping across screens

Open sahilshivekar opened this issue 5 months ago โ€ข 2 comments

Fixes - Jira-#783

Client Loan Accounts Screen

Before After
image image

Loan Account Profile Screen

Background color for the loan status is same as it's in the web app now

Pending Approval

Before After
image image

Approved

Before After
image image

Active

Before After
image image

Closed (Overpaid)

Before After
App crashes with exception because the send_money.xml file was using @android:color/white. Exception java.lang.IllegalArgumentException: Invalid color value @android:color/white image

Closed (Obligations Met)

Before After
image image

Rejected

Before After
image image

Loan accounts with following loan status not found

Closed (Written Off)

Before After

Closed (Rescheduled)

Before After

Withdrawn by Applicant

Before After

sahilshivekar avatar Jun 26 '26 13:06 sahilshivekar

Review Change Stack

No actionable comments were generated in the recent review. ๐ŸŽ‰

โ„น๏ธ Recent review info
โš™๏ธ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8c35c903-b451-42da-a72e-30151ff892a9

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 81275fef728e7032533ad8bff6956ca1fce79eb8 and 3b74add3dd4cc306780ace21afa47bc7c82f6468.

๐Ÿ“’ Files selected for processing (2)
  • feature/loan/src/commonMain/composeResources/values/strings.xml
  • feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/utils/LoanStatus.kt
๐Ÿšง Files skipped from review as they are similar to previous changes (1)
  • feature/loan/src/commonMain/composeResources/values/strings.xml
๐Ÿ“œ Recent review details
โฐ Context from checks skipped due to timeout. (1)
  • GitHub Check: PR Checks / Static Analysis Check
๐Ÿงฐ Additional context used
๐Ÿ““ Path-based instructions (1)
**/*.kt

โš™๏ธ CodeRabbit configuration file

**/*.kt: Additional Code Review Guidelines:

  1. Null Safety & Stability
  • Avoid using !! operator
  • Handle null cases explicitly using safe calls or proper state handling
  • Do not assume values are always non-null without guarantees
  1. Architecture Boundaries
  • ViewModel must not depend on specific network/library implementations
  • Ensure proper separation between data, domain, and presentation layers
  • Do not format data (currency, dates, calculations) inside the UI layer
  • All formatting must be handled in the ViewModel and exposed via state (e.g., StateFlow)
  1. Performance Considerations
  • Avoid unnecessary recompositions in Compose
  • Do not attach heavy logic to frequently changing states (e.g., scrollState)
  • Prefer lifting state up instead of recomputing in child composables
  1. Compose & Navigation Best Practices
  • NEVER trigger navigation functions or side-effects directly during composition
  • Always wrap navigation calls inside LaunchedEffect or EventsEffect to avoid repeated execution on recomposition
  • Avoid triggering intensive side-effects during recomposition
  • Navigation routes must be type-safe.
  • Ensure all route classes or objects used for navigation are annotated with @Serializable.
  1. UI Structure
  • Dialogs must be separated into their own composables
  • Do not embed dialogs inline within complex main screens
  1. Localization Consistency
  • Ensure all supported languages are updated consistently across modules
  • Verify translations exist for newly added UI strings
  1. Code Cleanliness
  • Avoid unnecessary inline comments unless critical
  • Remove leftover debug or commented code
  1. Focus on correctness, readability, and maintainability over cosmetic nitpicks.
  • Avoid reviewing README, config, or asset files.
  • Prioritize identifying bugs, performance issues, and architectural concerns.
  1. Naming & Intent Rules:
  • Follow the official Kotlin Coding Conventions: https://kotlinlang.org/docs/coding-conventions.html
  • Use self-explanatory ...

Files:

  • feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/utils/LoanStatus.kt
๐Ÿง  Learnings (2)
๐Ÿ“š Learning: 2026-02-06T13:15:16.968Z
Learnt from: sahilshivekar
Repo: openMF/android-client PR: 2603
File: feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/loanTransaction/LoanTransactionsViewModel.kt:43-106
Timestamp: 2026-02-06T13:15:16.968Z
Learning: Guideline: When a Kotlin function parameter is nullable (e.g., balance: Double?, currencyCode: String?, maximumFractionDigits: Int?) and downstream calls require a non-null value, add null-safety handling in all implementations. Specifically, avoid calling Currency.getInstance(currencyCode) with a possibly null currencyCode; provide a safe default (e.g., currencyCode ?: "$") or validate before use. Ensure all platform targets (Android/Desktop/Native) follow consistent null handling, and consider centralizing currencyCode normalization in the common layer if feasible. Add tests covering null currencyCode to prevent NPEs.

Applied to files:

  • feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/utils/LoanStatus.kt
๐Ÿ“š Learning: 2026-04-01T05:03:14.323Z
Learnt from: kartikey004
Repo: openMF/mifos-x-field-officer-app PR: 2659
File: feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/loanDisbursement/LoanAccountDisbursementScreen.kt:190-195
Timestamp: 2026-04-01T05:03:14.323Z
Learning: In this repo, existing `SelectableDates` / `SelectableDates.isSelectableDate(utcTimeMillis: Long)` implementations use `Clock.System.now().toEpochMilliseconds()` (UTC epoch millis) for date-boundary checks. During PR reviews, do not flag these checks for not using a timezone-aware `LocalDate` start-of-day approach; treat it as an established project-wide pattern. If a change is desired, handle it as a coordinated project-wide improvement rather than as a per-PR review issue.

Applied to files:

  • feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/utils/LoanStatus.kt
๐Ÿ”‡ Additional comments (2)
feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/utils/LoanStatus.kt (2)

68-72: LGTM!


74-85: ๐ŸŽฏ Functional Correctness

Verify whether closed also needs an explicit branch.

The upstream status contract still includes a separate closed flag, but this mapper never reads it. If the backend can return closed == true without one of the more specific closed variants, these accounts will now fall through to UNKNOWN, and the downstream screens will render the gray unknown badge/action set instead of a closed state.


Summary by CodeRabbit

  • New Features

    • Improved loan status display with consistent, localized labels and matching colors across loan screens.
    • Added/updated loan status variants (approved, pending approval, active, closed variants, rejected, withdrawn by applicant).
    • Updated next-action behavior to reflect the current loan status (approve, repay, transfer, or view details).
  • Bug Fixes

    • Fixed inconsistent status rendering between loan summary and profile views by using a shared status mapping.
    • Improved loan status badge behavior to always render the correct label and color.
  • Style

    • Updated a drawable icon to use a fixed white fill color for more reliable rendering.

Walkthrough

Loan status handling now uses a shared LoanStatus model across loan profile, summary, and client loan account screens. Loan status strings and theme colors were updated, and the send-money icon fill color changed to white.

Changes

Loan status normalization

Loan status handling is centralized across the loan feature.

Review checkpoint table
Layer / File(s) Summary
Status model and resources
feature/loan/src/commonMain/composeResources/values/strings.xml, core/designsystem/src/commonMain/kotlin/com/mifos/core/designsystem/theme/Color.kt, feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/utils/LoanStatus.kt
Loan status strings and theme colors are defined for the new status set, and LoanStatus maps entity flags to those resources.
Profile state and actions
feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/loanAccountProfile/LoanAccountProfileViewModel.kt, feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/loanAccountProfile/LoanAccountProfileScreen.kt
LoanAccountProfileViewModel now derives status and next actions from getLoanStatus(), and the profile screen consumes the updated state and badge rendering.
Summary and client screens
feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/loanAccountSummary/LoanAccountSummaryScreen.kt, feature/client/src/commonMain/kotlin/com/mifos/feature/client/clientLoanAccounts/ClientLoanAccountsScreen.kt
LoanAccountSummaryScreen and ClientLoanAccountsScreen now render loan statuses through getLoanStatus().

The send-money icon change is separate.

Send money drawable
Layer / File(s) Summary
Icon fill color
core/ui/src/commonMain/composeResources/drawable/send_money.xml
The drawable path fill color changes from the Android white resource to #FFFFFF.

Sequence Diagram(s)

The shared status mapper now feeds profile, summary, and client loan account rendering.

Loan status flow
sequenceDiagram
  participant LoanStatusEntity
  participant LoanAccountProfileViewModel
  participant LoanAccountProfileScreen
  participant LoanAccountSummaryScreen
  participant ClientLoanAccountsScreen

  LoanStatusEntity->>LoanAccountProfileViewModel: loan.status.getLoanStatus()
  LoanAccountProfileViewModel->>LoanAccountProfileScreen: currentStatus and nextActionButtonRes
  LoanStatusEntity->>LoanAccountSummaryScreen: loanWithAssociations.status.getLoanStatus()
  LoanStatusEntity->>ClientLoanAccountsScreen: loan.status.getLoanStatus().label

Estimated code review effort

๐ŸŽฏ 3 (Moderate) | โฑ๏ธ ~25 minutes

๐Ÿšฅ Pre-merge checks | โœ… 3 | โŒ 1

โŒ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
โœ… Passed checks (3 passed)
Check name Status Explanation
Title check โœ… Passed The title matches the PR's main refactor of centralizing loan status mapping across loan screens.
Description check โœ… Passed The description matches the PR by describing the loan status UI refactor and the send_money.xml fix.
Jira Link And Before/After Sections โœ… Passed The PR description has a valid Jira link and multiple non-empty Before/After sections with image media.
โœจ Finishing Touches
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Jun 26 '26 13:06 coderabbitai[bot]

LGTM

Nagarjuna0033 avatar Jun 29 '26 17:06 Nagarjuna0033