From fe3d976cdbff19ec61efba322d5d39769e8e595d Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 9 May 2023 18:49:34 -0700 Subject: [PATCH] nwc: pay with nwc if we have it configured --- damus/Components/ZapButton.swift | 9 +++++++-- damus/Util/WalletConnect.swift | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/damus/Components/ZapButton.swift b/damus/Components/ZapButton.swift index 18b70be7..57d2955a 100644 --- a/damus/Components/ZapButton.swift +++ b/damus/Components/ZapButton.swift @@ -184,8 +184,13 @@ func send_zap(damus_state: DamusState, event: NostrEvent, lnurl: String, is_cust } DispatchQueue.main.async { - let ev = ZappingEvent(is_custom: is_custom, type: .got_zap_invoice(inv), event: event) - notify(.zapping, ev) + if let url = damus_state.settings.nostr_wallet_connect, + let nwc = WalletConnectURL(str: url) { + nwc_pay(url: nwc, pool: damus_state.pool, post: damus_state.postbox, invoice: inv) + } else { + let ev = ZappingEvent(is_custom: is_custom, type: .got_zap_invoice(inv), event: event) + notify(.zapping, ev) + } } } diff --git a/damus/Util/WalletConnect.swift b/damus/Util/WalletConnect.swift index 9cd96102..c5f0227b 100644 --- a/damus/Util/WalletConnect.swift +++ b/damus/Util/WalletConnect.swift @@ -77,3 +77,13 @@ func make_wallet_connect_request(req: WalletRequest, to_pk: String, keypai } return create_encrypted_event(content, to_pk: to_pk, tags: tags, keypair: keypair, created_at: created_at, kind: 23194) } + +func nwc_pay(url: WalletConnectURL, pool: RelayPool, post: PostBox, invoice: String) { + let req = make_wallet_pay_invoice_request(invoice: invoice) + guard let ev = make_wallet_connect_request(req: req, to_pk: url.pubkey, keypair: url.keypair) else { + return + } + + try? pool.add_relay(url.relay, info: .ephemeral) + post.send(ev, to: [url.relay.id], skip_ephemeral: false) +}