Add paid relay details
This commit is contained in:
@@ -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
|
||||
|
||||
33
damus/Views/Relays/Detail/RelayPaidDetail.swift
Normal file
33
damus/Views/Relays/Detail/RelayPaidDetail.swift
Normal file
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
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))
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user