fix: respect source amount cursor position#27367
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
…to swaps-input-cursor # Conflicts: # app/components/UI/Bridge/Views/BridgeView/__snapshots__/BridgeView.test.tsx.snap # app/components/UI/Bridge/Views/BridgeView/index.tsx
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
These changes affect the Bridge/Swap flow UX (amount input, quick-pick presets, flip tokens button). The SmokeTrade tag covers bridge and swap flows. Per the tag description, SmokeTrade requires SmokeConfirmations since transaction confirmations are part of the swap/bridge flow. No changes to: core controllers, Engine, navigation, account management, network management, identity/sync, or any other feature areas. No performance-critical code paths (no list rendering, no startup code, no state management infrastructure). Performance Test Selection: |
|
✅ E2E Fixture Validation — Schema is up to date |
|
| **Description** | **Input** | **Key(s) Pressed** | **Cursor position** | **Expected** | **iOS Actual** | **Android Actual** | **iOS Result** | **Android Result** |
|--------------------------------------------------------------------------------------------------------|-------------|--------------------|---------------------|--------------|----------------|--------------------|:--------------:|:----------------------------------------------------------------------------------------------------------------------:|
| adding the value 1 into empty input appends at the end | "" | 1 | 0 | 1 | 1 | 1 | ✅ | ✅ |
| adding the value 1. into empty input appends at the end | "" | 1. | 0 | 1. | 1. | 1. | ✅ | ✅ |
| adding the value 1.2 into empty input appends at the end | "" | 1.2 | 0 | 1.2 | 1.2 | 1.2 | ✅ | ✅ |
| removing last character from a value | "1.2" | <Backspace> | 3 | 1. | 1. | 1. | ✅ | ✅ |
| adding (dot) character at the end of an integer does not break value | "23" | . | 2 | 23. | 23. | 23. | ✅ | ✅ |
| removing (dot) character at the end of an integer does not break value | "23." | <Backspace> | 3 | 23 | 23 | 23 | ✅ | ✅ |
| adding (dot) as first character appends to zero | "" | . | 0 | 0. | 0. | 0. | ✅ | ✅ |
| should not add second (dot) immediately after a (dot) | "0." | . | 2 | 0. | 0. | 0. | ✅ | ✅ |
| should not add second (dot) in decimal if already present | "0.0234" | . | 6 | 0.0234 | 0.0234 | 0.0234 | ✅ | ✅ |
| should not add second (dot) in decimal if already present | "0.0234" | . | 2 | 0.0234 | 0.0234 | 0.0234 | ✅ | ✅ |
| should not add second (dot) in decimal if already present | "0.0234" | . | 0 | 0.0234 | 0.0234 | 0.0234 | ✅ | ✅ |
| deleting (dot) when number is zero should result in a single zero | "0.00000" | <Backspace> | 3 | 0 | 0 | 0 | ✅ | ✅ |
| should delete correct character in integer value when cursor is place inside | "2,365" | <Backspace> | 3 | 235 | 235 | 235 | ✅ | ✅ |
| should delete correct character in integer value when cursor is place inside | "2,365" | <Backspace> | 1 | 265 | 265 | 265 | ✅ | ✅ |
| removing (dot) at the middle of a number should turn the number into integer and not adjust formatting | "5,899.58" | <Backspace> | 5 | 589,958 | 589,958 | 589,958 | ✅ | ✅ |
| adding (dot) at the middle of a number should turn the number into integer and not adjust formatting | "589,958" | . | 5 | 58,995.8 | 58,995.8 | 58,995.8 | ✅ | ✅ |
| adding (dot) at formatted position where comma exist, should update the value and reformat | "1,556,234" | . | 4 | 1,556.234 | 1,556.234 | 1,556.234 | ✅ | ✅ |
| pressing keypad numbers quickly should always append to last cursor position | "" | 745347878 | 0 | 745,347,878 | 745,347,878 | 745,347,878 | ✅ | ⚠️ Sometimes the cursor position moves around when pressing keypads quickly and do not wait a bit between each keypress | |




Description
This PR fixes Bridge source amount editing so keypad insertion and deletion respect the user-selected cursor position, including when the displayed amount contains locale formatting such as grouping separators.
The change keeps shared keypad components untouched and instead adds Bridge-local cursor handling:
useSourceAmountCursorto own source cursor state and keypad edit behaviorapplyKeyAtCursorso insert/delete/decimal edits happen deterministically at the raw cursor positionTokenInputAreato support sourceselectionandonSelectionChangeChangelog
CHANGELOG entry: Fixed a bug where Bridge amount edits did not respect the cursor position when using the keypad.
Related issues
Fixes: SWAPS-4131
Manual testing steps
Screenshots/Recordings
Before
N/A
After
Screen.Recording.2026-03-18.at.12.02.49.mov
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes how Bridge source amounts are edited and selected, including cursor mapping between formatted display values and raw input, which could impact entered swap amounts. Covered by new unit tests but touches core user input behavior.
Overview
Fixes Bridge source-amount editing so keypad insert/delete operations apply at the user-selected caret position even when the displayed amount includes locale formatting (grouping/decimal separators).
Adds
useSourceAmountCursorplus new cursor-mapping and edit utilities (cursorPosition,applyKeyAtCursor) and wires controlledselection/onSelectionChangethroughTokenInputArea. Also updates Max/preset flows to normalize amounts vianormalizeSourceAmountToMaxLengthand changes gasless quick-pick presets to explicitly replace the amount (newonAmountSelect+tokenBalanceprop), with updated/added tests.Written by Cursor Bugbot for commit 166c4cd. This will update automatically on new commits. Configure here.