Remove webln from state, simplify webln detection.

This commit is contained in:
Chad Curtis committed 2025-10-05 20:59:27 +00:00
1 parent 45cdcecf9e
commit b77885093c
4 files changed
+32 -38

No files matched your search

+3 -9
View File
@@ -1,9 +1,8 @@
import { useState, useEffect, useCallback, useMemo } from 'react';
import { useMemo } from 'react';
import { useNWC } from '@/hooks/useNWCContext';
import type { WebLNProvider } from '@webbtc/webln-types';
export interface WalletStatus {
hasWebLN: boolean;
hasNWC: boolean;
webln: WebLNProvider | null;
activeNWC: ReturnType<typeof useNWC>['getActiveConnection'] extends () => infer T ? T : null;
@@ -11,17 +10,13 @@ export interface WalletStatus {
}
export function useWallet() {
const [webln, setWebln] = useState<WebLNProvider | null>(null);
const { connections, getActiveConnection } = useNWC();
// Get the active connection directly - no memoization to avoid stale state
const activeNWC = getActiveConnection();
// Detect WebLN synchronously on mount
useEffect(() => {
const webLn = (globalThis as { webln?: WebLNProvider }).webln;
setWebln(webLn || null);
}, []);
// Access WebLN directly from browser global scope
const webln = (globalThis as { webln?: WebLNProvider }).webln || null;
// Calculate status values reactively
const hasNWC = useMemo(() => {
@@ -36,7 +31,6 @@ export function useWallet() {
: 'manual';
const status: WalletStatus = {
hasWebLN: !!webln,
hasNWC,
webln,
activeNWC,