Merge branch 'master' into add-wallet-modal

This commit is contained in:
Suhail Saqan
2022-12-25 23:44:51 -06:00
4 changed files with 43 additions and 8 deletions

View File

@@ -57,13 +57,25 @@ struct Profile: Codable {
set(s) { value["lud16"] = s }
}
var lnurl: String? {
guard let addr = lud06 ?? lud16 else {
return nil;
}
if addr.contains("@") {
return lnaddress_to_lnurl(addr);
}
return addr;
}
var nip05: String? {
get { return value["nip05"]; }
set(s) { value["nip05"] = s }
}
var lightning_uri: URL? {
return make_ln_url(self.lud06) ?? make_ln_url(self.lud16)
return make_ln_url(self.lnurl)
}
init(from decoder: Decoder) throws {
@@ -110,3 +122,17 @@ struct NostrSubscription {
let sub_id: String
let filter: NostrFilter
}
func lnaddress_to_lnurl(_ lnaddr: String) -> String? {
let parts = lnaddr.split(separator: "@")
guard parts.count == 2 else {
return nil
}
let url = "https://\(parts[1])/.well-known/lnurlp/\(parts[0])";
guard let dat = url.data(using: .utf8) else {
return nil
}
return bech32_encode(hrp: "lnurl", Array(dat))
}

View File

@@ -133,7 +133,8 @@ func get_saved_pubkey() -> String? {
}
func get_saved_privkey() -> String? {
try? Vault.getPrivateKey(keychainConfiguration: DamusKeychainConfiguration())
let mkey = try? Vault.getPrivateKey(keychainConfiguration: DamusKeychainConfiguration());
return mkey.map { $0.trimmingCharacters(in: .whitespaces) }
}
fileprivate func removePrivateKeyFromUserDefaults() throws {

View File

@@ -84,8 +84,8 @@ struct EditMetadataView: View {
website: website,
nip05: nip05.isEmpty ? nil : nip05,
picture: picture.isEmpty ? nil : picture,
lud06: ln.contains("@") ? ln : nil,
lud16: ln.contains("@") ? nil : ln
lud06: ln.contains("@") ? nil : ln,
lud16: ln.contains("@") ? ln : nil
);
let m_metadata_ev = make_metadata_event(keypair: damus_state.keypair, metadata: metadata)

View File

@@ -126,7 +126,7 @@ struct ProfileView: View {
//@EnvironmentObject var profile: ProfileModel
func LNButton(lud06: String?, lud16: String?) -> some View {
func LNButton(lud06: String?, lud16: String?, profile: Profile) -> some View {
Button(action: {
if let l = lud06 {
inv = l
@@ -139,6 +139,12 @@ struct ProfileView: View {
.symbolRenderingMode(.palette)
.font(.system(size: 34).weight(.thin))
.foregroundStyle(colorScheme == .light ? .black : .white, colorScheme == .light ? .black.opacity(0.1) : .white.opacity(0.2))
}.contextMenu {
Button {
UIPasteboard.general.string = profile.lnurl ?? ""
} label: {
Label("Copy LNUrl", systemImage: "doc.on.doc")
}
}.sheet(isPresented: $showingSelectWallet, onDismiss: {showingSelectWallet = false}) {
SelectWalletView(showingSelectWallet: $showingSelectWallet, invoice: $inv)
}
@@ -164,9 +170,11 @@ struct ProfileView: View {
ProfilePicView(pubkey: profile.pubkey, size: PFP_SIZE, highlight: .custom(Color.black, 2), profiles: damus_state.profiles)
Spacer()
if (data != nil) && (data?.lud06 != nil || data?.lud16 != nil) {
LNButton(lud06: data?.lud06, lud16: data?.lud16)
if let profile = data {
if (profile?.lud06 != nil || profile?.lud16 != nil) {
LNButton(lud06: data?.lud06, lud16: data?.lud16,, profile: profile)
}
}
DMButton