damus

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

commit dbe938ad9bdc69ca2d489d462db30a6dad57dca9
parent 289d55b918919cb5174fb20eaa9421d4cebfaf51
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 10 Feb 2023 10:01:17 -0800

Add paid relay details

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 12++++++++++++
Mdamus/Nostr/Relay.swift | 1+
Adamus/Views/Relays/Detail/RelayPaidDetail.swift | 33+++++++++++++++++++++++++++++++++
Mdamus/Views/Relays/RelayDetailView.swift | 72+++++++++++++++++++++++++++++++++++++-----------------------------------
4 files changed, 83 insertions(+), 35 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -172,6 +172,7 @@ 4CE8794E2996B16A00F758CC /* RelayToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8794D2996B16A00F758CC /* RelayToggle.swift */; }; 4CE879502996B2BD00F758CC /* RelayStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8794F2996B2BD00F758CC /* RelayStatus.swift */; }; 4CE879522996B68900F758CC /* RelayType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE879512996B68900F758CC /* RelayType.swift */; }; + 4CE879552996BAB900F758CC /* RelayPaidDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE879542996BAB900F758CC /* RelayPaidDetail.swift */; }; 4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */; }; 4CEE2AF1280B216B00AB5EEF /* EventDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */; }; 4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */; }; @@ -467,6 +468,7 @@ 4CE8794D2996B16A00F758CC /* RelayToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayToggle.swift; sourceTree = "<group>"; }; 4CE8794F2996B2BD00F758CC /* RelayStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayStatus.swift; sourceTree = "<group>"; }; 4CE879512996B68900F758CC /* RelayType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayType.swift; sourceTree = "<group>"; }; + 4CE879542996BAB900F758CC /* RelayPaidDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayPaidDetail.swift; sourceTree = "<group>"; }; 4CEE2AE72804F57C00AB5EEF /* libsecp256k1.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsecp256k1.a; sourceTree = "<group>"; }; 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrRequest.swift; sourceTree = "<group>"; }; 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventDetailView.swift; sourceTree = "<group>"; }; @@ -773,6 +775,7 @@ 4CAAD8AE29888A9B00060CEA /* Relays */ = { isa = PBXGroup; children = ( + 4CE879532996BA0000F758CC /* Detail */, 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */, 4C06670028FC7C5900038D2A /* RelayView.swift */, 4CAAD8AF29888AD200060CEA /* RelayConfigView.swift */, @@ -937,6 +940,14 @@ path = Relays; sourceTree = "<group>"; }; + 4CE879532996BA0000F758CC /* Detail */ = { + isa = PBXGroup; + children = ( + 4CE879542996BAB900F758CC /* RelayPaidDetail.swift */, + ); + path = Detail; + sourceTree = "<group>"; + }; 4CEE2AE62804F57B00AB5EEF /* Frameworks */ = { isa = PBXGroup; children = ( @@ -1305,6 +1316,7 @@ 4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */, F7908E92298B0F0700AB113A /* RelayDetailView.swift in Sources */, 4C3A1D332960DB0500558C0F /* Markdown.swift in Sources */, + 4CE879552996BAB900F758CC /* RelayPaidDetail.swift in Sources */, 4CF0ABD42980996B00D66079 /* Report.swift in Sources */, 4C06670B28FDE64700038D2A /* damus.c in Sources */, 3AAA95CC298E07E900F3D526 /* DeepLPlan.swift in Sources */, diff --git a/damus/Nostr/Relay.swift b/damus/Nostr/Relay.swift @@ -41,6 +41,7 @@ struct RelayMetadata: Codable { let software: String? let version: String? let limitation: Limitations? + let payments_url: String? var is_paid: Bool { return limitation?.payment_required ?? false diff --git a/damus/Views/Relays/Detail/RelayPaidDetail.swift b/damus/Views/Relays/Detail/RelayPaidDetail.swift @@ -0,0 +1,33 @@ +// +// RelayPaidDetail.swift +// damus +// +// Created by William Casarin on 2023-02-10. +// + +import SwiftUI + +struct RelayPaidDetail: View { + let payments_url: String? + + @Environment(\.openURL) var openURL + + var body: some View { + HStack { + RelayType(is_paid: true) + if let url = payments_url.flatMap({ URL(string: $0) }) { + Button(action: { + openURL(url) + }, label: { + Text("\(url)") + }) + } + } + } +} + +struct RelayPaidDetail_Previews: PreviewProvider { + static var previews: some View { + RelayPaidDetail(payments_url: "https://jb55.com") + } +} diff --git a/damus/Views/Relays/RelayDetailView.swift b/damus/Views/Relays/RelayDetailView.swift @@ -22,44 +22,46 @@ struct RelayDetailView: View { var body: some View { Group { - if let nip11 { - Form { - if let pubkey = nip11.pubkey { - Section(NSLocalizedString("Admin", comment: "Label to display relay contact user.")) { - UserView(damus_state: state, pubkey: pubkey) - } + Form { + if let pubkey = nip11.pubkey { + Section(NSLocalizedString("Admin", comment: "Label to display relay contact user.")) { + UserView(damus_state: state, pubkey: pubkey) } - Section(NSLocalizedString("Relay", comment: "Label to display relay address.")) { - HStack { - Text(relay) - Spacer() - RelayStatus(pool: state.pool, relay: relay) - } - } - Section(NSLocalizedString("Description", comment: "Label to display relay description.")) { - FieldText(nip11.description) - } - Section(NSLocalizedString("Contact", comment: "Label to display relay contact information.")) { - FieldText(nip11.contact) - } - Section(NSLocalizedString("Software", comment: "Label to display relay software.")) { - FieldText(nip11.software) - } - Section(NSLocalizedString("Version", comment: "Label to display relay software version.")) { - FieldText(nip11.version) + } + Section(NSLocalizedString("Relay", comment: "Label to display relay address.")) { + HStack { + Text(relay) + Spacer() + RelayStatus(pool: state.pool, relay: relay) } - if let nips = nip11.supported_nips, nips.count > 0 { - Section(NSLocalizedString("Supported NIPs", comment: "Label to display relay's supported NIPs.")) { - Text(nipsList(nips: nips)) - } + } + if nip11.is_paid { + Section(content: { + RelayPaidDetail(payments_url: nip11.payments_url) + }, header: { + Text("Paid Relay") + }, footer: { + Text("This is a paid relay, you must pay for posts to be accepted.") + }) + } + + Section(NSLocalizedString("Description", comment: "Label to display relay description.")) { + FieldText(nip11.description) + } + Section(NSLocalizedString("Contact", comment: "Label to display relay contact information.")) { + FieldText(nip11.contact) + } + Section(NSLocalizedString("Software", comment: "Label to display relay software.")) { + FieldText(nip11.software) + } + Section(NSLocalizedString("Version", comment: "Label to display relay software version.")) { + FieldText(nip11.version) + } + if let nips = nip11.supported_nips, nips.count > 0 { + Section(NSLocalizedString("Supported NIPs", comment: "Label to display relay's supported NIPs.")) { + Text(nipsList(nips: nips)) } } - } else if let errorString { - Text(errorString) - .foregroundColor(.red) - .font(.caption) - } else { - ProgressView() } } .onReceive(handle_notify(.switched_timeline)) { notif in @@ -88,7 +90,7 @@ struct RelayDetailView: View { struct RelayDetailView_Previews: PreviewProvider { static var previews: some View { - let metadata = RelayMetadata(name: "name", description: "desc", pubkey: "pubkey", contact: "contact", supported_nips: [1,2,3], software: "software", version: "version", limitation: Limitations.empty) + let metadata = RelayMetadata(name: "name", description: "desc", pubkey: "pubkey", contact: "contact", supported_nips: [1,2,3], software: "software", version: "version", limitation: Limitations.empty, payments_url: "https://jb55.com") RelayDetailView(state: test_damus_state(), relay: "relay", nip11: metadata) } }