Add an Open with signer app option to the connect dialogs
This commit is contained in:
5 files changed
+85
-4
No files matched your search
@@ -46,6 +46,17 @@
|
||||
Copy connection URI
|
||||
</button>
|
||||
</p>
|
||||
<p class="mt-2">
|
||||
<a href="<%= @pending_session.nostrconnect_uri %>"
|
||||
class="<%= action_button_class %>"
|
||||
data-action="nostr-signer-connect#openSigner">
|
||||
Open with signer app
|
||||
</a>
|
||||
</p>
|
||||
<p class="mt-2 hidden <%= text_class %> text-amber-800"
|
||||
data-nostr-signer-connect-target="signerHint">
|
||||
Didn’t open your signer app? Scan the QR code or copy the connection link.
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -99,7 +110,7 @@
|
||||
|
||||
<div class="mt-4">
|
||||
<%= button_to "Connect remote signer", @create_url, method: :post,
|
||||
class: "btn-md btn-blue w-full sm:w-auto" %>
|
||||
class: "btn-md btn-gray w-full sm:w-auto" %>
|
||||
</div>
|
||||
|
||||
<details class="mt-4">
|
||||
|
||||
@@ -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" ]
|
||||
static targets = [ "status", "error", "authWrapper", "authLink", "uri", "details", "retry", "signerHint" ]
|
||||
static values = { statusUrl: String }
|
||||
|
||||
connect () {
|
||||
@@ -70,6 +70,59 @@ export default class extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
openSigner () {
|
||||
if (!this.hasSignerHintTarget) return
|
||||
|
||||
this.signerHintTarget.classList.add("hidden")
|
||||
const attempt = this.launchAttempt = (this.launchAttempt || 0) + 1
|
||||
let launched = false
|
||||
let timer
|
||||
let onNavigateError
|
||||
|
||||
const finish = () => {
|
||||
clearTimeout(timer)
|
||||
document.removeEventListener("visibilitychange", onVisibility)
|
||||
window.removeEventListener("blur", onBlur)
|
||||
if (onNavigateError && "navigation" in window) {
|
||||
navigation.removeEventListener("navigateerror", onNavigateError)
|
||||
}
|
||||
}
|
||||
|
||||
const revealHint = () => {
|
||||
if (attempt !== this.launchAttempt || !this.hasSignerHintTarget) return
|
||||
this.signerHintTarget.classList.remove("hidden")
|
||||
}
|
||||
|
||||
const markLaunched = () => {
|
||||
launched = true
|
||||
finish()
|
||||
}
|
||||
|
||||
const onVisibility = () => {
|
||||
if (document.visibilityState === "hidden") markLaunched()
|
||||
}
|
||||
|
||||
const onBlur = () => markLaunched()
|
||||
|
||||
document.addEventListener("visibilitychange", onVisibility)
|
||||
window.addEventListener("blur", onBlur, { once: true })
|
||||
|
||||
if ("navigation" in window) {
|
||||
onNavigateError = (event) => {
|
||||
if (!event.destination?.url?.startsWith("nostrconnect:")) return
|
||||
finish()
|
||||
revealHint()
|
||||
}
|
||||
navigation.addEventListener("navigateerror", onNavigateError)
|
||||
}
|
||||
|
||||
timer = setTimeout(() => {
|
||||
if (launched || attempt !== this.launchAttempt) return
|
||||
finish()
|
||||
revealHint()
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
showAuthUrl (url) {
|
||||
if (!url) {
|
||||
this.authWrapperTarget.classList.add("hidden")
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<h2 class="mb-2 text-xl font-bold text-gray-900">Remote signer</h2>
|
||||
|
||||
<p class="mb-6 text-gray-600">
|
||||
Open your Nostr signer app and scan the QR code, or copy the connection URL
|
||||
and paste it in your signer app.
|
||||
Open your Nostr signer app on this device, or scan the QR code or copy the
|
||||
connection URL to use a signer on another device.
|
||||
</p>
|
||||
|
||||
<%= render NostrSignerConnectComponent.new(
|
||||
|
||||
@@ -53,6 +53,14 @@ 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")
|
||||
|
||||
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")
|
||||
expect(rendered.css("[data-nostr-signer-connect-target='signerHint']").any?).to be(true)
|
||||
|
||||
expect(rendered.css("p.text-sm")).to be_empty
|
||||
expect(rendered.css("button.btn-sm")).to be_empty
|
||||
expect(rendered.css("p.text-base").any?).to be(true)
|
||||
@@ -100,6 +108,7 @@ RSpec.describe NostrSignerConnectComponent, type: :component do
|
||||
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("a[data-action='nostr-signer-connect#openSigner']").any?).to be(true)
|
||||
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
|
||||
@@ -122,5 +131,10 @@ RSpec.describe NostrSignerConnectComponent, type: :component do
|
||||
|
||||
expect(rendered.text).to include("Connect remote signer")
|
||||
expect(rendered.text).to include("Already have a bunker:// URI?")
|
||||
|
||||
connect = rendered.css("button, input[type=submit]").find do |node|
|
||||
node.text.strip == "Connect remote signer" || node["value"] == "Connect remote signer"
|
||||
end
|
||||
expect(connect["class"]).to include("btn-gray")
|
||||
end
|
||||
end
|
||||
@@ -39,6 +39,9 @@ RSpec.describe "Users::NostrConnects", type: :request do
|
||||
expect(html.at_css("h1").text.strip).to eq("Log in")
|
||||
expect(html.at_css("h2").text.strip).to eq("Remote signer")
|
||||
expect(html.css("h4").map { |node| node.text.strip }).not_to include("Remote signer")
|
||||
|
||||
open_link = html.css("a[data-action='nostr-signer-connect#openSigner']").first
|
||||
expect(open_link["href"]).to start_with("nostrconnect://")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user