damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit ac1a5d237e88b749a4dca7adcf3617fd75c8d918
parent cfcd799d63ced0be931342b5af9684e18f99c862
Author: Joel Klabo <joelklabo@gmail.com>
Date:   Tue, 31 Jan 2023 18:32:11 -0800

Add Copy Invoice Button

Changelog-Added: Copy invoice button
Closes: #469

Diffstat:
Mdamus/Components/InvoiceView.swift | 71+++++++++++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 47 insertions(+), 24 deletions(-)

diff --git a/damus/Components/InvoiceView.swift b/damus/Components/InvoiceView.swift @@ -7,33 +7,32 @@ import SwiftUI -func open_with_wallet(wallet: Wallet.Model, invoice: String) { - if let url = URL(string: "\(wallet.link)\(invoice)"), UIApplication.shared.canOpenURL(url) { - UIApplication.shared.open(url) - } else { - guard let store_link = wallet.appStoreLink else { - // TODO: do something here if we don't have an appstore link - return - } - - guard let url = URL(string: store_link) else { - return - } - - guard UIApplication.shared.canOpenURL(url) else { - return - } - - UIApplication.shared.open(url) - } -} - struct InvoiceView: View { @Environment(\.colorScheme) var colorScheme @Environment(\.openURL) private var openURL let our_pubkey: String let invoice: Invoice @State var showing_select_wallet: Bool = false + @State var copied = false + + var CopyButton: some View { + Button { + copied = true + DispatchQueue.main.asyncAfter(deadline: .now() + 3) { + copied = false + } + UIImpactFeedbackGenerator(style: .medium).impactOccurred() + UIPasteboard.general.string = invoice.string + } label: { + if !copied { + Image(systemName: "doc.on.clipboard") + .foregroundColor(.gray) + } else { + Image(systemName: "checkmark.circle") + .foregroundColor(Color("DamusGreen")) + } + } + } var PayButton: some View { Button { @@ -43,7 +42,7 @@ struct InvoiceView: View { open_with_wallet(wallet: get_default_wallet(our_pubkey).model, invoice: invoice.string) } } label: { - RoundedRectangle(cornerRadius: 20) + RoundedRectangle(cornerRadius: 20, style: .circular) .foregroundColor(colorScheme == .light ? .black : .white) .overlay { Text("Pay", comment: "Button to pay a Lightning invoice.") @@ -51,9 +50,9 @@ struct InvoiceView: View { .foregroundColor(colorScheme == .light ? .white : .black) } } - //.buttonStyle(.bordered) .onTapGesture { // Temporary solution so that the "pay" button can be clicked (Yes we need an empty tap gesture) + print("pay button tap") } } @@ -67,6 +66,8 @@ struct InvoiceView: View { Label("", systemImage: "bolt.fill") .foregroundColor(.orange) Text("Lightning Invoice", comment: "Indicates that the view is for paying a Lightning invoice.") + Spacer() + CopyButton } Divider() Text(invoice.description_string) @@ -84,11 +85,33 @@ struct InvoiceView: View { } } +func open_with_wallet(wallet: Wallet.Model, invoice: String) { + if let url = URL(string: "\(wallet.link)\(invoice)"), UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url) + } else { + guard let store_link = wallet.appStoreLink else { + // TODO: do something here if we don't have an appstore link + return + } + + guard let url = URL(string: store_link) else { + return + } + + guard UIApplication.shared.canOpenURL(url) else { + return + } + + UIApplication.shared.open(url) + } +} + + let test_invoice = Invoice(description: .description("this is a description"), amount: .specific(10000), string: "lnbc100n1p357sl0sp5t9n56wdztun39lgdqlr30xqwksg3k69q4q2rkr52aplujw0esn0qpp5mrqgljk62z20q4nvgr6lzcyn6fhylzccwdvu4k77apg3zmrkujjqdpzw35xjueqd9ejqcfqv3jhxcmjd9c8g6t0dcxqyjw5qcqpjrzjqt56h4gvp5yx36u2uzqa6qwcsk3e2duunfxppzj9vhypc3wfe2wswz607uqq3xqqqsqqqqqqqqqqqlqqyg9qyysgqagx5h20aeulj3gdwx3kxs8u9f4mcakdkwuakasamm9562ffyr9en8yg20lg0ygnr9zpwp68524kmda0t5xp2wytex35pu8hapyjajxqpsql29r", expiry: 604800, payment_hash: Data(), created_at: 1666139119) struct InvoiceView_Previews: PreviewProvider { static var previews: some View { InvoiceView(our_pubkey: "", invoice: test_invoice) - .frame(width: 200, height: 200) + .frame(width: 300, height: 200) } }