Improve the mobile signer connect experience
This commit is contained in:
4 files changed
+61
-32
No files matched your search
@@ -30,23 +30,42 @@
|
||||
data-nostr-signer-connect-status-url-value="<%= @status_url %>">
|
||||
<% unless @pending_session.bunker? %>
|
||||
<div data-nostr-signer-connect-target="details">
|
||||
<div class="<%= @title.present? ? "mt-4" : "" %> flex justify-center">
|
||||
<div class="<%= @title.present? ? "mt-4" : "" %> hidden justify-center sm:flex"
|
||||
data-nostr-signer-connect-target="qr">
|
||||
<div class="<%= qr_wrapper_class %> rounded-lg bg-white p-3">
|
||||
<%= qr_svg %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="mt-3">
|
||||
<input type="text" readonly value="<%= @pending_session.nostrconnect_uri %>"
|
||||
class="w-full <%= input_class %>" data-nostr-signer-connect-target="uri" />
|
||||
</p>
|
||||
<p class="mt-2">
|
||||
<button type="button" class="<%= action_button_class %>"
|
||||
data-action="nostr-signer-connect#copy">
|
||||
Copy connection URI
|
||||
<p class="mt-2 sm:hidden" data-nostr-signer-connect-target="qrToggle">
|
||||
<button type="button" class="text-sm text-gray-600 underline"
|
||||
data-action="nostr-signer-connect#showQr">
|
||||
Show QR code
|
||||
</button>
|
||||
</p>
|
||||
<p class="mt-2">
|
||||
|
||||
<p data-controller="clipboard" class="mt-3 flex gap-1">
|
||||
<input type="text" readonly value="<%= @pending_session.nostrconnect_uri %>"
|
||||
class="grow <%= input_class %>" data-clipboard-target="source" />
|
||||
<button type="button" class="btn-md btn-icon btn-outline shrink-0"
|
||||
data-clipboard-target="trigger" data-action="clipboard#copy"
|
||||
title="Copy to clipboard">
|
||||
<span class="content-initial">
|
||||
<%= render partial: "icons/copy", locals: { custom_class: "text-blue-600 h-4 w-4 inline" } %>
|
||||
</span>
|
||||
<span class="content-active hidden">
|
||||
<%= render partial: "icons/check", locals: { custom_class: "text-blue-600 h-4 w-4 inline" } %>
|
||||
</span>
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<p class="mt-2 sm:hidden">
|
||||
<a href="<%= @pending_session.nostrconnect_uri %>"
|
||||
class="btn-md btn-blue w-full text-center"
|
||||
data-action="nostr-signer-connect#openSigner">
|
||||
Open with signer app
|
||||
</a>
|
||||
</p>
|
||||
<p class="mt-2 hidden sm:block">
|
||||
<a href="<%= @pending_session.nostrconnect_uri %>"
|
||||
class="<%= action_button_class %>"
|
||||
data-action="nostr-signer-connect#openSigner">
|
||||
|
||||
@@ -4,7 +4,7 @@ const POLL_INTERVAL = 2000
|
||||
const MAX_ATTEMPTS = 160
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "status", "error", "authWrapper", "authLink", "uri", "details", "retry", "signerHint" ]
|
||||
static targets = [ "status", "error", "authWrapper", "authLink", "details", "retry", "signerHint", "qr", "qrToggle" ]
|
||||
static values = { statusUrl: String }
|
||||
|
||||
connect () {
|
||||
@@ -58,18 +58,6 @@ export default class extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
async copy () {
|
||||
try {
|
||||
await navigator.clipboard.writeText(this.uriTarget.value)
|
||||
this.statusTarget.textContent = "Connection URI copied."
|
||||
setTimeout(() => {
|
||||
if (!this.stopped) this.statusTarget.textContent = "Waiting for your signer…"
|
||||
}, 3000)
|
||||
} catch (error) {
|
||||
this.showError("Could not copy the connection URI.")
|
||||
}
|
||||
}
|
||||
|
||||
openSigner () {
|
||||
if (!this.hasSignerHintTarget) return
|
||||
|
||||
@@ -123,6 +111,14 @@ export default class extends Controller {
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
showQr () {
|
||||
if (!this.hasQrTarget) return
|
||||
|
||||
this.qrTarget.classList.remove("hidden")
|
||||
this.qrTarget.classList.add("flex")
|
||||
if (this.hasQrToggleTarget) this.qrToggleTarget.classList.add("hidden")
|
||||
}
|
||||
|
||||
showAuthUrl (url) {
|
||||
if (!url) {
|
||||
this.authWrapperTarget.classList.add("hidden")
|
||||
|
||||
@@ -50,15 +50,24 @@ RSpec.describe NostrSignerConnectComponent, type: :component do
|
||||
|
||||
qr_wrapper = rendered.css("div.rounded-lg.bg-white").first
|
||||
expect(qr_wrapper["class"]).to include("w-[232px]", "max-w-full")
|
||||
|
||||
qr = rendered.css("[data-nostr-signer-connect-target='qr']").first
|
||||
expect(qr["class"]).to include("hidden", "sm:flex")
|
||||
expect(rendered.css("[data-nostr-signer-connect-target='qrToggle']").any?).to be(true)
|
||||
expect(rendered.css("[data-nostr-signer-connect-target='details']").any?).to be(true)
|
||||
expect(rendered.text).to include("Try again")
|
||||
|
||||
open_link = rendered.css("a[data-action='nostr-signer-connect#openSigner']").first
|
||||
expect(open_link["href"]).to eq(pending_session.nostrconnect_uri)
|
||||
expect(open_link.text).to include("Open with signer app")
|
||||
expect(open_link["class"]).to include("btn-gray")
|
||||
expect(open_link["class"]).not_to include("btn-blue")
|
||||
expect(rendered.text.index("Copy connection URI")).to be < rendered.text.index("Open with signer app")
|
||||
clipboard = rendered.css("[data-controller='clipboard']").first
|
||||
expect(clipboard.css("[data-clipboard-target='source']").any?).to be(true)
|
||||
expect(clipboard.css("[data-clipboard-target='trigger']").any?).to be(true)
|
||||
expect(clipboard.css("button.btn-icon.btn-outline").any?).to be(true)
|
||||
expect(rendered.text).not_to include("Copy connection URI")
|
||||
|
||||
open_links = rendered.css("a[data-action='nostr-signer-connect#openSigner']")
|
||||
expect(open_links.size).to eq(2)
|
||||
expect(open_links.first["href"]).to eq(pending_session.nostrconnect_uri)
|
||||
expect(open_links.first["class"]).to include("btn-blue", "w-full")
|
||||
expect(open_links.last["class"]).to include("btn-gray")
|
||||
expect(rendered.css("[data-nostr-signer-connect-target='signerHint']").any?).to be(true)
|
||||
|
||||
expect(rendered.css("p.text-sm")).to be_empty
|
||||
@@ -84,7 +93,9 @@ RSpec.describe NostrSignerConnectComponent, type: :component do
|
||||
|
||||
expect(rendered.css("h4")).to be_empty
|
||||
expect(rendered.css("section").first["class"]).not_to include("mt-8")
|
||||
expect(rendered.css("div.flex.justify-center").first["class"]).not_to include("mt-4")
|
||||
|
||||
qr = rendered.css("[data-nostr-signer-connect-target='qr']").first
|
||||
expect(qr["class"]).not_to include("mt-4")
|
||||
end
|
||||
|
||||
it "uses normal typography in modal mode" do
|
||||
@@ -117,7 +128,8 @@ RSpec.describe NostrSignerConnectComponent, type: :component do
|
||||
qr_wrapper = rendered.css("div.rounded-lg").first
|
||||
expect(qr_wrapper["class"]).to include("w-[264px]")
|
||||
expect(rendered.css("div.w-56")).to be_empty
|
||||
expect(rendered.css("button.w-full").size).to be >= 3
|
||||
expect(rendered.css("button.w-full").size).to be >= 2
|
||||
expect(rendered.css("a.w-full").size).to be >= 2
|
||||
expect(rendered.css("form.w-full").size).to eq(2)
|
||||
|
||||
retry_node = rendered.css("[data-nostr-signer-connect-target='retry']").first
|
||||
|
||||
@@ -42,6 +42,8 @@ RSpec.describe "Users::NostrConnects", type: :request do
|
||||
|
||||
open_link = html.css("a[data-action='nostr-signer-connect#openSigner']").first
|
||||
expect(open_link["href"]).to start_with("nostrconnect://")
|
||||
expect(html.css("a[data-action='nostr-signer-connect#openSigner']").size).to eq(2)
|
||||
expect(html.css("[data-controller='clipboard']").any?).to be(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user