damus

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

commit 8097cfdfb8e6fe328e0a2683ec24b6d31edd7dc9
parent af912b1a0e5f76e950d9af04db263af61c602df3
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 15 May 2023 09:59:43 -0700

Include donation_amount on profile

Diffstat:
Mdamus/Nostr/Nostr.swift | 18++++++++++++++++--
Mdamus/Views/Profile/ProfilePicView.swift | 2+-
Mdamus/Views/Profile/ProfileView.swift | 2+-
Mdamus/Views/SaveKeysView.swift | 2+-
Mdamus/Views/Wallet/WalletView.swift | 12++++++++++++
5 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/damus/Nostr/Nostr.swift b/damus/Nostr/Nostr.swift @@ -10,7 +10,7 @@ import Foundation class Profile: Codable { var value: [String: AnyCodable] - init (name: String?, display_name: String?, about: String?, picture: String?, banner: String?, website: String?, lud06: String?, lud16: String?, nip05: String?) { + init (name: String?, display_name: String?, about: String?, picture: String?, banner: String?, website: String?, lud06: String?, lud16: String?, nip05: String?, damus_donation: Int?) { self.value = [:] self.name = name self.display_name = display_name @@ -21,12 +21,17 @@ class Profile: Codable { self.lud06 = lud06 self.lud16 = lud16 self.nip05 = nip05 + self.damus_donation = damus_donation } private func str(_ str: String) -> String? { return get_val(str) } + private func int(_ key: String) -> Int? { + return get_val(key) + } + private func get_val<T>(_ v: String) -> T? { guard let val = self.value[v] else{ return nil @@ -52,6 +57,10 @@ class Profile: Codable { set_val(key, val) } + private func set_int(_ key: String, _ val: Int?) { + set_val(key, val) + } + var reactions: Bool? { get { return get_val("reactions"); } set(s) { set_val("reactions", s) } @@ -77,6 +86,11 @@ class Profile: Codable { set(s) { set_str("about", s) } } + var damus_donation: Int? { + get { return int("damus_donation"); } + set(s) { set_int("damus_donation", s) } + } + var picture: String? { get { return str("picture"); } set(s) { set_str("picture", s) } @@ -180,7 +194,7 @@ class Profile: Codable { } func make_test_profile() -> Profile { - return Profile(name: "jb55", display_name: "Will", about: "Its a me", picture: "https://cdn.jb55.com/img/red-me.jpg", banner: "https://pbs.twimg.com/profile_banners/9918032/1531711830/600x200", website: "jb55.com", lud06: "jb55@jb55.com", lud16: nil, nip05: "jb55@jb55.com") + return Profile(name: "jb55", display_name: "Will", about: "Its a me", picture: "https://cdn.jb55.com/img/red-me.jpg", banner: "https://pbs.twimg.com/profile_banners/9918032/1531711830/600x200", website: "jb55.com", lud06: "jb55@jb55.com", lud16: nil, nip05: "jb55@jb55.com", damus_donation: 1) } func make_ln_url(_ str: String?) -> URL? { diff --git a/damus/Views/Profile/ProfilePicView.swift b/damus/Views/Profile/ProfilePicView.swift @@ -177,7 +177,7 @@ func get_profile_url(picture: String?, pubkey: String, profiles: Profiles) -> UR func make_preview_profiles(_ pubkey: String) -> Profiles { let profiles = Profiles() let picture = "http://cdn.jb55.com/img/red-me.jpg" - let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, banner: "", website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com") + let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, banner: "", website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com", damus_donation: nil) let ts_profile = TimestampedProfile(profile: profile, timestamp: 0, event: test_event) profiles.add(id: pubkey, profile: ts_profile) return profiles diff --git a/damus/Views/Profile/ProfileView.swift b/damus/Views/Profile/ProfileView.swift @@ -497,7 +497,7 @@ func test_damus_state() -> DamusState { let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681" let damus = DamusState.empty - let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", banner: "", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io") + let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", banner: "", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io", damus_donation: nil) let tsprof = TimestampedProfile(profile: prof, timestamp: 0, event: test_event) damus.profiles.add(id: pubkey, profile: tsprof) return damus diff --git a/damus/Views/SaveKeysView.swift b/damus/Views/SaveKeysView.swift @@ -224,5 +224,5 @@ struct SaveKeysView_Previews: PreviewProvider { } func create_account_to_metadata(_ model: CreateAccountModel) -> Profile { - return Profile(name: model.nick_name, display_name: model.real_name, about: model.about, picture: model.profile_image, banner: nil, website: nil, lud06: nil, lud16: nil, nip05: nil) + return Profile(name: model.nick_name, display_name: model.real_name, about: model.about, picture: model.profile_image, banner: nil, website: nil, lud06: nil, lud16: nil, nip05: nil, damus_donation: nil) } diff --git a/damus/Views/Wallet/WalletView.swift b/damus/Views/Wallet/WalletView.swift @@ -154,6 +154,18 @@ struct WalletView: View { ConnectWalletView(model: model) case .existing(let nwc): MainWalletView(nwc: nwc) + .onDisappear { + guard let keypair = damus_state.keypair.to_full(), + let profile = damus_state.profiles.lookup(id: damus_state.pubkey), + profile.damus_donation != settings.donation_percent + else { + return + } + + profile.damus_donation = settings.donation_percent + let meta = make_metadata_event(keypair: keypair, metadata: profile) + damus_state.postbox.send(meta) + } } } }