Compare commits

...

1 Commits

Author SHA1 Message Date
46db94b94d Trim whitespaces from Lightning addresses
Changelog-Fixed: Trim whitespaces from Lightning addresses
Signed-off-by: Terry Yiu <git@tyiu.xyz>
2025-02-16 23:05:53 -05:00
3 changed files with 15 additions and 10 deletions

View File

@@ -31,7 +31,8 @@ class ProfileRecord {
} }
guard let profile = data.profile, guard let profile = data.profile,
let addr = profile.lud16 ?? profile.lud06 else { let addr = (profile.lud16 ?? profile.lud06)?.trimmingCharacters(in: .whitespaces)
else {
return nil; return nil;
} }
@@ -301,7 +302,7 @@ class Profile: Codable {
*/ */
func make_test_profile() -> Profile { 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", damus_donation: 1) 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: nil, lud16: "jb55@jb55.com", nip05: "jb55@jb55.com", damus_donation: 1)
} }
func make_ln_url(_ str: String?) -> URL? { func make_ln_url(_ str: String?) -> URL? {

View File

@@ -170,6 +170,9 @@ struct EditMetadataView: View {
TextField(NSLocalizedString("Lightning Address or LNURL", comment: "Placeholder text for entry of Lightning Address or LNURL."), text: $ln) TextField(NSLocalizedString("Lightning Address or LNURL", comment: "Placeholder text for entry of Lightning Address or LNURL."), text: $ln)
.autocorrectionDisabled(true) .autocorrectionDisabled(true)
.textInputAutocapitalization(.never) .textInputAutocapitalization(.never)
.onReceive(Just(ln)) { newValue in
self.ln = newValue.trimmingCharacters(in: .whitespaces)
}
} }
Section(content: { Section(content: {

View File

@@ -24,8 +24,8 @@ struct ProfileZapLinkView<Content: View>: View {
self.label = label self.label = label
self.action = action self.action = action
self.reactions_enabled = reactions_enabled self.reactions_enabled = reactions_enabled
self.lud16 = lud16 self.lud16 = lud16?.trimmingCharacters(in: .whitespaces)
self.lnurl = lnurl self.lnurl = lnurl?.trimmingCharacters(in: .whitespaces)
} }
init(damus_state: DamusState, pubkey: Pubkey, action: ActionFunction? = nil, @ViewBuilder label: @escaping ContentViewFunction) { init(damus_state: DamusState, pubkey: Pubkey, action: ActionFunction? = nil, @ViewBuilder label: @escaping ContentViewFunction) {
@@ -36,8 +36,8 @@ struct ProfileZapLinkView<Content: View>: View {
let profile_txn = damus_state.profiles.lookup_with_timestamp(pubkey) let profile_txn = damus_state.profiles.lookup_with_timestamp(pubkey)
let record = profile_txn?.unsafeUnownedValue let record = profile_txn?.unsafeUnownedValue
self.reactions_enabled = record?.profile?.reactions ?? true self.reactions_enabled = record?.profile?.reactions ?? true
self.lud16 = record?.profile?.lud06 self.lud16 = record?.profile?.lud06?.trimmingCharacters(in: .whitespaces)
self.lnurl = record?.lnurl self.lnurl = record?.lnurl?.trimmingCharacters(in: .whitespaces)
} }
init(unownedProfileRecord: ProfileRecord?, profileModel: ProfileModel, action: ActionFunction? = nil, @ViewBuilder label: @escaping ContentViewFunction) { init(unownedProfileRecord: ProfileRecord?, profileModel: ProfileModel, action: ActionFunction? = nil, @ViewBuilder label: @escaping ContentViewFunction) {
@@ -46,8 +46,8 @@ struct ProfileZapLinkView<Content: View>: View {
self.action = action self.action = action
self.reactions_enabled = unownedProfileRecord?.profile?.reactions ?? true self.reactions_enabled = unownedProfileRecord?.profile?.reactions ?? true
self.lud16 = unownedProfileRecord?.profile?.lud16 self.lud16 = unownedProfileRecord?.profile?.lud16?.trimmingCharacters(in: .whitespaces)
self.lnurl = unownedProfileRecord?.lnurl self.lnurl = unownedProfileRecord?.lnurl?.trimmingCharacters(in: .whitespaces)
} }
var body: some View { var body: some View {
@@ -81,12 +81,13 @@ struct ProfileZapLinkView<Content: View>: View {
} }
} }
} }
.disabled(lnurl == nil) .disabled(lnurl == nil && lud16 == nil)
} }
} }
#Preview { #Preview {
ProfileZapLinkView(pubkey: test_pubkey, reactions_enabled: true, lud16: make_test_profile().lud16, lnurl: "test@sendzaps.lol", label: { reactions_enabled, lud16, lnurl in let profile = make_test_profile()
ProfileZapLinkView(pubkey: test_pubkey, reactions_enabled: true, lud16: profile.lud16, lnurl: profile.lud06, label: { reactions_enabled, lud16, lnurl in
Image("zap.fill") Image("zap.fill")
}) })
} }