Add client permissions views
This commit is contained in:
@@ -16,13 +16,13 @@ final class NostrClientModel {
|
||||
|
||||
var signingPolicy: SigningPolicy?
|
||||
|
||||
var readPublicKeyPermission: Bool?
|
||||
var nip04EncryptPermission: Bool?
|
||||
var nip44EncryptPermission: Bool?
|
||||
var nip04DencryptPermission: Bool?
|
||||
var nip44DencryptPermission: Bool?
|
||||
var getRelaysPermission: Bool?
|
||||
var decryptZapEventPermission: Bool?
|
||||
var readPublicKeyPermission: Bool = false
|
||||
var nip04EncryptPermission: Bool = false
|
||||
var nip44EncryptPermission: Bool = false
|
||||
var nip04DecryptPermission: Bool = false
|
||||
var nip44DecryptPermission: Bool = false
|
||||
var getRelaysPermission: Bool = false
|
||||
var decryptZapEventPermission: Bool = false
|
||||
|
||||
init(id: String) {
|
||||
self.id = id
|
||||
|
||||
@@ -12,9 +12,27 @@
|
||||
},
|
||||
"Create a key" : {
|
||||
"comment" : "Button to create a key."
|
||||
},
|
||||
"Decrypt DMs" : {
|
||||
|
||||
},
|
||||
"Decrypt legacy DMs" : {
|
||||
|
||||
},
|
||||
"Decrypt zap events" : {
|
||||
|
||||
},
|
||||
"Done" : {
|
||||
"comment" : "Button to go to the next view that adds the user’s entered private key."
|
||||
},
|
||||
"Encrypt DMs" : {
|
||||
|
||||
},
|
||||
"Encrypt legacy DMs" : {
|
||||
|
||||
},
|
||||
"Get relays" : {
|
||||
|
||||
},
|
||||
"History" : {
|
||||
"comment" : "Title for History tab"
|
||||
@@ -36,6 +54,9 @@
|
||||
},
|
||||
"Permissions" : {
|
||||
"comment" : "Title for Permissions tab"
|
||||
},
|
||||
"Read your profile" : {
|
||||
|
||||
},
|
||||
"Recommended for most people. This policy will minimize the number of interruptions during your app usage." : {
|
||||
"comment" : "Description of event signing policy that approves basic actions."
|
||||
@@ -51,6 +72,9 @@
|
||||
},
|
||||
"Should I approve Nostr events automatically or would you like to review them for each app?" : {
|
||||
"comment" : "Prompt asking user which signing policy to use."
|
||||
},
|
||||
"Sign kind %@ events" : {
|
||||
|
||||
},
|
||||
"Yeti: Nostr Helper" : {
|
||||
"comment" : "Application title."
|
||||
|
||||
58
Yeti/Views/NostrClientView.swift
Normal file
58
Yeti/Views/NostrClientView.swift
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// NostrClientView.swift
|
||||
// Yeti
|
||||
//
|
||||
// Created by Terry Yiu on 1/21/25.
|
||||
//
|
||||
|
||||
import SwiftData
|
||||
import SwiftUI
|
||||
|
||||
struct NostrClientView: View {
|
||||
@Query private var nostrClientModels: [NostrClientModel]
|
||||
|
||||
init(nostrClientModelId: String) {
|
||||
self._nostrClientModels = Query(filter: #Predicate<NostrClientModel> {
|
||||
$0.id == nostrClientModelId
|
||||
})
|
||||
}
|
||||
|
||||
var nostrClientModel: NostrClientModel {
|
||||
nostrClientModels.first!
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
let bindableNostrClientModel = Bindable(nostrClientModel)
|
||||
|
||||
Text(bindableNostrClientModel.id)
|
||||
.font(.headline)
|
||||
|
||||
List {
|
||||
Toggle("Read your profile", isOn: bindableNostrClientModel.readPublicKeyPermission)
|
||||
Toggle("Get relays", isOn: bindableNostrClientModel.getRelaysPermission)
|
||||
Toggle("Encrypt DMs", isOn: bindableNostrClientModel.nip44EncryptPermission)
|
||||
Toggle("Decrypt DMs", isOn: bindableNostrClientModel.nip44DecryptPermission)
|
||||
Toggle("Encrypt legacy DMs", isOn: bindableNostrClientModel.nip04EncryptPermission)
|
||||
Toggle("Decrypt legacy DMs", isOn: bindableNostrClientModel.nip04DecryptPermission)
|
||||
Toggle("Decrypt zap events", isOn: bindableNostrClientModel.decryptZapEventPermission)
|
||||
|
||||
ForEach(bindableNostrClientModel.signEventPermissions, id: \.self) { signEventPermissionModel in
|
||||
Toggle("Sign kind \(signEventPermissionModel.kind.wrappedValue.description) events", isOn: signEventPermissionModel.allowed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension NostrClientModel {
|
||||
static func predicateById(_ id: String) -> Predicate<NostrClientModel> {
|
||||
#Predicate<NostrClientModel> { nostrClientModel in
|
||||
nostrClientModel.id == id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
NostrClientView(nostrClientModelId: UUID().uuidString)
|
||||
}
|
||||
@@ -5,11 +5,38 @@
|
||||
// Created by Terry Yiu on 1/20/25.
|
||||
//
|
||||
|
||||
import SwiftData
|
||||
import SwiftUI
|
||||
|
||||
struct PermissionsView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query(sort: \NostrClientModel.id) var nostrClientModels: [NostrClientModel]
|
||||
|
||||
var body: some View {
|
||||
EmptyView()
|
||||
NavigationStack {
|
||||
List {
|
||||
ForEach(nostrClientModels, id: \.self) { nostrClientModel in
|
||||
NavigationLink(
|
||||
nostrClientModel.id,
|
||||
destination: NostrClientView(nostrClientModelId: nostrClientModel.id)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO Remove this dummy code
|
||||
.onAppear(perform: addNostrClientModel)
|
||||
}
|
||||
|
||||
// TODO Remove this dummy code
|
||||
private func addNostrClientModel() {
|
||||
withAnimation {
|
||||
let newNostrClientModel = NostrClientModel(id: Date().timeIntervalSince1970.rounded().description)
|
||||
newNostrClientModel.signEventPermissions = [
|
||||
SignEventPermissionModel(kind: 1, allowed: true),
|
||||
SignEventPermissionModel(kind: 31923, allowed: true)
|
||||
]
|
||||
modelContext.insert(newNostrClientModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user