-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLnurlWithdrawAmount.swift
More file actions
94 lines (77 loc) · 3.14 KB
/
LnurlWithdrawAmount.swift
File metadata and controls
94 lines (77 loc) · 3.14 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
import SwiftUI
struct LnurlWithdrawAmount: View {
@EnvironmentObject var app: AppViewModel
@EnvironmentObject var currency: CurrencyViewModel
@EnvironmentObject var wallet: WalletViewModel
let onContinue: () -> Void
@StateObject private var amountViewModel = AmountInputViewModel()
var minAmount: Int {
let minMsats = app.lnurlWithdrawData!.minWithdrawable ?? Env.msatsPerSat
return Int(max(1, LightningAmountConversion.satsCeil(fromMsats: minMsats)))
}
var maxAmount: Int {
Int(LightningAmountConversion.satsFloor(fromMsats: app.lnurlWithdrawData!.maxWithdrawable))
}
var amount: UInt64 {
amountViewModel.amountSats
}
var isValid: Bool {
amount <= maxAmount
}
var body: some View {
VStack(spacing: 0) {
SheetHeader(title: t("wallet__lnurl_w_title"), showBackButton: true)
VStack(alignment: .leading, spacing: 0) {
NumberPadTextField(viewModel: amountViewModel, testIdentifier: "SendNumberField")
.onTapGesture {
amountViewModel.togglePrimaryDisplay(currency: currency)
}
.padding(.vertical, 16)
Spacer()
HStack(alignment: .bottom) {
AvailableAmount(label: t("wallet__lnurl_w_max"), amount: maxAmount)
.onTapGesture {
amountViewModel.updateFromSats(UInt64(maxAmount), currency: currency)
}
Spacer()
NumberPadActionButton(
text: currency.primaryDisplay == .bitcoin ? "Bitcoin" : currency.selectedCurrency,
imageName: "transfer",
color: .brandAccent
) {
withAnimation {
amountViewModel.togglePrimaryDisplay(currency: currency)
}
}
}
.padding(.bottom, 12)
NumberPad(
type: amountViewModel.getNumberPadType(currency: currency),
errorKey: amountViewModel.errorKey
) { key in
amountViewModel.handleNumberPadInput(key, currency: currency)
}
CustomButton(title: t("common__continue"), isDisabled: !isValid) {
handleContinue()
}
.accessibilityIdentifier("ContinueAmount")
}
}
.navigationBarHidden(true)
.padding(.horizontal, 16)
.sheetBackground()
.onAppear {
if amountViewModel.amountSats == 0 {
amountViewModel.updateFromSats(UInt64(minAmount), currency: currency)
}
}
}
private func handleContinue() {
// If minimum is above the amount the user entered, automatically set amount to that minimum
if amount < minAmount {
amountViewModel.updateFromSats(UInt64(minAmount), currency: currency)
}
wallet.lnurlWithdrawAmount = amount
onContinue()
}
}