Skip to content

Commit 2dc90a7

Browse files
committed
Add LNURL withdraw routes to send flow
1 parent a619611 commit 2dc90a7

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

Bitkit/Utilities/PaymentNavigationHelper.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ struct PaymentNavigationHelper {
103103
currency: CurrencyViewModel,
104104
settings: SettingsViewModel
105105
) -> SendRoute {
106+
if let lnurlWithdrawData = app.lnurlWithdrawData {
107+
if lnurlWithdrawData.minWithdrawable == lnurlWithdrawData.maxWithdrawable {
108+
return .lnurlWithdrawConfirm
109+
} else {
110+
return .lnurlWithdrawAmount
111+
}
112+
}
113+
106114
let shouldUseQuickpay = shouldUseQuickpay(app: app, settings: settings, currency: currency)
107115

108116
// Handle Lightning address / LNURL pay

Bitkit/Views/Wallets/LnurlWithdraw/LnurlWithdrawAmount.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct LnurlWithdrawAmount: View {
44
@EnvironmentObject var app: AppViewModel
55
@EnvironmentObject var currency: CurrencyViewModel
66
@EnvironmentObject var wallet: WalletViewModel
7-
@Binding var navigationPath: [LnurlWithdrawRoute]
7+
let onContinue: () -> Void
88

99
@StateObject private var amountViewModel = AmountInputViewModel()
1010

@@ -65,7 +65,7 @@ struct LnurlWithdrawAmount: View {
6565
}
6666

6767
CustomButton(title: t("common__continue"), isDisabled: !isValid) {
68-
onContinue()
68+
handleContinue()
6969
}
7070
.accessibilityIdentifier("ContinueAmount")
7171
}
@@ -80,14 +80,14 @@ struct LnurlWithdrawAmount: View {
8080
}
8181
}
8282

83-
private func onContinue() {
83+
private func handleContinue() {
8484
// If minimum is above the amount the user entered, automatically set amount to that minimum
8585
if amount < minAmount {
8686
amountViewModel.updateFromSats(UInt64(minAmount), currency: currency)
8787
}
8888

8989
wallet.lnurlWithdrawAmount = amount
9090

91-
navigationPath.append(.confirm)
91+
onContinue()
9292
}
9393
}

Bitkit/Views/Wallets/LnurlWithdraw/LnurlWithdrawConfirm.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct LnurlWithdrawConfirm: View {
55
@EnvironmentObject var currency: CurrencyViewModel
66
@EnvironmentObject var sheets: SheetViewModel
77
@EnvironmentObject var wallet: WalletViewModel
8-
@Binding var navigationPath: [LnurlWithdrawRoute]
8+
let onFailure: (UInt64) -> Void
99
@State private var isLoading = false
1010

1111
var amount: UInt64 {
@@ -83,7 +83,7 @@ struct LnurlWithdrawConfirm: View {
8383

8484
} catch {
8585
await MainActor.run {
86-
navigationPath.append(.failure(amount: amount))
86+
onFailure(amount)
8787
isLoading = false
8888
}
8989
}

Bitkit/Views/Wallets/LnurlWithdraw/LnurlWithdrawFailure.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ struct LnurlWithdrawFailure: View {
44
@EnvironmentObject var currency: CurrencyViewModel
55
@EnvironmentObject var navigation: NavigationViewModel
66
@EnvironmentObject var sheets: SheetViewModel
7-
@Binding var navigationPath: [LnurlWithdrawRoute]
87
let amount: UInt64
98

109
// TODO: add localized strings

Bitkit/Views/Wallets/LnurlWithdraw/LnurlWithdrawSheet.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ struct LnurlWithdrawSheet: View {
4343
private func viewForRoute(_ route: LnurlWithdrawRoute) -> some View {
4444
switch route {
4545
case .amount:
46-
LnurlWithdrawAmount(navigationPath: $navigationPath)
46+
LnurlWithdrawAmount {
47+
navigationPath.append(.confirm)
48+
}
4749
case .confirm:
48-
LnurlWithdrawConfirm(navigationPath: $navigationPath)
50+
LnurlWithdrawConfirm { amount in
51+
navigationPath.append(.failure(amount: amount))
52+
}
4953
case let .failure(amount):
50-
LnurlWithdrawFailure(navigationPath: $navigationPath, amount: amount)
54+
LnurlWithdrawFailure(amount: amount)
5155
}
5256
}
5357
}

Bitkit/Views/Wallets/Send/SendSheet.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ enum SendRoute: Hashable {
1414
case failure
1515
case lnurlPayAmount
1616
case lnurlPayConfirm
17+
case lnurlWithdrawAmount
18+
case lnurlWithdrawConfirm
19+
case lnurlWithdrawFailure(amount: UInt64)
1720
}
1821

1922
struct SendConfig {
@@ -96,6 +99,16 @@ struct SendSheet: View {
9699
LnurlPayAmount(navigationPath: $navigationPath)
97100
case .lnurlPayConfirm:
98101
LnurlPayConfirm(navigationPath: $navigationPath)
102+
case .lnurlWithdrawAmount:
103+
LnurlWithdrawAmount {
104+
navigationPath.append(.lnurlWithdrawConfirm)
105+
}
106+
case .lnurlWithdrawConfirm:
107+
LnurlWithdrawConfirm { amount in
108+
navigationPath.append(.lnurlWithdrawFailure(amount: amount))
109+
}
110+
case let .lnurlWithdrawFailure(amount):
111+
LnurlWithdrawFailure(amount: amount)
99112
}
100113
}
101114
}

0 commit comments

Comments
 (0)