SelectWalletView.swift (3574B)
1 // 2 // SelectWalletView.swift 3 // damus 4 // 5 // Created by Suhail Saqan on 12/22/22. 6 // 7 8 import SwiftUI 9 10 struct SelectWalletView: View { 11 let default_wallet: Wallet 12 @Binding var active_sheet: Sheets? 13 let our_pubkey: Pubkey 14 let invoice: String 15 @State var invoice_copied: Bool = false 16 17 @State var allWalletModels: [Wallet.Model] = Wallet.allModels 18 let generator = UIImpactFeedbackGenerator(style: .light) 19 20 var body: some View { 21 NavigationView { 22 Form { 23 Section(NSLocalizedString("Copy invoice", comment: "Title of section for copying a Lightning invoice identifier.")) { 24 HStack { 25 Text(invoice).font(.body) 26 .lineLimit(2) 27 .truncationMode(.tail) 28 29 Spacer() 30 31 Image(self.invoice_copied ? "check-circle" : "copy2").foregroundColor(.blue) 32 }.clipShape(RoundedRectangle(cornerRadius: 5)).onTapGesture { 33 UIPasteboard.general.string = invoice 34 self.invoice_copied = true 35 generator.impactOccurred() 36 } 37 } 38 Section(NSLocalizedString("Select a Lightning wallet", comment: "Title of section for selecting a Lightning wallet to pay a Lightning invoice.")) { 39 List{ 40 Button() { 41 // TODO: Handle cases where wallet cannot be opened by the system 42 try? open_with_wallet(wallet: default_wallet.model, invoice: invoice) 43 } label: { 44 HStack { 45 Text("Default Wallet", comment: "Button to pay a Lightning invoice with the user's default Lightning wallet.").font(.body).foregroundColor(.blue) 46 } 47 }.buttonStyle(.plain) 48 List($allWalletModels) { $wallet in 49 if wallet.index >= 0 { 50 Button() { 51 // TODO: Handle cases where wallet cannot be opened by the system 52 try? open_with_wallet(wallet: wallet, invoice: invoice) 53 } label: { 54 HStack { 55 Image(wallet.image).resizable().frame(width: 32.0, height: 32.0,alignment: .center).cornerRadius(5) 56 Text(wallet.displayName).font(.body) 57 } 58 }.buttonStyle(.plain) 59 } 60 } 61 }.padding(.vertical, 2.5) 62 } 63 }.navigationBarTitle(Text("Pay the Lightning invoice", comment: "Navigation bar title for view to pay Lightning invoice."), displayMode: .inline).navigationBarItems(trailing: Button(action: { 64 self.active_sheet = nil 65 }) { 66 Text("Done", comment: "Button to dismiss wallet selection view for paying Lightning invoice.").bold() 67 }) 68 } 69 } 70 } 71 72 struct SelectWalletView_Previews: PreviewProvider { 73 @State static var active_sheet: Sheets? = nil 74 75 static var previews: some View { 76 SelectWalletView(default_wallet: .lnlink, active_sheet: $active_sheet, our_pubkey: test_pubkey, invoice: "") 77 } 78 }