-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSendEnterManuallyView.swift
More file actions
130 lines (113 loc) · 4.64 KB
/
Copy pathSendEnterManuallyView.swift
File metadata and controls
130 lines (113 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import SwiftUI
struct SendEnterManuallyView: View {
@EnvironmentObject var app: AppViewModel
@EnvironmentObject var wallet: WalletViewModel
@EnvironmentObject var currency: CurrencyViewModel
@EnvironmentObject var settings: SettingsViewModel
@EnvironmentObject var contactsManager: ContactsManager
@EnvironmentObject var navigation: NavigationViewModel
@EnvironmentObject var pubkyProfile: PubkyProfileManager
@EnvironmentObject var sheets: SheetViewModel
@Binding var navigationPath: [SendRoute]
@FocusState private var isTextEditorFocused: Bool
private var manualEntryBinding: Binding<String> {
Binding(
get: { app.manualEntryInput },
set: { newValue in
app.manualEntryInput = newValue
app.validateManualEntryInput(
newValue,
savingsBalanceSats: wallet.spendableOnchainBalanceSats,
spendingBalanceSats: wallet.maxSendLightningSats
)
}
)
}
var body: some View {
VStack {
SheetHeader(title: t("wallet__send_bitcoin"), showBackButton: true)
CaptionMText(t("wallet__send_to"))
.frame(maxWidth: .infinity, alignment: .leading)
ZStack(alignment: .topLeading) {
if app.manualEntryInput.isEmpty {
TitleText(t("wallet__send_address_placeholder"), textColor: .textSecondary)
.padding(20)
}
TextEditor(text: manualEntryBinding)
.focused($isTextEditorFocused)
.padding(EdgeInsets(top: -10, leading: -5, bottom: -5, trailing: -5))
.padding(20)
.frame(maxHeight: .infinity)
.scrollContentBackground(.hidden)
.font(.custom(Fonts.bold, size: 22))
.foregroundColor(.textPrimary)
.accentColor(.brandAccent)
.submitLabel(.done)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
.dismissKeyboardOnReturn(text: manualEntryBinding, isFocused: $isTextEditorFocused)
.accessibilityValue(app.manualEntryInput)
.accessibilityIdentifier("RecipientInput")
}
.background(Color.white06)
.cornerRadius(8)
Spacer(minLength: 16)
CustomButton(title: "Continue", isDisabled: !app.isManualEntryInputValid) {
await handleContinue()
}
.buttonBottomPadding(isFocused: isTextEditorFocused)
.accessibilityIdentifier("AddressContinue")
}
.navigationBarHidden(true)
.padding(.horizontal, 16)
.sheetBackground()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onAppear {
isTextEditorFocused = true
}
}
func handleContinue() async {
let uri = app.normalizeManualEntry(app.manualEntryInput)
guard !uri.isEmpty, app.isManualEntryInputValid else { return }
if let route = resolvePubkyRoute(
input: uri,
ownPublicKey: pubkyProfile.publicKey,
contacts: contactsManager.contacts
) {
sheets.hideSheetIfActive(.send, reason: "Manual pubky entry routed to contacts")
navigation.navigate(route)
return
}
do {
wallet.resetSendState(speed: settings.defaultTransactionSpeed)
do {
try await wallet.setFeeRate(speed: settings.defaultTransactionSpeed)
} catch {
Logger.error("Failed to set default fee rate: \(error)")
}
try await app.handleScannedData(uri)
if let route = PaymentNavigationHelper.appropriateSendRoute(
app: app,
currency: currency,
settings: settings
) {
navigationPath.append(route)
}
} catch {
Logger.error(error, context: "Failed to read data from clipboard")
app.toast(error)
}
}
}
#Preview {
SendEnterManuallyView(navigationPath: .constant([]))
.environmentObject(AppViewModel())
.environmentObject(WalletViewModel())
.environmentObject(CurrencyViewModel())
.environmentObject(SettingsViewModel.shared)
.environmentObject(ContactsManager())
.environmentObject(NavigationViewModel())
.environmentObject(PubkyProfileManager())
.environmentObject(SheetViewModel())
.preferredColorScheme(.dark)
}