fix: mobile nostr signer detection, mobile TTS auto-unlock, button loaders

- Nostr signer: poll for window.nostr up to 3s on mobile (Amber injects
  late). Both login() and handleSignerLogin() now wait before failing.
- Mobile TTS: install global one-time click/touch/keydown handler to
  auto-unlock AudioContext when fight pages mount. Previously only
  triggered by explicit sound toggle, so mobile TTS silently failed.
- Add loading spinners to "I BUILD BOTS" and "I FIGHT MYSELF" buttons.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 14:44:38 +00:00
co-authored by Claude Opus 4.6
parent 4897335686
commit dd3cbdae7f
5 changed files with 80 additions and 18 deletions
+22 -6
View File
@@ -112,6 +112,17 @@ export function useNostr() {
const isLoggedIn = computed(() => !!pubkey.value && !!bot.value)
const hasExtension = computed(() => !!window.nostr)
/** Wait for window.nostr to appear (mobile signers inject late) */
async function waitForSigner(timeoutMs = 3000): Promise<boolean> {
if (window.nostr) return true
const start = Date.now()
while (Date.now() - start < timeoutMs) {
await new Promise(r => setTimeout(r, 200))
if (window.nostr) return true
}
return false
}
/**
* Authenticate with the server using NIP-98 signed request.
* Works with NIP-07 extension, Amber signer, or local nsec.
@@ -159,17 +170,21 @@ export function useNostr() {
*/
async function login(): Promise<{ pubkey: string; bot: BotData | null }> {
if (!window.nostr) {
// Fall back to stored nsec if available
const storedNsec = localStorage.getItem('bf_nsec')
if (storedNsec) {
return loginWithNsec(storedNsec)
// Mobile signers (Amber) inject window.nostr late — poll for up to 3s
const found = await waitForSigner(3000)
if (!found) {
// Fall back to stored nsec if available
const storedNsec = localStorage.getItem('bf_nsec')
if (storedNsec) {
return loginWithNsec(storedNsec)
}
throw new Error('No Nostr signer found. Install a browser extension or use "Generate New Identity".')
}
throw new Error('No Nostr signer found. Install a browser extension or use "Generate New Identity".')
}
// Verify extension is responsive
try {
await window.nostr.getPublicKey()
await window.nostr!.getPublicKey()
} catch {
throw new Error('Nostr signer denied access. Approve the request and try again.')
}
@@ -419,6 +434,7 @@ export function useNostr() {
hasExtension,
hasStoredKey,
login,
waitForSigner,
generateLogin,
loginWithNsec,
registerBot,