Skip to content

Commit 64655dc

Browse files
CypherPoetCypherPoet
authored andcommitted
refactor: migrate AmountInputViewModel to @observable
Replaces the legacy ObservableObject/@StateObject/@ObservedObject pattern with @observable + @State, aligning with the project's stated SwiftUI direction. No behavior change: there are no two-way bindings to the view model, so no @bindable is needed. Touches the view model, NumberPadTextField, and the 8 amount-entry call sites.
1 parent 6af6d68 commit 64655dc

10 files changed

Lines changed: 14 additions & 13 deletions

Bitkit/Components/NumberPadTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftUI
33
/// NumberPadTextField - Amount view to be used with number pad
44
struct NumberPadTextField: View {
55
@EnvironmentObject var currency: CurrencyViewModel
6-
@ObservedObject var viewModel: AmountInputViewModel
6+
var viewModel: AmountInputViewModel
77

88
var showConversion: Bool = true
99
var showEditButton: Bool = false

Bitkit/ViewModels/AmountInputViewModel.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Foundation
22
import SwiftUI
33

4+
@Observable
45
@MainActor
5-
class AmountInputViewModel: ObservableObject {
6-
@Published var amountSats: UInt64 = 0
7-
@Published var displayText: String = ""
8-
@Published var errorKey: String?
6+
final class AmountInputViewModel {
7+
var amountSats: UInt64 = 0
8+
var displayText: String = ""
9+
var errorKey: String?
910

1011
/// Optional per-screen cap (e.g. the max sendable balance in the send flow).
1112
/// When set, input is additionally blocked above this value, on top of `maxAmount`.

Bitkit/Views/Transfer/FundManualAmountView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct FundManualAmountView: View {
88

99
let lnPeer: LnPeer
1010

11-
@StateObject private var amountViewModel = AmountInputViewModel()
11+
@State private var amountViewModel = AmountInputViewModel()
1212
@State private var didAttemptPeerConnection = false
1313

1414
var amountSats: UInt64 {

Bitkit/Views/Transfer/SpendingAdvancedView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct SpendingAdvancedView: View {
1010
@EnvironmentObject var transfer: TransferViewModel
1111
@Environment(\.dismiss) var dismiss
1212

13-
@StateObject private var amountViewModel = AmountInputViewModel()
13+
@State private var amountViewModel = AmountInputViewModel()
1414
@State private var feeEstimate: UInt64?
1515
@State private var isLoading = false
1616
@State private var feeEstimateTask: Task<Void, Never>?

Bitkit/Views/Transfer/SpendingAmount.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct SpendingAmount: View {
1010
@EnvironmentObject var transfer: TransferViewModel
1111
@EnvironmentObject var wallet: WalletViewModel
1212

13-
@StateObject private var amountViewModel = AmountInputViewModel()
13+
@State private var amountViewModel = AmountInputViewModel()
1414
@State private var isLoading = false
1515
@State private var availableAmount: UInt64?
1616
@State private var maxTransferAmount: UInt64?

Bitkit/Views/Wallets/LnurlWithdraw/LnurlWithdrawAmount.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct LnurlWithdrawAmount: View {
66
@EnvironmentObject var wallet: WalletViewModel
77
let onContinue: () -> Void
88

9-
@StateObject private var amountViewModel = AmountInputViewModel()
9+
@State private var amountViewModel = AmountInputViewModel()
1010

1111
var minAmount: Int {
1212
Int(max(1, app.lnurlWithdrawData!.minWithdrawableSat))

Bitkit/Views/Wallets/Receive/ReceiveCjitAmount.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct ReceiveCjitAmount: View {
99

1010
@Binding var navigationPath: [ReceiveRoute]
1111

12-
@StateObject private var amountViewModel = AmountInputViewModel()
12+
@State private var amountViewModel = AmountInputViewModel()
1313

1414
var minimumAmount: UInt64 {
1515
blocktank.minCjitSats ?? 0

Bitkit/Views/Wallets/Receive/ReceiveEdit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct ReceiveEdit: View {
1212

1313
@Binding var navigationPath: [ReceiveRoute]
1414

15-
@StateObject private var amountViewModel = AmountInputViewModel()
15+
@State private var amountViewModel = AmountInputViewModel()
1616
@State private var note = ""
1717
@State private var isAmountInputFocused: Bool = false
1818
@FocusState private var isNoteEditorFocused: Bool

Bitkit/Views/Wallets/Send/LnurlPayAmount.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct LnurlPayAmount: View {
77

88
@Binding var navigationPath: [SendRoute]
99

10-
@StateObject private var amountViewModel = AmountInputViewModel()
10+
@State private var amountViewModel = AmountInputViewModel()
1111

1212
var maxAmount: UInt64 {
1313
// TODO: subtract fee

Bitkit/Views/Wallets/Send/SendAmountView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct SendAmountView: View {
88

99
@Binding var navigationPath: [SendRoute]
1010

11-
@StateObject private var amountViewModel = AmountInputViewModel()
11+
@State private var amountViewModel = AmountInputViewModel()
1212
@State private var maxSendableAmount: UInt64?
1313
@State private var routingFee: UInt64 = 0
1414

0 commit comments

Comments
 (0)