This commit implements a single-tap zap on the profile action sheet and fixes an issue where zapping would silently fail on default settings if the user had no lightning wallet installed in their system. Testing ------- Configurations: - iPhone 13 Mini (physical device) on iOS 17.0.2 with NWC wallet attached - iPhone 15 Pro (simulator) on iOS 17.0.1 with no lightning wallet nor NWC Damus: This commit Coverage: - Zapping using NWC connected wallet: PASS (Zaps and shows UX feedback of the completed action) - Zapping under default settings and no lightning wallet: PASS (Shows the wallet selector invoice view) - Long press on zap button brings custom zap view Regression testing ------------------ Preconditions: iPhone 15 Pro (simulator) on iOS 17.0.1 with no lightning wallet nor NWC Coverage: - Zapping user on their full profile shows wallet selector. PASS - On-post invoice shows wallet selector. PASS Closes: https://github.com/damus-io/damus/issues/1634 Changelog-Changed: Zap button on profile action sheet now zaps with a single click, while a long press brings custom zap view Changelog-Fixed: Fixed an issue where zapping would silently fail on default settings if the user does not have a lightning wallet preinstalled on their device. Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Reviewed-by: William Casarin <jb55@jb55.com> Signed-off-by: William Casarin <jb55@jb55.com>
79 lines
3.5 KiB
Swift
79 lines
3.5 KiB
Swift
//
|
|
// SelectWalletView.swift
|
|
// damus
|
|
//
|
|
// Created by Suhail Saqan on 12/22/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SelectWalletView: View {
|
|
let default_wallet: Wallet
|
|
@Binding var active_sheet: Sheets?
|
|
let our_pubkey: Pubkey
|
|
let invoice: String
|
|
@State var invoice_copied: Bool = false
|
|
|
|
@State var allWalletModels: [Wallet.Model] = Wallet.allModels
|
|
let generator = UIImpactFeedbackGenerator(style: .light)
|
|
|
|
var body: some View {
|
|
NavigationView {
|
|
Form {
|
|
Section(NSLocalizedString("Copy invoice", comment: "Title of section for copying a Lightning invoice identifier.")) {
|
|
HStack {
|
|
Text(invoice).font(.body)
|
|
.lineLimit(2)
|
|
.truncationMode(.tail)
|
|
|
|
Spacer()
|
|
|
|
Image(self.invoice_copied ? "check-circle" : "copy2").foregroundColor(.blue)
|
|
}.clipShape(RoundedRectangle(cornerRadius: 5)).onTapGesture {
|
|
UIPasteboard.general.string = invoice
|
|
self.invoice_copied = true
|
|
generator.impactOccurred()
|
|
}
|
|
}
|
|
Section(NSLocalizedString("Select a Lightning wallet", comment: "Title of section for selecting a Lightning wallet to pay a Lightning invoice.")) {
|
|
List{
|
|
Button() {
|
|
// TODO: Handle cases where wallet cannot be opened by the system
|
|
try? open_with_wallet(wallet: default_wallet.model, invoice: invoice)
|
|
} label: {
|
|
HStack {
|
|
Text("Default Wallet", comment: "Button to pay a Lightning invoice with the user's default Lightning wallet.").font(.body).foregroundColor(.blue)
|
|
}
|
|
}.buttonStyle(.plain)
|
|
List($allWalletModels) { $wallet in
|
|
if wallet.index >= 0 {
|
|
Button() {
|
|
// TODO: Handle cases where wallet cannot be opened by the system
|
|
try? open_with_wallet(wallet: wallet, invoice: invoice)
|
|
} label: {
|
|
HStack {
|
|
Image(wallet.image).resizable().frame(width: 32.0, height: 32.0,alignment: .center).cornerRadius(5)
|
|
Text(wallet.displayName).font(.body)
|
|
}
|
|
}.buttonStyle(.plain)
|
|
}
|
|
}
|
|
}.padding(.vertical, 2.5)
|
|
}
|
|
}.navigationBarTitle(Text("Pay the Lightning invoice", comment: "Navigation bar title for view to pay Lightning invoice."), displayMode: .inline).navigationBarItems(trailing: Button(action: {
|
|
self.active_sheet = nil
|
|
}) {
|
|
Text("Done", comment: "Button to dismiss wallet selection view for paying Lightning invoice.").bold()
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SelectWalletView_Previews: PreviewProvider {
|
|
@State static var active_sheet: Sheets? = nil
|
|
|
|
static var previews: some View {
|
|
SelectWalletView(default_wallet: .lnlink, active_sheet: $active_sheet, our_pubkey: test_pubkey, invoice: "")
|
|
}
|
|
}
|