Skip to content

Commit 0be7feb

Browse files
committed
chore: allow manually running CI on draft PR
1 parent 6f91ccf commit 0be7feb

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Bitkit/ViewModels/AmountInputViewModel.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ class AmountInputViewModel: ObservableObject {
9696
amountSats = newAmountSats
9797
displayText = formatDisplayTextFromAmount(newAmountSats, currency: currency)
9898
// Update raw input text based on the formatted display
99+
// Remove formatting separators (spaces for modern Bitcoin, commas for fiat)
99100
if currency.primaryDisplay == .fiat {
100101
rawInputText = displayText.replacingOccurrences(of: ",", with: "")
102+
} else if currency.displayUnit == .modern {
103+
// Modern Bitcoin uses spaces as grouping separators
104+
rawInputText = displayText.replacingOccurrences(of: " ", with: "")
101105
} else {
102106
rawInputText = displayText
103107
}
@@ -115,8 +119,12 @@ class AmountInputViewModel: ObservableObject {
115119
if amountSats > 0 {
116120
displayText = formatDisplayTextFromAmount(amountSats, currency: currency)
117121
// Update raw input text based on the formatted display
122+
// Remove formatting separators (spaces for modern Bitcoin, commas for fiat)
118123
if currency.primaryDisplay == .fiat {
119124
rawInputText = displayText.replacingOccurrences(of: ",", with: "")
125+
} else if currency.displayUnit == .modern {
126+
// Modern Bitcoin uses spaces as grouping separators
127+
rawInputText = displayText.replacingOccurrences(of: " ", with: "")
120128
} else {
121129
rawInputText = displayText
122130
}
@@ -135,8 +143,14 @@ class AmountInputViewModel: ObservableObject {
135143
// First convert fiat to sats, then format for Bitcoin display
136144
let cleanFiat = currentRawInput.replacingOccurrences(of: ",", with: "")
137145
if let fiatValue = Double(cleanFiat), let sats = currency.convert(fiatAmount: fiatValue) {
138-
rawInputText = formatBitcoinFromSats(sats, isModern: currency.displayUnit == .modern)
139-
displayText = rawInputText
146+
let formatted = formatBitcoinFromSats(sats, isModern: currency.displayUnit == .modern)
147+
displayText = formatted
148+
// Remove spaces from rawInputText for modern Bitcoin
149+
if currency.displayUnit == .modern {
150+
rawInputText = formatted.replacingOccurrences(of: " ", with: "")
151+
} else {
152+
rawInputText = formatted
153+
}
140154
}
141155
}
142156
}

BitkitTests/NumberPadTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,33 @@ final class NumberPadTests: XCTestCase {
179179
XCTAssertEqual(viewModel.amountSats, 0)
180180
}
181181

182+
func testDeleteAfterMaxAmountModernBitcoin() {
183+
let viewModel = AmountInputViewModel()
184+
let currency = mockCurrency(primaryDisplay: .bitcoin, displayUnit: .modern)
185+
186+
// Set max amount using updateFromSats (simulates tapping max button)
187+
// This creates formatted text with spaces (e.g., "100 000 000")
188+
viewModel.updateFromSats(100_000_000, currency: currency)
189+
XCTAssertEqual(viewModel.displayText, "100 000 000")
190+
XCTAssertEqual(viewModel.amountSats, 100_000_000)
191+
192+
// Delete should remove digits, not spaces
193+
// After first delete, should be "10 000 000" (one digit removed)
194+
viewModel.handleNumberPadInput("delete", currency: currency)
195+
XCTAssertEqual(viewModel.displayText, "10 000 000")
196+
XCTAssertEqual(viewModel.amountSats, 10_000_000)
197+
198+
// Delete again
199+
viewModel.handleNumberPadInput("delete", currency: currency)
200+
XCTAssertEqual(viewModel.displayText, "1 000 000")
201+
XCTAssertEqual(viewModel.amountSats, 1_000_000)
202+
203+
// Delete again
204+
viewModel.handleNumberPadInput("delete", currency: currency)
205+
XCTAssertEqual(viewModel.displayText, "100 000")
206+
XCTAssertEqual(viewModel.amountSats, 100_000)
207+
}
208+
182209
// MARK: - Leading Zero Tests
183210

184211
func testLeadingZeroBehavior() {

0 commit comments

Comments
 (0)