mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 16:33:36 +00:00
Show live progress during the nostrconnect login handshake
When a user tapped "Open signer app", the dialog previously stayed frozen on the same screen — same button, same copy-URI fallback, no feedback — until the login either succeeded (and the dialog dismissed) or timed out after two minutes. With slow or flaky signers (Amber's current listening-REQ bug being the immediate trigger, but any NIP-46 signer that takes more than a second or two to respond hits the same hole) this looked indistinguishable from a hang. Users retapped the button, closed the dialog, gave up. Now the dialog swaps the QR / Open signer app area for a centered spinner with a live status line as the handshake advances: - "Waiting for signer connection…" while the signer app has the user and we're listening on kind 24133 for the connect-ack. - "Getting public key…" once the connect-ack arrives and we're issuing the NIP-46 get_public_key RPC. On mobile the swap happens synchronously when the user taps "Open signer app" so they see the progress state the moment they return from the signer. On desktop the QR stays visible through the awaiting-connect phase (they may still be scanning with a different device) and only swaps in once the signer has acknowledged. The progress view includes a Cancel link that aborts the in-flight subscription and regenerates fresh connect params. Also fix a related effect-lifecycle bug: the listening effect previously depended on `onClose` and `isWaitingForConnect`. Since parents pass inline arrow functions for onClose, the effect re-ran on every parent render and its cleanup flipped a local `cancelled` flag — if the signer's response arrived on a re-rendered instance, the success branch silently swallowed the login. The effect now depends only on `nostrConnectParams` with stable refs for onClose/login, gates the success branch on `controller.signal.aborted` instead of a teardown flag, and handles cancellation explicitly in the dialog-close and retry paths. The handshake phases are surfaced via the new `onStatus` callback on `NLogin.fromNostrConnect` in @nostrify/react 0.6.0. Bumps @nostrify/react to ^0.6.0. Also switches the fallback relay used for NIP-46 communication from wss://relay.damus.io to wss://relay.ditto.pub. Only applies when the user has no writable relays in their metadata. Incidental cleanup while editing the dialog: the Copy URI button and the "Open your signer app to connect." / "Scan with your signer app." caption lines are removed. The primary Open signer app button is self-explanatory on mobile, and the QR on desktop doesn't need a caption.
This commit is contained in:
4 files changed
+127
-65
No files matched your search
@@ -1,10 +1,15 @@
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { NLogin, type NostrConnectParams, useNostrLogin } from '@nostrify/react/login';
|
||||
import {
|
||||
NLogin,
|
||||
type NostrConnectParams,
|
||||
type NostrConnectStatus,
|
||||
useNostrLogin,
|
||||
} from '@nostrify/react/login';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
|
||||
// NOTE: This file should not be edited except for adding new login methods.
|
||||
|
||||
export type { NostrConnectParams };
|
||||
export type { NostrConnectParams, NostrConnectStatus };
|
||||
export { generateNostrConnectParams, generateNostrConnectURI } from '@nostrify/react/login';
|
||||
|
||||
export function useLoginActions() {
|
||||
@@ -29,9 +34,16 @@ export function useLoginActions() {
|
||||
addLogin(login);
|
||||
},
|
||||
// Login via nostrconnect:// (client-initiated NIP-46)
|
||||
// The client displays a QR code and waits for the remote signer to connect
|
||||
async nostrconnect(params: NostrConnectParams, signal?: AbortSignal): Promise<void> {
|
||||
const login = await NLogin.fromNostrConnect(params, nostr, { signal });
|
||||
// The client displays a QR code and waits for the remote signer to connect.
|
||||
//
|
||||
// `onStatus` is forwarded from @nostrify/react so the UI can render
|
||||
// live progress through the handshake phases — see NostrConnectStatus.
|
||||
async nostrconnect(
|
||||
params: NostrConnectParams,
|
||||
signal?: AbortSignal,
|
||||
onStatus?: (status: NostrConnectStatus) => void,
|
||||
): Promise<void> {
|
||||
const login = await NLogin.fromNostrConnect(params, nostr, { signal, onStatus });
|
||||
addLogin(login);
|
||||
},
|
||||
// Get the relay URLs for NIP-46 nostrconnect communication
|
||||
@@ -39,7 +51,7 @@ export function useLoginActions() {
|
||||
const relays = config.relayMetadata.relays
|
||||
.filter((r) => r.write)
|
||||
.map((r) => r.url);
|
||||
return relays.length > 0 ? relays : ['wss://relay.damus.io'];
|
||||
return relays.length > 0 ? relays : ['wss://relay.ditto.pub'];
|
||||
},
|
||||
// Log out the current user
|
||||
async logout(): Promise<void> {
|
||||
|
||||
Reference in new issue
Block a user