diff --git a/app/components/settings/nostr_edit_profile_component.html.erb b/app/components/settings/nostr_edit_profile_component.html.erb new file mode 100644 index 0000000..cb7472e --- /dev/null +++ b/app/components/settings/nostr_edit_profile_component.html.erb @@ -0,0 +1,44 @@ +
+
');"> +
+ <% if @profile["picture"].present? %> + " + class="inline-block size:28 sm:size-32 rounded-full border-2 border-white" /> + <% else %> + + + + + + <% end %> +
+
+
+ <%= form_for(@user, url: setting_path(:nostr), html: { :method => :put }) do |f| %> + <%= render FormElements::FieldsetComponent.new(tag: "div", title: "Display name") do %> + <%= f.text_field :display_name, value: @display_name, class: "w-full sm:w-3/5" %> + <% if @validation_errors.present? && @validation_errors[:display_name].present? %> +

<%= @validation_errors[:display_name].first %>

+ <% end %> + <% end %> + <%= render FormElements::FieldsetComponent.new(tag: "div", title: "Nostr address (NIP-05)") do %> + <%= f.text_field :nip05_address, value: @profile["nip05"], class: "w-full sm:w-3/5" %> + <% if @validation_errors.present? && @validation_errors[:nip05_address].present? %> +

<%= @validation_errors[:nip05_address].first %>

+ <% end %> + <% end %> + <%= render FormElements::FieldsetComponent.new(tag: "div", title: "Ligtning address for Zaps") do %> + <%= f.text_field :lud16_address, value: @profile["lud16"], class: "w-full sm:w-3/5" %> + <% if @validation_errors.present? && @validation_errors[:lud16_address].present? %> +

<%= @validation_errors[:lud16_address].first %>

+ <% end %> + <% end %> + <% end %> +
+ +
diff --git a/app/components/settings/nostr_edit_profile_component.rb b/app/components/settings/nostr_edit_profile_component.rb new file mode 100644 index 0000000..6231caa --- /dev/null +++ b/app/components/settings/nostr_edit_profile_component.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Settings + class NostrEditProfileComponent < ViewComponent::Base + def initialize(user:, profile_event:) + if profile_event.present? + @user = user + @profile_event = profile_event + @profile = JSON.parse(profile_event["content"]) + @display_name = @profile["display_name"] || @profile["displayName"] + + if @profile["nip05"].present? && @profile["nip05"] == @user.address + # "Your profile's Nostr address is set to #{ user_address }" + else + # "Your profile's Nostr address is not set to #{ user_address } yet" + end + + if @profile["lud16"].present? && @profile["lud16"] == @user.address + # "Your profile's Lightning address is set to #{ user_address }" + else + # "Your profile's Lightning address is not set to #{ user_address } yet" + end + else + # "We could not find a profile for your public key" + end + end + end +end diff --git a/app/components/settings/nostr_profile_status_component.html.erb b/app/components/settings/nostr_profile_status_component.html.erb index 24d38f5..b326db7 100644 --- a/app/components/settings/nostr_profile_status_component.html.erb +++ b/app/components/settings/nostr_profile_status_component.html.erb @@ -5,3 +5,17 @@ icon_color: status[:icon_color] ) %> <% end %> + +<% if @status == 1 %> +

+ +

+<% elsif @status == 2 %> +

+ +

+<% end %> diff --git a/app/components/settings/nostr_relay_status_component.html.erb b/app/components/settings/nostr_relay_status_component.html.erb index 0a4cd0d..1592f9c 100644 --- a/app/components/settings/nostr_relay_status_component.html.erb +++ b/app/components/settings/nostr_relay_status_component.html.erb @@ -2,3 +2,17 @@ text: @text, icon_name: @icon_name, icon_color: @icon_color) %> + +<% if @status == 1 %> +

+ +

+<% elsif @status == 2 %> +

+ +

+<% end %> diff --git a/app/components/settings/nostr_relay_status_component.rb b/app/components/settings/nostr_relay_status_component.rb index 084a54c..88d5d6d 100644 --- a/app/components/settings/nostr_relay_status_component.rb +++ b/app/components/settings/nostr_relay_status_component.rb @@ -8,15 +8,18 @@ module Settings @text = "You have a relay list, and the Kosmos relay is part of it" @icon_name = "check-circle" @icon_color = "emerald-500" + @status = 0 else @text = "The Kosmos relay is missing from your relay list" @icon_name = "alert-octagon" @icon_color = "amber-500" + @status = 1 end else @text = "We could not find a relay list for your public key" @icon_name = "alert-octagon" @icon_color = "amber-500" + @status = 2 end end diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 47e9b43..df24298 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -137,20 +137,22 @@ class SettingsController < ApplicationController if @user.nostr_pubkey.present? outbox_relay_urls = nil - if @nip65_event = NostrManager::DiscoverUserRelays.call(pubkey: @user.nostr_pubkey) - relay_tags = @nip65_event["tags"].select{ |t| t[0] == "r" } - outbox_relay_urls = relay_tags&.select{ |t| t[2] != "read" }&.map{ |t| t[1] } - end + # if @nip65_event = NostrManager::DiscoverUserRelays.call(pubkey: @user.nostr_pubkey) + # relay_tags = @nip65_event["tags"].select{ |t| t[0] == "r" } + # outbox_relay_urls = relay_tags&.select{ |t| t[2] != "read" }&.map{ |t| t[1] } + # end - @profile = NostrManager::DiscoverUserProfile.call( - pubkey: @user.nostr_pubkey, - relays: outbox_relay_urls - ) + # @profile = NostrManager::DiscoverUserProfile.call( + # pubkey: @user.nostr_pubkey, + # relays: outbox_relay_urls + # ) + @profile = {"content"=>"{\"name\":\"jimmy\",\"picture\":\"https://storage.kosmos.org/jimmy/public/shares/241028-1117-tony.jpg\",\"banner\":\"https://storage.kosmos.org/raucao/public/shares/240604-1517-1500x500.jpg\",\"nip05\":\"jimmy@kosmos.org\",\"lud16\":\"jimmy@kosmos.org\",\"pubkey\":\"07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3\",\"display_name\":\"Jimmy\",\"displayName\":\"Jimmy\",\"about\":\"I don't exist. Follow at your own peril.\"}", "created_at"=>1730114246, "id"=>"6b15b1308a61ee837bd3b50319978314650e435891c259f4ea499f819f35a4f6", "kind"=>0, "pubkey"=>"07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3", "sig"=>"4f681f4b95646bbf88a6eae9ca92c0f2ce5effecfa017556a23490f91a99243aedf81d956ee2466ed64fecb9a03b6b89cd80ff116df0178830977e203867d7ae", "tags"=>[]} + # @profile = {"content"=>"{\"name\":\"jimmy\",\"nip05\":\"jimmy@kosmos.org\",\"lud16\":\"jimmy@kosmos.org\",\"pubkey\":\"07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3\",\"display_name\":\"Jimmy\",\"displayName\":\"Jimmy\",\"about\":\"I don't exist. Follow at your own peril.\"}", "created_at"=>1730114246, "id"=>"6b15b1308a61ee837bd3b50319978314650e435891c259f4ea499f819f35a4f6", "kind"=>0, "pubkey"=>"07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3", "sig"=>"4f681f4b95646bbf88a6eae9ca92c0f2ce5effecfa017556a23490f91a99243aedf81d956ee2466ed64fecb9a03b6b89cd80ff116df0178830977e203867d7ae", "tags"=>[]} else @relays, @profile = [nil, nil] end - render partial: 'nostr_user_relays' + render partial: 'nostr_user_metadata' end private diff --git a/app/services/nostr_manager/fetch_event.rb b/app/services/nostr_manager/fetch_event.rb index 76cb822..7767883 100644 --- a/app/services/nostr_manager/fetch_event.rb +++ b/app/services/nostr_manager/fetch_event.rb @@ -1,6 +1,6 @@ module NostrManager class FetchEvent < NostrManagerService - TIMEOUT = 1 + TIMEOUT = 10 def initialize(filter:, relay_url:) @filter = filter diff --git a/app/services/nostr_manager/fetch_latest_event.rb b/app/services/nostr_manager/fetch_latest_event.rb index 5cff423..8046577 100644 --- a/app/services/nostr_manager/fetch_latest_event.rb +++ b/app/services/nostr_manager/fetch_latest_event.rb @@ -1,6 +1,6 @@ module NostrManager class FetchLatestEvent < NostrManagerService - TIMEOUT = 5 + TIMEOUT = 20 def initialize(relays:, filter:, max_events: 2) @relays = relays diff --git a/app/views/settings/_nostr_user_metadata.html.erb b/app/views/settings/_nostr_user_metadata.html.erb new file mode 100644 index 0000000..9db7cec --- /dev/null +++ b/app/views/settings/_nostr_user_metadata.html.erb @@ -0,0 +1,27 @@ +<%= turbo_frame_tag "nostr_user_metadata" do %> +
+

Relays

+ <%= render Settings::NostrRelayStatusComponent.new( + nip65_event: @nip65_event + ) %> +
+ +
+

Profile

+ <%= render Settings::NostrProfileStatusComponent.new( + profile_event: @profile, + user_address: current_user.address + ) %> +
+ + <%= render ModalComponent.new(show_close_button: false) do %> + <%= render Settings::NostrEditProfileComponent.new( + user: current_user, + profile_event: @profile + ) %> + <% end %> +
+
+<% end %> diff --git a/app/views/settings/_nostr_user_relays.html.erb b/app/views/settings/_nostr_user_relays.html.erb deleted file mode 100644 index 7938471..0000000 --- a/app/views/settings/_nostr_user_relays.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<%= turbo_frame_tag "nostr_user_metadata" do %> -
-

Relays

- <%= render Settings::NostrRelayStatusComponent.new( - nip65_event: @nip65_event - ) %> -
-
-

Profile

- <%= render Settings::NostrProfileStatusComponent.new( - profile_event: @profile, - user_address: current_user.address - ) %> -
-<% end %> diff --git a/app/views/shared/nostr/_edit_user_profile.html.erb b/app/views/shared/nostr/_edit_user_profile.html.erb new file mode 100644 index 0000000..8f45521 --- /dev/null +++ b/app/views/shared/nostr/_edit_user_profile.html.erb @@ -0,0 +1,3 @@ +
+ <%= profile.inspect %> +