Fix: App crash when entered amount exceeds 100,000 in Receive Money screen#2005
Fix: App crash when entered amount exceeds 100,000 in Receive Money screen#2005rahul31124 wants to merge 1 commit intoopenMF:developmentfrom
Conversation
📝 WalkthroughWalkthroughThis PR separates snackbar and clipboard concerns in the Mpay QR feature by introducing a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
feature/mpay-qr/src/commonMain/kotlin/org/mifospay/feature/mpay/qr/MpayQrScreen.ktfeature/mpay-qr/src/commonMain/kotlin/org/mifospay/feature/mpay/qr/MpayQrViewModel.kt
| } catch (e: IllegalArgumentException) { | ||
| mutableStateFlow.update { it.copy(dialogState = null) } | ||
| sendEvent(MpayQrEvent.ShowSnackbar(e.message ?: "Invalid amount entered")) | ||
| } |
There was a problem hiding this comment.
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.
| } 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.
|
@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. |
|
Hello @biplab1, thank you for guiding me. I have already gone through the document and have joined the Slack channel. |
Issue Fix
Fixes #{MM-579}
Jira Task: MM-579
Screenshots
Record_2026-04-11-14-25-33_6a5d239ecc870d7d1b844aa672071987.mp4
Description
ViewModel (
MpayQrViewModel.kt)ShowSnackbarandCopyToClipboardtoMpayQrActionandMpayQrEvent.handleAction()and emitted events usingsendEvent().UI (
MpayQrScreen.kt)EventsEffect(viewModel)to handle new events.ShowSnackbardisplays messages usingsnackbarHostState.CopyToClipboardcopies text usingclipboardManagerand shows a confirmation snackbar.Result
Code Quality
Ctrl + Alt + L).Apply the
AndroidStyle.xmlstyle template to your code in Android Studio.Run the unit tests with
./gradlew checkto make sure you didn't break anythingIf you have multiple commits please combine them into one commit by squashing them.
Summary by CodeRabbit
Bug Fixes
Improvements