Open remote signer connections in a settings modal
This commit is contained in:
8 files changed
+145
-37
No files matched your search
@@ -2,7 +2,7 @@
|
||||
<!-- Modal Background -->
|
||||
<div class="hidden fixed inset-0 bg-black bg-opacity-80 overflow-y-auto flex items-center justify-center"
|
||||
data-modal-target="background"
|
||||
data-action="click->modal#closeBackground"
|
||||
<% if @dismissible %>data-action="click->modal#closeBackground"<% end %>
|
||||
data-transition-enter="transition-all ease-in-out duration-100"
|
||||
data-transition-enter-from="bg-opacity-0"
|
||||
data-transition-enter-to="bg-opacity-80"
|
||||
@@ -15,7 +15,7 @@
|
||||
class="relative m-4 max-h-screen w-auto max-w-full
|
||||
hidden animate-scale-in fixed inset-0 overflow-y-auto flex items-center justify-center">
|
||||
<!-- Modal Card -->
|
||||
<div class="m-1 bg-white rounded shadow">
|
||||
<div class="m-1 bg-white rounded shadow <%= @card_class %>">
|
||||
<div class="p-8">
|
||||
<%= content %>
|
||||
<% if @show_close_button %>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
class ModalComponent < ViewComponent::Base
|
||||
def initialize(show_close_button: true)
|
||||
def initialize(show_close_button: true, dismissible: true, card_class: nil)
|
||||
@show_close_button = show_close_button
|
||||
@dismissible = dismissible
|
||||
@card_class = card_class
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,8 +1,8 @@
|
||||
<section class="mt-8">
|
||||
<section class="<%= section_class %>">
|
||||
<h4 class="mb-0"><%= @title %></h4>
|
||||
|
||||
<% if @description.present? %>
|
||||
<p class="mt-2 text-sm text-gray-600"><%= @description %></p>
|
||||
<p class="mt-2 <%= text_class %> text-gray-600"><%= @description %></p>
|
||||
<% end %>
|
||||
|
||||
<% if @active_session.present? %>
|
||||
@@ -24,7 +24,7 @@
|
||||
data-nostr-signer-connect-status-url-value="<%= @status_url %>">
|
||||
<% unless @pending_session.bunker? %>
|
||||
<div data-nostr-signer-connect-target="details">
|
||||
<p class="mt-3 text-sm">Scan this QR code with your signer app, or copy the connection URI:</p>
|
||||
<p class="mt-3 <%= text_class %>">Scan this QR code with your signer app, or copy the connection URI:</p>
|
||||
|
||||
<div class="mt-4 flex justify-center">
|
||||
<div class="w-56 max-w-full rounded-lg bg-white p-3">
|
||||
@@ -34,10 +34,10 @@
|
||||
|
||||
<p class="mt-3">
|
||||
<input type="text" readonly value="<%= @pending_session.nostrconnect_uri %>"
|
||||
class="w-full text-xs" data-nostr-signer-connect-target="uri" />
|
||||
class="w-full <%= input_class %>" data-nostr-signer-connect-target="uri" />
|
||||
</p>
|
||||
<p class="mt-2">
|
||||
<button type="button" class="btn-sm btn-gray"
|
||||
<button type="button" class="<%= action_button_class %>"
|
||||
data-action="nostr-signer-connect#copy">
|
||||
Copy connection URI
|
||||
</button>
|
||||
@@ -45,11 +45,11 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<p class="mt-4 text-sm text-gray-600" data-nostr-signer-connect-target="status">
|
||||
<p class="mt-4 <%= text_class %> text-gray-600" data-nostr-signer-connect-target="status">
|
||||
Waiting for your signer…
|
||||
</p>
|
||||
|
||||
<p class="mt-2 hidden text-sm" data-nostr-signer-connect-target="authWrapper">
|
||||
<p class="mt-2 hidden <%= text_class %>" data-nostr-signer-connect-target="authWrapper">
|
||||
<a href="#" target="_blank" rel="noopener noreferrer"
|
||||
class="text-blue-700 underline"
|
||||
data-nostr-signer-connect-target="authLink">
|
||||
@@ -57,31 +57,33 @@
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p class="mt-2 hidden text-sm text-red-700" data-nostr-signer-connect-target="error"></p>
|
||||
<p class="mt-2 hidden <%= text_class %> text-red-700" data-nostr-signer-connect-target="error"></p>
|
||||
|
||||
<p class="mt-4 hidden" data-nostr-signer-connect-target="retry">
|
||||
<%= button_to "Try again", @create_url, method: :post, class: "btn-sm btn-gray" %>
|
||||
<%= button_to "Try again", @create_url, method: :post, class: action_button_class %>
|
||||
</p>
|
||||
|
||||
<details class="mt-4 text-sm">
|
||||
<summary class="cursor-pointer text-gray-600">Prefer a bunker:// URI?</summary>
|
||||
<%= form_with url: @create_url, method: :post, local: true, class: "mt-3" do %>
|
||||
<p>
|
||||
<%= text_field_tag :bunker_uri, nil,
|
||||
placeholder: "bunker://…",
|
||||
class: "w-full text-xs",
|
||||
autocomplete: "off" %>
|
||||
</p>
|
||||
<p class="mt-2">
|
||||
<%= submit_tag "Connect bunker", class: "btn-sm btn-gray" %>
|
||||
</p>
|
||||
<% end %>
|
||||
</details>
|
||||
<% unless @modal %>
|
||||
<details class="mt-4 text-sm">
|
||||
<summary class="cursor-pointer text-gray-600">Prefer a bunker:// URI?</summary>
|
||||
<%= form_with url: @create_url, method: :post, local: true, class: "mt-3" do %>
|
||||
<p>
|
||||
<%= text_field_tag :bunker_uri, nil,
|
||||
placeholder: "bunker://…",
|
||||
class: "w-full text-xs",
|
||||
autocomplete: "off" %>
|
||||
</p>
|
||||
<p class="mt-2">
|
||||
<%= submit_tag "Connect bunker", class: "btn-sm btn-gray" %>
|
||||
</p>
|
||||
<% end %>
|
||||
</details>
|
||||
<% end %>
|
||||
|
||||
<% if @show_disconnect && @destroy_url.present? %>
|
||||
<p class="mt-4">
|
||||
<%= button_to "Cancel", @destroy_url, method: :delete,
|
||||
class: "btn-sm btn-outline text-gray-700" %>
|
||||
class: cancel_button_class %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,7 @@ require "rqrcode"
|
||||
class NostrSignerConnectComponent < ViewComponent::Base
|
||||
def initialize(pending_session: nil, active_session: nil, create_url:, destroy_url: nil,
|
||||
status_url: nil, title: "Remote signer", description: nil,
|
||||
show_disconnect: true)
|
||||
show_disconnect: true, modal: false)
|
||||
@pending_session = pending_session
|
||||
@active_session = active_session
|
||||
@create_url = create_url
|
||||
@@ -12,6 +12,27 @@ class NostrSignerConnectComponent < ViewComponent::Base
|
||||
@title = title
|
||||
@description = description
|
||||
@show_disconnect = show_disconnect
|
||||
@modal = modal
|
||||
end
|
||||
|
||||
def section_class
|
||||
@modal ? "" : "mt-8"
|
||||
end
|
||||
|
||||
def text_class
|
||||
@modal ? "text-base" : "text-sm"
|
||||
end
|
||||
|
||||
def input_class
|
||||
@modal ? "text-sm font-mono" : "text-xs"
|
||||
end
|
||||
|
||||
def action_button_class
|
||||
@modal ? "btn-md btn-gray" : "btn-sm btn-gray"
|
||||
end
|
||||
|
||||
def cancel_button_class
|
||||
@modal ? "btn-md btn-outline text-gray-700" : "btn-sm btn-outline text-gray-700"
|
||||
end
|
||||
|
||||
def qr_svg
|
||||
|
||||
@@ -89,13 +89,32 @@
|
||||
<% end %>
|
||||
|
||||
<% if nostr_remote_signer_available? %>
|
||||
<%= render NostrSignerConnectComponent.new(
|
||||
pending_session: @pending_signer_session,
|
||||
active_session: active_nostr_signer_session,
|
||||
create_url: nostr_signer_settings_path,
|
||||
destroy_url: nostr_signer_settings_path,
|
||||
status_url: @pending_signer_session ? nostr_signer_status_settings_path(token: @pending_signer_session.token) : nil
|
||||
) %>
|
||||
<% if @pending_signer_session.present? %>
|
||||
<div data-controller="modal"
|
||||
data-modal-open-value="true"
|
||||
data-action="turbo:load->modal#open">
|
||||
<%= render ModalComponent.new(
|
||||
show_close_button: false,
|
||||
dismissible: false,
|
||||
card_class: "w-80 max-w-[85vw]"
|
||||
) do %>
|
||||
<%= render NostrSignerConnectComponent.new(
|
||||
pending_session: @pending_signer_session,
|
||||
create_url: nostr_signer_settings_path,
|
||||
destroy_url: nostr_signer_settings_path,
|
||||
status_url: nostr_signer_status_settings_path(token: @pending_signer_session.token),
|
||||
title: "Connect remote signer",
|
||||
modal: true
|
||||
) %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= render NostrSignerConnectComponent.new(
|
||||
active_session: active_nostr_signer_session,
|
||||
create_url: nostr_signer_settings_path,
|
||||
destroy_url: nostr_signer_settings_path
|
||||
) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe ModalComponent, type: :component do
|
||||
it "dismisses on background click by default" do
|
||||
rendered = render_inline(described_class.new) { "Body" }
|
||||
|
||||
background = rendered.css("[data-modal-target='background']").first
|
||||
expect(background["data-action"]).to eq("click->modal#closeBackground")
|
||||
end
|
||||
|
||||
it "can disable background dismissal" do
|
||||
rendered = render_inline(described_class.new(dismissible: false, card_class: "w-80")) { "Body" }
|
||||
|
||||
background = rendered.css("[data-modal-target='background']").first
|
||||
expect(background["data-action"]).to be_nil
|
||||
expect(rendered.css(".w-80").any?).to be(true)
|
||||
end
|
||||
end
|
||||
@@ -48,4 +48,37 @@ RSpec.describe NostrSignerConnectComponent, type: :component do
|
||||
expect(rendered.css("[data-nostr-signer-connect-target='details']").any?).to be(true)
|
||||
expect(rendered.text).to include("Try again")
|
||||
end
|
||||
|
||||
it "uses normal typography in modal mode" do
|
||||
pending_session = instance_double(
|
||||
NostrSignerSession,
|
||||
bunker?: false,
|
||||
nostrconnect_uri: "nostrconnect://#{SecureRandom.hex(32)}?relay=wss%3A%2F%2Frelay.example.com&secret=abc"
|
||||
)
|
||||
|
||||
rendered = render_inline(
|
||||
described_class.new(
|
||||
pending_session: pending_session,
|
||||
create_url: "/settings/nostr_signer",
|
||||
destroy_url: "/settings/nostr_signer",
|
||||
status_url: "/settings/nostr_signer/status",
|
||||
title: "Connect remote signer",
|
||||
modal: true
|
||||
)
|
||||
)
|
||||
|
||||
expect(rendered.text).to include("Connect remote signer")
|
||||
expect(rendered.text).to include("Cancel")
|
||||
expect(rendered.text).not_to include("Prefer a bunker:// URI?")
|
||||
expect(rendered.css("p.text-base").any?).to be(true)
|
||||
expect(rendered.css("button.btn-md").any?).to be(true)
|
||||
expect(rendered.css("section.mt-8")).to be_empty
|
||||
end
|
||||
|
||||
it "keeps the inline bunker option when no connection exists" do
|
||||
rendered = render_inline(described_class.new(create_url: "/settings/nostr_signer"))
|
||||
|
||||
expect(rendered.text).to include("Connect remote signer")
|
||||
expect(rendered.text).to include("Already have a bunker:// URI?")
|
||||
end
|
||||
end
|
||||
@@ -44,7 +44,7 @@ RSpec.describe "Settings::NostrSigners", type: :request do
|
||||
expect(data["uri"]).to start_with("nostrconnect://")
|
||||
end
|
||||
|
||||
it "renders the QR code and status poll for a pending session" do
|
||||
it "renders the QR code and status poll inside an open modal" do
|
||||
post nostr_signer_settings_path, as: :json
|
||||
|
||||
get setting_path(:nostr)
|
||||
@@ -52,6 +52,19 @@ RSpec.describe "Settings::NostrSigners", type: :request do
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("nostrconnect://")
|
||||
expect(response.body).to include("Waiting for your signer")
|
||||
expect(response.body).to include('data-modal-open-value="true"')
|
||||
expect(response.body).to include('data-modal-target="background"')
|
||||
expect(response.body).to include("Connect remote signer")
|
||||
expect(response.body).not_to include("Already have a bunker:// URI?")
|
||||
end
|
||||
|
||||
it "keeps the inline connect button and bunker option when no session is pending" do
|
||||
get setting_path(:nostr)
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("Connect remote signer")
|
||||
expect(response.body).to include("Already have a bunker:// URI?")
|
||||
expect(response.body).not_to include('data-modal-open-value="true"')
|
||||
end
|
||||
|
||||
it "creates a bunker session" do
|
||||
|
||||
Reference in new issue
Block a user