From 5cce18c8b6725ae28e8220746c611806e1a8fff0 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Wed, 10 May 2023 11:41:38 -0700 Subject: [PATCH] nwc: attach lud16 to profile when attaching wallet --- damus/ContentView.swift | 17 +++++++++++++++++ damus/Models/WalletModel.swift | 1 + damus/Util/Notifications.swift | 3 +++ 3 files changed, 21 insertions(+) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 2049c67c..d336143b 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -359,6 +359,23 @@ struct ContentView: View { self.muting = pubkey self.confirm_mute = true } + .onReceive(handle_notify(.attached_wallet)) { notif in + // update the lightning address on our profile when we attach a + // wallet with an associated + let nwc = notif.object as! WalletConnectURL + guard let ds = self.damus_state, + let lud16 = nwc.lud16, + let keypair = ds.keypair.to_full(), + let profile = ds.profiles.lookup(id: ds.pubkey), + lud16 != profile.lud16 + else { + return + } + + profile.lud16 = lud16 + let ev = make_metadata_event(keypair: keypair, metadata: profile) + ds.postbox.send(ev) + } .onReceive(handle_notify(.broadcast_event)) { obj in let ev = obj.object as! NostrEvent guard let ds = self.damus_state else { diff --git a/damus/Models/WalletModel.swift b/damus/Models/WalletModel.swift index c44e4cb9..206dab63 100644 --- a/damus/Models/WalletModel.swift +++ b/damus/Models/WalletModel.swift @@ -53,6 +53,7 @@ class WalletModel: ObservableObject { func connect(_ nwc: WalletConnectURL) { self.settings?.nostr_wallet_connect = nwc.to_url().absoluteString + notify(.attached_wallet, nwc) self.connect_state = .existing(nwc) self.previous_state = .existing(nwc) } diff --git a/damus/Util/Notifications.swift b/damus/Util/Notifications.swift index 11021b51..d23011fc 100644 --- a/damus/Util/Notifications.swift +++ b/damus/Util/Notifications.swift @@ -92,6 +92,9 @@ extension Notification.Name { static var onlyzaps_mode: Notification.Name { return Notification.Name("hide_reactions") } + static var attached_wallet: Notification.Name { + return Notification.Name("attached_wallet") + } } func handle_notify(_ name: Notification.Name) -> NotificationCenter.Publisher {