commit 5cce18c8b6725ae28e8220746c611806e1a8fff0
parent a5726d4650de4f6a8cf2a9a84aeb7c5560537b45
Author: William Casarin <jb55@jb55.com>
Date: Wed, 10 May 2023 11:41:38 -0700
nwc: attach lud16 to profile when attaching wallet
Diffstat:
3 files changed, 21 insertions(+), 0 deletions(-)
diff --git 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
@@ -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
@@ -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 {