fix: set transfer amount to max on cap error#1013
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f495670474
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Greptile SummaryThis PR ports the "snap to max on cap exceeded" behavior from iOS to Android. When the user types an amount above the spending cap on the Transfer to Spending screen (and on the Advanced screen), the input now snaps to the current maximum rather than being silently blocked. The quarter-amount capping logic is also moved from the UI layer into the ViewModel.
Confidence Score: 4/5Safe to merge for the primary happy path; the open question from the previous review thread about whether The change is narrow and well-contained: two UI screens and one ViewModel. The The
|
| Filename | Overview |
|---|---|
| app/src/main/java/to/bitkit/ui/screens/transfer/SpendingAmountScreen.kt | Adds MaxExceeded snap-to-max behavior with currentCurrencies fix; removes viewModel.updateLimits() from both MAX and quarter paths — the previous thread noted this gap in the MaxExceeded path specifically. |
| app/src/main/java/to/bitkit/ui/screens/transfer/SpendingAdvancedScreen.kt | Applies the same snap-to-max pattern for the advanced-screen cap; correctly uses currentCurrencies via rememberUpdatedState. |
| app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt | Moves quarter-amount calculation into the ViewModel and exposes it as quarterAmount in state; removes the balanceAfterFeeQuarter() helper. The min(..., maxSend) guard on quarterAmount is mathematically redundant (25% ≤ 100%) but harmless. |
| app/src/test/java/to/bitkit/viewmodels/TransferViewModelTest.kt | Adds an assertion for the new quarterAmount field; test coverage is proportionate to the ViewModel change. |
| changelog.d/next/1013.fixed.md | Adds changelog entry for the fix; correctly placed in the next fragment directory. |
Sequence Diagram
sequenceDiagram
participant User
participant SpendingAmountScreen
participant AmountInputViewModel
participant TransferViewModel
User->>AmountInputViewModel: "types amount > max"
AmountInputViewModel-->>SpendingAmountScreen: emit MaxExceeded effect
SpendingAmountScreen->>AmountInputViewModel: setSats(currentMaxAllowedToSend, currentCurrencies)
SpendingAmountScreen->>SpendingAmountScreen: show toast
User->>SpendingAmountScreen: tap MAX button
SpendingAmountScreen->>AmountInputViewModel: setSats(uiState.maxAllowedToSend, currencies)
User->>SpendingAmountScreen: tap 25% button
SpendingAmountScreen->>AmountInputViewModel: setSats(uiState.quarterAmount, currencies)
Note over TransferViewModel: quarterAmount pre-computed in ViewModel
User->>SpendingAmountScreen: tap Continue
SpendingAmountScreen->>TransferViewModel: onConfirmAmount(sats)
Reviews (2): Last reviewed commit: "fix: stale currencies" | Re-trigger Greptile
|
I didn't implement on send flows because could cause issues on services that require exact amounts like Boltz if the user don't see that the amount was auto-capped |
This PR makes the Transfer to Spending amount screen fill in the maximum transferable amount when you try to enter a value above the cap, instead of only flashing an error toast.
Description
Previously, entering an amount above the spending maximum on the Transfer to Spending screen blocked the input and showed the "Spending Balance Maximum" toast while leaving the field unchanged. Now, when the cap is exceeded, the amount snaps to the current maximum allowed to send and the toast still appears, so it is a single step to continue with the largest possible transfer.
This ports the max-exceeded behavior from the iOS fix in synonymdev/bitkit-ios#595. The two-pass LSP max-client-balance clamping that the iOS PR also introduced already exists on Android in the transfer view model, so this change is limited to the input-snapping behavior.
Preview
Screen_recording_20260615_082049.webm
QA Notes
Manual Tests
regression:Spending Amount → tap MAX: amount fills to the maximum.regression:Spending Amount → tap 25%: amount is the quarter capped to the maximum.Automated Checks
just compilepasses.