diff --git a/crates/browser-signer-proxy/index.html b/crates/browser-signer-proxy/index.html index 2b81b30..1b5c3a2 100644 --- a/crates/browser-signer-proxy/index.html +++ b/crates/browser-signer-proxy/index.html @@ -1,44 +1,189 @@ - - NIP-07 Proxy - - - - -
-

NIP-07 Proxy

-

This page acts

as a proxy between your native application and the NIP-07 browser extension.

-
- Status: Checking... -
-

Keep this tab open while using your application. The page will automatically poll for requests from your native app.

+ + + + Coop — Web Signer Proxy + + + + + + +
+ - - +

Web Signer

+

+ This page connects the app to your Nostr Web Signer extension so you can sign in and use Coop securely. +

+ +
+
+ Checking extension… +
+ +
+ Keep this tab open while using the app — it automatically handles sign-in requests in the background. +
+
+ + + diff --git a/crates/browser-signer-proxy/proxy.js b/crates/browser-signer-proxy/proxy.js index ecb96a4..f04465b 100644 --- a/crates/browser-signer-proxy/proxy.js +++ b/crates/browser-signer-proxy/proxy.js @@ -129,13 +129,12 @@ async function handleNip07Request(request) { } } -function updateStatus(message, status) { - const statusEl = document.getElementById('nip07-proxy-status'); - if (statusEl) { - statusEl.textContent = message; - statusEl.style = status === "connected" ? - "color: green; font-weight: bold;" : - "color: red; font-weight: bold;"; +function updateStatus(message, state) { + const container = document.getElementById('nip07-status'); + const textEl = document.getElementById('nip07-status-text'); + if (container && textEl) { + container.className = 'status status--' + state; + textEl.textContent = message; } } @@ -146,10 +145,10 @@ window.addEventListener('load', () => { // Check if NIP-07 extension is available if (window.nostr) { console.log('NIP-07 extension detected'); - updateStatus('Connected to NIP-07 extension - Ready', 'connected'); + updateStatus('Connected — ready', 'connected'); } else { console.log('NIP-07 extension not found'); - updateStatus('NIP-07 extension not found', 'error'); + updateStatus('No NIP-07 extension found', 'error'); } // Start polling every 500 ms diff --git a/crates/state/Cargo.toml b/crates/state/Cargo.toml index 5f1d824..fee518b 100644 --- a/crates/state/Cargo.toml +++ b/crates/state/Cargo.toml @@ -12,7 +12,6 @@ nostr-sdk.workspace = true nostr-gossip-memory.workspace = true nostr-blossom.workspace = true nostr-connect.workspace = true -browser-signer-proxy = { path = "../browser-signer-proxy" } gpui.workspace = true instant.workspace = true @@ -29,6 +28,7 @@ mime_guess = "2.0.4" nostr-memory.workspace = true [target.'cfg(not(target_arch = "wasm32"))'.dependencies] +browser-signer-proxy = { path = "../browser-signer-proxy" } nostr-lmdb.workspace = true smol.workspace = true gpui_tokio.workspace = true diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index e33c3e0..23fa04a 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use anyhow::{Error, anyhow}; +#[cfg(not(target_arch = "wasm32"))] use browser_signer_proxy::prelude::*; use common::config_dir; use gpui::{App, AppContext, Context, Entity, EventEmitter, Global, Task, Window}; @@ -265,6 +266,7 @@ impl NostrRegistry { cx.notify(); })?; } else if content == "proxy" { + #[cfg(not(target_arch = "wasm32"))] this.update(cx, |this, cx| { this.connect_proxy(cx); })?; @@ -314,6 +316,7 @@ impl NostrRegistry { } /// Start the browser proxy + #[cfg(not(target_arch = "wasm32"))] pub fn connect_proxy(&mut self, cx: &mut Context) { let proxy = BrowserSignerProxy::new(BrowserSignerProxyOptions::default()); let (tx, rx) = flume::bounded::(1); diff --git a/crates/workspace/src/dialogs/import.rs b/crates/workspace/src/dialogs/import.rs index b6fcb24..cb41d76 100644 --- a/crates/workspace/src/dialogs/import.rs +++ b/crates/workspace/src/dialogs/import.rs @@ -164,6 +164,7 @@ impl ImportIdentity { })); } + #[cfg(not(target_arch = "wasm32"))] fn proxy(&mut self, cx: &mut Context) { let nostr = NostrRegistry::global(cx); nostr.update(cx, |this, cx| { @@ -209,6 +210,7 @@ impl Render for ImportIdentity { const BUNKER_WARN: &str = "Nostr Connect will usually take more time to get all your messages. Please keep your session open until you see all your messages."; const KEY_WARN: &str = "Coop won't store your identity key on the local device. You need to re-login again in the next session. You can use Nostr Connect for persistent login."; + let is_wasm = cfg!(target_arch = "wasm32"); let require_password = self.key_input.read(cx).value().starts_with("ncryptsec1"); let key_warning = self.key_input.read(cx).value().starts_with("nsec1") || require_password; let bunker_warning = self.key_input.read(cx).value().starts_with("bunker://"); @@ -265,16 +267,18 @@ impl Render for ImportIdentity { })), ) .child(divider(cx)) - .child( - Button::new("proxy") - .label("Connect via Web Extension (Experimental)") - .ghost_alt() - .loading(self.loading) - .disabled(self.loading) - .on_click(cx.listener(move |this, _ev, _window, cx| { - this.proxy(cx); - })), - ) + .when(!is_wasm, |this| { + this.child( + Button::new("proxy") + .label("Connect via Web Extension (Experimental)") + .ghost_alt() + .loading(self.loading) + .disabled(self.loading) + .on_click(cx.listener(move |this, _ev, _window, cx| { + this.proxy(cx); + })), + ) + }) .when_some(self.error.read(cx).as_ref(), |this, error| { this.child( div()