Skip to content

fix: accept hardware input on numeric keypads - #1040

Merged
romchornyi merged 6 commits into
dashpay:developfrom
PastaPastaPasta:fix/balance-hardware-keyboard
Aug 28, 2026
Merged

romchornyi merged 6 commits into
dashpay:developfrom
PastaPastaPasta:fix/balance-hardware-keyboard

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Aug 22, 2026 •

Copy link
Copy Markdown
Member

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?

  • Added an app-level numeric keypad wrapper that preserves the existing DashUIKit keypad and action behavior.
  • Added a hidden UIKit first responder that accepts hardware digits, locale-aware decimal input, and Backspace without presenting a second software keyboard.
  • Adopted the wrapper at every integrated numeric-keypad call site so send, internal transfer, receive amount, swap, Coinbase, DashSpend, contact payment, evonode withdrawal, and OTP entry behave consistently.
  • Added compile-ready tests for digit entry, deletion, locale decimal separators, duplicate separators, and integer-only input.

How Has This Been Tested?

  • Built the dashpay scheme for the arm64 iOS Simulator:
    xcodebuild -quiet -workspace DashWallet.xcworkspace -scheme dashpay -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' ARCHS=arm64 build
  • Installed the build on an iOS 26.5 testnet simulator and opened the balance-row Internal send screen.
  • Sent 0.01 through Simulator hardware-key events and verified the displayed amount and enabled Continue state updated immediately.
  • Tapped the integrated 2 key afterward and verified the amount became 0.012, confirming the on-screen keypad remains functional.
  • The repository's unit-test target remains pre-existing broken as documented in CLAUDE.md; the new unit cases are compile-ready.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

This pull request was created by Codex.

Summary by CodeRabbit

  • New Features

    • Numeric entry fields now support physical keyboard input alongside the on-screen keypad.
    • Digit, decimal separator, and delete keys work with locale-aware formatting.
    • Physical input is appropriately disabled while actions are processing.
    • Updated amount entry, payments, transfers, swaps, withdrawals, and authentication screens to use the enhanced input experience.
  • Tests

    • Added coverage for digit entry, deletion, decimal separator handling, and duplicate prevention.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

Next included review available in 3 seconds.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2e93a11f-b20f-43f8-b7f9-7706d33110e6

📥 Commits

Reviewing files that changed from the base of the PR and between 7354a34 and 032c6b1.

⛔ Files ignored due to path filters (1)
  • DashWallet.xcworkspace/xcshareddata/swiftpm/Package.resolved is excluded by !**/Package.resolved
📒 Files selected for processing (6)
  • DashWallet.xcodeproj/project.pbxproj
  • DashWallet/Sources/UI/Menu/Tools/Masternode Withdrawal/EvonodeWithdrawalScreen.swift
  • DashWallet/Sources/UI/Payments/Pay/SendScreen.swift
  • DashWallet/Sources/UI/Swap/Buy/EnterAmount/BuyEnterAmountView.swift
  • DashWallet/Sources/UI/Swap/Convert/SwapConvertView.swift
  • DashWallet/Sources/UI/SwiftUI Components/HardwareNumericKeyboardView.swift

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 297e3559-d762-41e7-9d8a-2a285a0fff27

📥 Commits

Reviewing files that changed from the base of the PR and between 6bd8338 and 7354a34.

📒 Files selected for processing (14)
  • DashWallet.xcodeproj/project.pbxproj
  • DashWallet/Sources/UI/Coinbase/Transfer Amount/TransferAmountView.swift
  • DashWallet/Sources/UI/DashPay/Contacts/SwiftUI/ContactProfileSheet.swift
  • DashWallet/Sources/UI/Explore Dash/Views/DashSpend/Components/DashSpendSinglePanel.swift
  • DashWallet/Sources/UI/Explore Dash/Views/DashSpend/DashSpendUserAuthScreen.swift
  • DashWallet/Sources/UI/Menu/Tools/Masternode Withdrawal/EvonodeWithdrawalScreen.swift
  • DashWallet/Sources/UI/Payments/Amount/SendAmountScreen.swift
  • DashWallet/Sources/UI/Payments/Amount/SpecifyAmountViewController.swift
  • DashWallet/Sources/UI/Payments/InternalTransfer/InternalTransferScreen.swift
  • DashWallet/Sources/UI/Payments/Pay/SendScreen.swift
  • DashWallet/Sources/UI/Swap/Buy/EnterAmount/BuyEnterAmountView.swift
  • DashWallet/Sources/UI/Swap/Convert/SwapConvertView.swift
  • DashWallet/Sources/UI/SwiftUI Components/HardwareNumericKeyboardView.swift
  • DashWalletTests/AmountObjectTests.swift

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Changes

The PR adds HardwareNumericKeyboardView, which combines the existing DashUIKit keypad with hardware keyboard input. It adds locale-aware digit, decimal, and deletion handling, then adopts the component across amount-entry and OTP screens.

Hardware numeric keyboard

Layer / File(s) Summary
Hardware input component
DashWallet/Sources/UI/SwiftUI Components/HardwareNumericKeyboardView.swift, DashWalletTests/AmountObjectTests.swift
The new wrapper forwards existing keypad configuration and handles physical digit, decimal, and delete commands. Tests cover deletion, locale-specific separators, duplicate separators, and hidden decimal input.
Screen integration
DashWallet/Sources/UI/Coinbase/Transfer Amount/TransferAmountView.swift, DashWallet/Sources/UI/DashPay/Contacts/SwiftUI/ContactProfileSheet.swift, DashWallet/Sources/UI/Explore Dash/Views/DashSpend/..., DashWallet/Sources/UI/Menu/Tools/Masternode Withdrawal/EvonodeWithdrawalScreen.swift, DashWallet/Sources/UI/Payments/..., DashWallet/Sources/UI/Swap/...
The affected screens now use HardwareNumericKeyboardView. Existing bindings, validation, actions, loading states, and layout configuration remain unchanged.
Xcode project registration
DashWallet.xcodeproj/project.pbxproj
The new Swift file is registered in the project group, file references, build files, and two target compilation phases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 7354a

This localized input-handling change has no actionable merge-blocking risk remaining; the only follow-up concerns an uncommon locale separator case.

Suggested reviewers: jeanpierreroma, romchornyi, quantumexplorer

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: enabling hardware keyboard input for numeric keypads.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

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]>

@romchornyi romchornyi left a comment •

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.

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

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.

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 == "," {

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.

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 {

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.

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) {

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.

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 {

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.

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] {

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.

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() {

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.

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() {

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.

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.
@llbartekll
llbartekll self-requested a review August 28, 2026 08:48
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 romchornyi left a comment

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.

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, so 1,000 typed in en_US became 1.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 .sheet is a pageSheet and 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/UITextView end-editing and DWPinField is a UIView<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") and textFieldShouldReturn — and both landed before inProgress could 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 bypassing PastedAmountParser. Cut/copy/paste are refused on the field.
  • The UIResponder probe selector is prefixed; private does 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

@romchornyi
romchornyi merged commit fb98a33 into dashpay:develop Aug 28, 2026
1 check passed
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.

4 participants