Repository navigation
fix: accept hardware input on numeric keypads - #1040
Conversation
|
Warning Review limit reachedNext included review available in 3 seconds. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (14)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughChangesThe PR adds Hardware numeric keyboard
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This localized input-handling change has no actionable merge-blocking risk remaining; the only follow-up concerns an uncommon locale separator case. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant User
participant HardwareNumericKeyboardResponder
participant HardwareNumericKeyboardView
participant NumericKeyboardView
participant AmountScreen
User->>HardwareNumericKeyboardResponder: enter numeric key
HardwareNumericKeyboardResponder->>HardwareNumericKeyboardView: dispatch recognized command
HardwareNumericKeyboardView->>HardwareNumericKeyboardView: update bound amount
HardwareNumericKeyboardView->>NumericKeyboardView: preserve keypad configuration
HardwareNumericKeyboardView->>AmountScreen: publish updated amount
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Replace the UIKeyCommand-based responder with a hidden UITextField that overrides insertText/deleteBackward and suppresses the software keyboard via an empty inputView, matching the existing DWPinField and TwoFactorAuthViewController pattern instead of introducing a fourth keyboard mechanism. This also makes hardware Return trigger the action button (gated the same way as the visible button, including the non-empty-value check), reclaims first responder after a sheet or alert with a text field steals it, and gains native key auto-repeat and paste handling. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
The problem is real and the call-site coverage is complete — all 11 NumericKeyboardView( usages on develop are converted, and the project-file wiring covers both the dashwallet and dashpay targets. My concerns are about where the fix lives and about the first-responder lifecycle.
The fix probably belongs in DashUIKit, not here. NumericKeyboardLocaleSupport.applyKeyPress already encodes exactly these input rules; it is just internal. This PR re-implements it app-side, so there are now two copies of the keypad's input semantics — and they have already diverged in a way that costs money (see the grouping-separator comment). Adding the hardware responder to NumericKeyboardView itself, or at minimum making applyKeyPress public and calling it, would keep one source of truth and give every consumer the fix for free.
The responder is never scoped to the visible screen. A SwiftUI .sheet is a pageSheet and an .overFullScreen PIN prompt keeps the presenter in the window, so the hidden field holds first responder while it is covered — and claimFirstResponderIfIdle() will actively re-take it from a modal that is currently on screen. That cuts both ways: hardware keys keep editing the amount behind a confirmation sheet, and the reclaim can steal focus from the PIN prompt.
Worth considering as an alternative: the deployment target is iOS 17, so UIKeyCommand / pressesBegan on the hosting controller would give the same behaviour without ever taking first responder — key commands travel up the responder chain and are automatically inert while a real text field is focused. That removes the covered-screen, PIN-prompt and paste issues in one move.
Details inline. The grouping-separator issue and the two focus-lifecycle issues should be resolved before merge; the rest are smaller.
One process note: the Tests section says the unit target is pre-existing broken and the new cases are "compile-ready", i.e. unverified. Since they only cover the duplicated pure function and not the responder lifecycle — which is where every problem below lives — they add little confidence either way.
🤖 Reviewed with Claude Code
| ) -> String { | ||
| switch key { | ||
| case .digit(let digit): | ||
| return value + digit |
There was a problem hiding this comment.
This is a second copy of NumericKeyboardLocaleSupport.applyKeyPress (DashUIKit, NumericKeyboardView.swift:41). The two are already out of sync on the grouping separator, and any future change to keypad input rules now has to be made twice, in two repos.
Suggest either making applyKeyPress public and delegating to it, or moving the whole hardware-input concern into NumericKeyboardView so there is one implementation.
| /// Both "." and "," map to the decimal separator: European numpads emit "," | ||
| /// for the decimal key, and the keypad has no grouping-separator concept. | ||
| static func key(for character: Character) -> HardwareNumericKeyboardKey? { | ||
| if character == "." || character == "," { |
There was a problem hiding this comment.
This silently produces amounts 1000x too small in en_US.
NumericKeyboardLocaleSupport.applyKeyPress deliberately rejects the locale's grouping separator when it differs from the decimal separator:
if !groupingSeparator.isEmpty, key == groupingSeparator, groupingSeparator != decimalSeparator {
return value
}Here , is mapped to the decimal separator unconditionally. In en_US (grouping ,, decimal .) a user typing 1,000 on a hardware keyboard gets 1.000 instead of 1000 — on Send, Pay, DashSpend and the withdrawal screens. The on-screen keypad and the hardware path disagree about the same keystroke.
The locale mapping should be: . and , both map to the decimal separator only when they are not the locale's grouping separator; otherwise the character should be dropped, matching applyKeyPress.
| helperText: helperText, | ||
| actionHandler: actionHandler | ||
| ) | ||
| .background { |
There was a problem hiding this comment.
The hidden field is only resigned implicitly, when the view leaves the window. A SwiftUI .sheet is presented as a pageSheet, so the presenting screen stays in the window and keeps first responder while it is covered.
Concretely, InternalTransferScreen presents its confirmation over this keypad: while the user reads the confirmation, hardware digits still mutate keypadBinding behind it, and Return re-invokes presentConfirmation(), reassigning .sheet(item:) to a new identity while it is already presented. Same shape in SendScreen (SendConfirmSheet), EvonodeWithdrawalScreen and DashSpendSinglePanel.
The field needs to resign when the screen is covered or disappears, not only when it is torn out of the window.
|
|
||
| // MARK: - UIKeyInput | ||
|
|
||
| override func insertText(_ text: String) { |
There was a problem hiding this comment.
With the hidden field focused, Cmd-V is now routed into it, but neither paste(_:) nor canPerformAction(_:withSender:) is overridden. Either UIKit funnels the pasted string through this insertText — which mangles grouped input (1,234.56 -> 1.23456, per the separator comment above) and bypasses PastedAmountParser / BaseAmountModel.pasteFromClipboard, which exist precisely to parse that correctly — or it goes through replace(_:withText:), in which case Cmd-V silently does nothing and overwrites the ZWSP sentinel that deleteBackward depends on.
Worth explicitly handling paste (delegate to the existing parser) or refusing it.
| onKey?(.delete) | ||
| } | ||
|
|
||
| func textFieldShouldReturn(_ textField: UITextField) -> Bool { |
There was a problem hiding this comment.
onReturn can fire from two paths for a single Return keypress: here, and from the "\n" / "\r" branch in insertText above. Both would run synchronously, before SwiftUI can propagate inProgress and before updateUIView nils out onReturn.
In PayContactSheet the action handler is pay(), i.e. an actual send with no confirmation step — so a double fire is a double payment. Please keep a single path (textFieldShouldReturn seems the right one, and it should also guard inputEnabled), or add a local re-entrancy guard.
Separately, worth confirming as a product decision that hardware Return should execute a contact payment outright; the on-screen keypad requires a deliberate button tap.
| // prompt) steals first responder while this view stays in the window, | ||
| // so `didMoveToWindow` alone would leave hardware input dead after | ||
| // dismissal. Reclaim whenever any other editor ends editing. | ||
| for name in [UITextField.textDidEndEditingNotification, UITextView.textDidEndEditingNotification] { |
There was a problem hiding this comment.
The comment above says this reclaim covers the PIN prompt, but the observer only listens for UITextField / UITextView end-editing. DWPinField is a UIView <UITextInput> (DWPinField.h:41) and posts neither notification, and there is no reclaim on app foregrounding or on a failed becomeFirstResponder.
So after the lock screen or any non-UITextField responder takes and releases focus over a keypad screen that is still in the window, hardware input on that screen stays dead until the view is rebuilt — which is the exact failure this class was written to prevent, in the most common flow in the app (amount -> PIN -> back).
| } | ||
| } | ||
|
|
||
| private func claimFirstResponderIfIdle() { |
There was a problem hiding this comment.
This re-claims focus for a screen that may currently be covered by a modal: the observer is registered with object: nil, so it fires on any UITextField / UITextView end-editing app-wide, and the only guard is "some other UITextInput happens to be focused right now".
Failure case: send-amount screen -> PIN prompt (PinPromptPresenter presents .overFullScreen, so the amount screen stays in the window) -> wrong PIN -> PinPromptView recreates its hidden field via .id(fieldGeneration), the old field ends editing, and its own refocus() only re-asserts focus on the next main-actor tick. This reclaim is scheduled on the same runloop turn and wins: the invisible keypad field under the prompt becomes first responder, the PIN keyboard dies, and typed PIN digits go into the amount behind the prompt. The currency picker's search field (DWLocalCurrencyViewController, opened from SendAmountScreen) reaches the same state.
Also note becomeFirstResponder() here has no key-window check. DWAppRootViewController.m:520-548 documents and works around exactly this hazard for the separate lockWindow; an always-on reclaim in a covered main window can trigger it on any stray end-editing notification.
At minimum this needs a "is my window key and is my screen actually visible / not covered by a presented controller" check before claiming.
| return FirstResponderProbe.current | ||
| } | ||
|
|
||
| @objc private func captureFirstResponder() { |
There was a problem hiding this comment.
Nit: private in Swift does not scope the ObjC selector — this installs captureFirstResponder on UIResponder process-wide, so it can collide with the same well-known trick in a pod or another file. A prefixed name (dw_captureFirstResponder) is safer.
Follow-up to the review on dashpay#1040. - Make `key(for:)` locale-aware so it drops the locale's grouping separator, matching `NumericKeyboardLocaleSupport.applyKeyPress`. Typing `1,000` in `en_US` produced `1.000` — a silent 1000x error on the send and pay screens. - Only act while the field's own screen is frontmost: its window is key and its view controller is the frontmost presented controller of that window, or is contained in it. A SwiftUI `.sheet` is a `pageSheet` and the PIN prompt is `.overFullScreen`, so the keypad screen stays in the window and previously kept consuming keys from behind the modal. - Give focus up as well as take it, and drive the reclaim from `updateUIView` too, so a dismissed sheet restores hardware input. - Widen the reclaim triggers to keyboard-did-hide and the window/app notifications. `DWPinField` is a `UIView<UITextInput>` and posts no end-editing notification, so hardware input stayed dead after a PIN prompt — the most common flow on these screens. - Collapse the two deliveries of a single hardware Return (`insertText("\n")` and `textFieldShouldReturn`) into one action. `PayContactSheet`'s handler sends money outright, and both deliveries land before SwiftUI can propagate `inProgress`. - Refuse cut/copy/paste on the hidden field. Cmd-V went through `insertText`, mangling grouped input and bypassing `PastedAmountParser`, or through `replace(_:withText:)`, corrupting the sentinel. - Prefix the `UIResponder` probe selector; `private` does not scope an ObjC selector installed process-wide. Tests cover the locale-aware separator mapping and that a grouped amount keeps its magnitude.
The three entries added for `HardwareNumericKeyboardView.swift` used hand-written `C0DE0001…` identifiers rather than the 24-hex identifiers Xcode generates. Functionally equivalent, but they read as placeholders in a file Xcode otherwise owns.
dashpay/DashUIKit#16 made `NumericKeyboardLocaleSupport` public, so the app no longer has to carry its own copy of the keypad's input rules. `key(forTyped:locale:)` maps a typed character to the key the on-screen keypad would have sent, and `applyKeyPress` decides what that key does to the value. Both input paths now run the same code, so they cannot drift apart again — which is how "1,000" typed in en_US came to produce "1.000". The app-side tests go with the app-side copy; the rules are covered by `NumericKeyboardLocaleSupportTests` in the package, including the grouping-separator cases.
romchornyi
left a comment
There was a problem hiding this comment.
Superseding my earlier review — every finding is addressed. I pushed the fixes to this branch across three commits:
f8987818c — the six correctness issues:
key(for:)mapped,to the decimal separator in every locale, so1,000typed inen_USbecame1.000. Now locale-aware and matching what the on-screen keypad does with the same keystroke.- The hidden responder was not scoped to the visible screen. A SwiftUI
.sheetis apageSheetand the PIN prompt is.overFullScreen, so the keypad kept consuming keys from behind a modal, and the reclaim could take focus back from the PIN prompt. Now gated on the field's screen being the frontmost presented controller of the key window. - Hardware input stayed dead after a PIN prompt, because the reclaim only listened for
UITextField/UITextViewend-editing andDWPinFieldis aUIView<UITextInput>. Widened to keyboard-did-hide plus the window and app notifications, all funnelled through the same ownership check. - A single Return arrived twice —
insertText("\n")andtextFieldShouldReturn— and both landed beforeinProgresscould propagate.PayContactSheet's handler sends money outright, so they are now collapsed into one. - Cmd-V went through the overridden
insertText, mangling grouped input and bypassingPastedAmountParser. Cut/copy/paste are refused on the field. - The
UIResponderprobe selector is prefixed;privatedoes not scope an ObjC selector installed process-wide.
e84ba1cd2 — replaced the hand-written C0DE0001… project-file identifiers with generated ones.
af11e47da — removed the app-side copy of the keypad rules. dashpay/DashUIKit#16 made NumericKeyboardLocaleSupport public, so both input paths now run the same applyKeyPress and cannot drift apart again; the rules are covered by NumericKeyboardLocaleSupportTests in the package, including the grouping-separator cases. The DashUIKit revision recorded in Package.resolved moves to 83cf65a accordingly (the requirement was already branch = master).
032c6b12f — merged develop. The branch was 67 commits behind and no longer compiled: develop had moved from the static PlatformWalletManager.estimateShieldedFee to SwiftDashSDKHost.shared.manager?.estimateShieldedFee.
Verified with a clean dashpay build for the arm64 iOS Simulator. The hardware-keyboard behaviour itself was not exercised on a device — simctl cannot deliver hardware key events — so the responder changes are verified by compilation and by reading, not by use.
🤖 Reviewed with Claude Code
Issue being fixed or feature implemented
DashUIKit's integrated numeric keypad is rendered as buttons and does not install a text responder. As a result, digits and decimal separators typed with a connected physical keyboard—or the Mac keyboard attached to Simulator—are discarded on amount and numeric-authentication screens.
What was done?
How Has This Been Tested?
dashpayscheme for the arm64 iOS Simulator:xcodebuild -quiet -workspace DashWallet.xcworkspace -scheme dashpay -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' ARCHS=arm64 build0.01through Simulator hardware-key events and verified the displayed amount and enabled Continue state updated immediately.2key afterward and verified the amount became0.012, confirming the on-screen keypad remains functional.CLAUDE.md; the new unit cases are compile-ready.Breaking Changes
None.
Checklist:
For repository code-owners and collaborators only
This pull request was created by Codex.
Summary by CodeRabbit
New Features
Tests