Skip to content

Fix: App crash when entered amount exceeds 100,000 in Receive Money screen#2005

Open
rahul31124 wants to merge 1 commit intoopenMF:developmentfrom
rahul31124:exceeding_amount
Open

Fix: App crash when entered amount exceeds 100,000 in Receive Money screen#2005
rahul31124 wants to merge 1 commit intoopenMF:developmentfrom
rahul31124:exceeding_amount

Conversation

@rahul31124
Copy link
Copy Markdown

@rahul31124 rahul31124 commented Apr 11, 2026

Issue Fix

Fixes #{MM-579}
Jira Task: MM-579

Screenshots

Record_2026-04-11-14-25-33_6a5d239ecc870d7d1b844aa672071987.mp4

Description

  • ViewModel (MpayQrViewModel.kt)

    • Added ShowSnackbar and CopyToClipboard to MpayQrAction and MpayQrEvent.
    • Implemented handling for these actions in handleAction() and emitted events using sendEvent().
    • Added validation for the entered amount to prevent crashes when the value exceeds the allowed limit.
  • UI (MpayQrScreen.kt)

    • Updated EventsEffect(viewModel) to handle new events.
    • ShowSnackbar displays messages using snackbarHostState.
    • CopyToClipboard copies text using clipboardManager and shows a confirmation snackbar.

Result

  • The app no longer crashes when the entered amount is greater than 100,000.
  • Users now receive proper feedback through snackbars.

Code Quality

  • Reformatted files (using Ctrl + Alt + L).

  • Apply the AndroidStyle.xml style template to your code in Android Studio.

  • Run the unit tests with ./gradlew check to make sure you didn't break anything

  • If you have multiple commits please combine them into one commit by squashing them.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for QR code generation with clearer error messaging.
  • Improvements

    • Separated clipboard copy and message notification flows for better UX clarity.
    • Clipboard copy operations now provide explicit confirmation feedback.

@rahul31124 rahul31124 requested a review from a team April 11, 2026 11:06
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

📝 Walkthrough

Walkthrough

This PR separates snackbar and clipboard concerns in the Mpay QR feature by introducing a new CopyToClipboard event type, refactoring screen event handling, and updating viewmodel logic to distinguish between notification and clipboard flows while adding error handling for QR encoding operations.

Changes

Cohort / File(s) Summary
Screen Event Handling
feature/mpay-qr/src/commonMain/kotlin/org/mifospay/feature/mpay/qr/MpayQrScreen.kt
Refactored event handling: ShowSnackbar now only displays snackbar messages; new CopyToClipboard event copies text to clipboard and shows "copied" confirmation message.
ViewModel Event & Action Types
feature/mpay-qr/src/commonMain/kotlin/org/mifospay/feature/mpay/qr/MpayQrViewModel.kt
Added new event type CopyToClipboard(text: String) and action type ShowSnackbar(message: String) to separate clipboard and notification concerns. Updated action handlers to emit appropriate event types. Simplified loadAccounts() control flow and added try-catch error handling in initiateSetAmount() for QR encoding exceptions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A clipboard quest, a snackbar's delight,
Events now separated, concerns held tight,
QR codes dance with error-handling care,
Refactored flows floating through the air! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing an app crash when the entered amount exceeds 100,000 in the Receive Money screen, which aligns with the PR's primary objective of adding validation to prevent this crash.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@feature/mpay-qr/src/commonMain/kotlin/org/mifospay/feature/mpay/qr/MpayQrViewModel.kt`:
- Around line 331-334: In the IllegalArgumentException catch inside
MpayQrViewModel, you're currently only clearing dialogState and showing a
snackbar but leaving the invalid value in state.qrData.amount; update the state
there to remove or rollback the bad amount so future calls to
encodeMpayString(state.qrData) won't rethrow (e.g., call mutableStateFlow.update
and set qrData.amount to null or to the previous valid value), ensuring the
catch block resets qrData.amount as well as dialogState before emitting the
snackbar.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 714a24e2-56a7-43e9-bbf0-3c9a2c1e01b1

📥 Commits

Reviewing files that changed from the base of the PR and between d399e0a and 6ceed82.

📒 Files selected for processing (2)
  • feature/mpay-qr/src/commonMain/kotlin/org/mifospay/feature/mpay/qr/MpayQrScreen.kt
  • feature/mpay-qr/src/commonMain/kotlin/org/mifospay/feature/mpay/qr/MpayQrViewModel.kt

Comment on lines +331 to +334
} catch (e: IllegalArgumentException) {
mutableStateFlow.update { it.copy(dialogState = null) }
sendEvent(MpayQrEvent.ShowSnackbar(e.message ?: "Invalid amount entered"))
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Invalid amount is left in state, so a crash path still exists.

After Line 333, the invalid value remains in state.qrData.amount. A later QR regeneration (e.g., account switch) can still hit encodeMpayString(state.qrData) and throw again. Clear or rollback invalid amount in this catch path.

Proposed fix
             } catch (e: IllegalArgumentException) {
-                mutableStateFlow.update { it.copy(dialogState = null) }
+                mutableStateFlow.update {
+                    it.copy(
+                        dialogState = null,
+                        qrData = it.qrData.copy(amount = ""),
+                    )
+                }
                 sendEvent(MpayQrEvent.ShowSnackbar(e.message ?: "Invalid amount entered"))
             }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (e: IllegalArgumentException) {
mutableStateFlow.update { it.copy(dialogState = null) }
sendEvent(MpayQrEvent.ShowSnackbar(e.message ?: "Invalid amount entered"))
}
} catch (e: IllegalArgumentException) {
mutableStateFlow.update {
it.copy(
dialogState = null,
qrData = it.qrData.copy(amount = ""),
)
}
sendEvent(MpayQrEvent.ShowSnackbar(e.message ?: "Invalid amount entered"))
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@feature/mpay-qr/src/commonMain/kotlin/org/mifospay/feature/mpay/qr/MpayQrViewModel.kt`
around lines 331 - 334, In the IllegalArgumentException catch inside
MpayQrViewModel, you're currently only clearing dialogState and showing a
snackbar but leaving the invalid value in state.qrData.amount; update the state
there to remove or rollback the bad amount so future calls to
encodeMpayString(state.qrData) won't rethrow (e.g., call mutableStateFlow.update
and set qrData.amount to null or to the previous valid value), ensuring the
catch block resets qrData.amount as well as dialogState before emitting the
snackbar.

@biplab1
Copy link
Copy Markdown
Contributor

biplab1 commented Apr 12, 2026

@rahul31124 Welcome to our community! Thank you for your PR.

Please go through this document if you haven't already https://mifosforge.jira.com/wiki/spaces/MP/pages/4537024513/Welcome+to+the+Mifos+Mobile+Apps+Community and feel free to sign up for the daily standup meeting (Mon - Fri, 10 PM IST). Link is in the document.

@rahul31124
Copy link
Copy Markdown
Author

Hello @biplab1, thank you for guiding me. I have already gone through the document and have joined the Slack channel.
Could you please review this PR when you get a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants