mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 00:37:23 +00:00
Remove webln from state, simplify webln detection.
This commit is contained in:
1 parent
45cdcecf9e
commit
b77885093c
4 files changed
+18
-24
No files matched your search
@@ -68,7 +68,7 @@ AddWalletContent.displayName = 'AddWalletContent';
|
|||||||
|
|
||||||
// Extracted WalletContent to prevent re-renders
|
// Extracted WalletContent to prevent re-renders
|
||||||
const WalletContent = forwardRef<HTMLDivElement, {
|
const WalletContent = forwardRef<HTMLDivElement, {
|
||||||
hasWebLN: boolean;
|
webln: import('@webbtc/webln-types').WebLNProvider | null;
|
||||||
hasNWC: boolean;
|
hasNWC: boolean;
|
||||||
connections: NWCConnection[];
|
connections: NWCConnection[];
|
||||||
connectionInfo: Record<string, NWCInfo>;
|
connectionInfo: Record<string, NWCInfo>;
|
||||||
@@ -77,7 +77,7 @@ const WalletContent = forwardRef<HTMLDivElement, {
|
|||||||
handleRemoveConnection: (cs: string) => void;
|
handleRemoveConnection: (cs: string) => void;
|
||||||
setAddDialogOpen: (open: boolean) => void;
|
setAddDialogOpen: (open: boolean) => void;
|
||||||
}>(({
|
}>(({
|
||||||
hasWebLN,
|
webln,
|
||||||
hasNWC,
|
hasNWC,
|
||||||
connections,
|
connections,
|
||||||
connectionInfo,
|
connectionInfo,
|
||||||
@@ -101,9 +101,9 @@ const WalletContent = forwardRef<HTMLDivElement, {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{hasWebLN && <CheckCircle className="h-4 w-4 text-green-600" />}
|
{webln && <CheckCircle className="h-4 w-4 text-green-600" />}
|
||||||
<Badge variant={hasWebLN ? "default" : "secondary"} className="text-xs">
|
<Badge variant={webln ? "default" : "secondary"} className="text-xs">
|
||||||
{hasWebLN ? "Ready" : "Not Found"}
|
{webln ? "Ready" : "Not Found"}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -189,7 +189,7 @@ const WalletContent = forwardRef<HTMLDivElement, {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{/* Help */}
|
{/* Help */}
|
||||||
{!hasWebLN && connections.length === 0 && (
|
{!webln && connections.length === 0 && (
|
||||||
<>
|
<>
|
||||||
<Separator />
|
<Separator />
|
||||||
<div className="text-center py-4 space-y-2">
|
<div className="text-center py-4 space-y-2">
|
||||||
@@ -220,7 +220,7 @@ export function WalletModal({ children, className }: WalletModalProps) {
|
|||||||
setActiveConnection
|
setActiveConnection
|
||||||
} = useNWC();
|
} = useNWC();
|
||||||
|
|
||||||
const { hasWebLN } = useWallet();
|
const { webln } = useWallet();
|
||||||
|
|
||||||
const hasNWC = connections.length > 0 && connections.some(c => c.isConnected);
|
const hasNWC = connections.length > 0 && connections.some(c => c.isConnected);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@@ -261,7 +261,7 @@ export function WalletModal({ children, className }: WalletModalProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const walletContentProps = {
|
const walletContentProps = {
|
||||||
hasWebLN,
|
webln,
|
||||||
hasNWC,
|
hasNWC,
|
||||||
connections,
|
connections,
|
||||||
connectionInfo,
|
connectionInfo,
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ interface ZapContentProps {
|
|||||||
isZapping: boolean;
|
isZapping: boolean;
|
||||||
qrCodeUrl: string;
|
qrCodeUrl: string;
|
||||||
copied: boolean;
|
copied: boolean;
|
||||||
hasWebLN: boolean;
|
webln: import('@webbtc/webln-types').WebLNProvider | null;
|
||||||
handleZap: () => void;
|
handleZap: () => void;
|
||||||
handleCopy: () => void;
|
handleCopy: () => void;
|
||||||
openInWallet: () => void;
|
openInWallet: () => void;
|
||||||
@@ -73,7 +73,7 @@ const ZapContent = forwardRef<HTMLDivElement, ZapContentProps>(({
|
|||||||
isZapping,
|
isZapping,
|
||||||
qrCodeUrl,
|
qrCodeUrl,
|
||||||
copied,
|
copied,
|
||||||
hasWebLN,
|
webln,
|
||||||
handleZap,
|
handleZap,
|
||||||
handleCopy,
|
handleCopy,
|
||||||
openInWallet,
|
openInWallet,
|
||||||
@@ -138,7 +138,7 @@ const ZapContent = forwardRef<HTMLDivElement, ZapContentProps>(({
|
|||||||
|
|
||||||
{/* Payment buttons */}
|
{/* Payment buttons */}
|
||||||
<div className="space-y-3 mt-4">
|
<div className="space-y-3 mt-4">
|
||||||
{hasWebLN && (
|
{webln && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const finalAmount = typeof amount === 'string' ? parseInt(amount, 10) : amount;
|
const finalAmount = typeof amount === 'string' ? parseInt(amount, 10) : amount;
|
||||||
@@ -239,7 +239,7 @@ export function ZapDialog({ target, children, className }: ZapDialogProps) {
|
|||||||
const { user } = useCurrentUser();
|
const { user } = useCurrentUser();
|
||||||
const { data: author } = useAuthor(target.pubkey);
|
const { data: author } = useAuthor(target.pubkey);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { webln, activeNWC, hasWebLN } = useWallet();
|
const { webln, activeNWC } = useWallet();
|
||||||
const { zap, isZapping, invoice, setInvoice } = useZaps(target, webln, activeNWC, () => setOpen(false));
|
const { zap, isZapping, invoice, setInvoice } = useZaps(target, webln, activeNWC, () => setOpen(false));
|
||||||
const [amount, setAmount] = useState<number | string>(100);
|
const [amount, setAmount] = useState<number | string>(100);
|
||||||
const [comment, setComment] = useState<string>('');
|
const [comment, setComment] = useState<string>('');
|
||||||
@@ -337,7 +337,7 @@ export function ZapDialog({ target, children, className }: ZapDialogProps) {
|
|||||||
isZapping,
|
isZapping,
|
||||||
qrCodeUrl,
|
qrCodeUrl,
|
||||||
copied,
|
copied,
|
||||||
hasWebLN,
|
webln,
|
||||||
handleZap,
|
handleZap,
|
||||||
handleCopy,
|
handleCopy,
|
||||||
openInWallet,
|
openInWallet,
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ async function handleAPIError(response: Response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error(`Invalid request: ${error.error?.message || error.details || error.error || 'Please check your request parameters.'}`);
|
throw new Error(`Invalid request: ${error.error?.message || error.details || error.error || 'Please check your request parameters.'}`);
|
||||||
} catch (parseError) {
|
} catch {
|
||||||
throw new Error('Invalid request. Please check your parameters and try again.');
|
throw new Error('Invalid request. Please check your parameters and try again.');
|
||||||
}
|
}
|
||||||
} else if (response.status === 404) {
|
} else if (response.status === 404) {
|
||||||
@@ -133,7 +133,7 @@ async function handleAPIError(response: Response) {
|
|||||||
try {
|
try {
|
||||||
const errorData = await response.json();
|
const errorData = await response.json();
|
||||||
throw new Error(`API error: ${errorData.error?.message || errorData.details || errorData.error || response.statusText}`);
|
throw new Error(`API error: ${errorData.error?.message || errorData.details || errorData.error || response.statusText}`);
|
||||||
} catch (parseError) {
|
} catch {
|
||||||
throw new Error(`Network error: ${response.statusText}. Please check your connection and try again.`);
|
throw new Error(`Network error: ${response.statusText}. Please check your connection and try again.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { useState, useEffect, useCallback, useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useNWC } from '@/hooks/useNWCContext';
|
import { useNWC } from '@/hooks/useNWCContext';
|
||||||
import type { WebLNProvider } from '@webbtc/webln-types';
|
import type { WebLNProvider } from '@webbtc/webln-types';
|
||||||
|
|
||||||
export interface WalletStatus {
|
export interface WalletStatus {
|
||||||
hasWebLN: boolean;
|
|
||||||
hasNWC: boolean;
|
hasNWC: boolean;
|
||||||
webln: WebLNProvider | null;
|
webln: WebLNProvider | null;
|
||||||
activeNWC: ReturnType<typeof useNWC>['getActiveConnection'] extends () => infer T ? T : null;
|
activeNWC: ReturnType<typeof useNWC>['getActiveConnection'] extends () => infer T ? T : null;
|
||||||
@@ -11,17 +10,13 @@ export interface WalletStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useWallet() {
|
export function useWallet() {
|
||||||
const [webln, setWebln] = useState<WebLNProvider | null>(null);
|
|
||||||
const { connections, getActiveConnection } = useNWC();
|
const { connections, getActiveConnection } = useNWC();
|
||||||
|
|
||||||
// Get the active connection directly - no memoization to avoid stale state
|
// Get the active connection directly - no memoization to avoid stale state
|
||||||
const activeNWC = getActiveConnection();
|
const activeNWC = getActiveConnection();
|
||||||
|
|
||||||
// Detect WebLN synchronously on mount
|
// Access WebLN directly from browser global scope
|
||||||
useEffect(() => {
|
const webln = (globalThis as { webln?: WebLNProvider }).webln || null;
|
||||||
const webLn = (globalThis as { webln?: WebLNProvider }).webln;
|
|
||||||
setWebln(webLn || null);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Calculate status values reactively
|
// Calculate status values reactively
|
||||||
const hasNWC = useMemo(() => {
|
const hasNWC = useMemo(() => {
|
||||||
@@ -36,7 +31,6 @@ export function useWallet() {
|
|||||||
: 'manual';
|
: 'manual';
|
||||||
|
|
||||||
const status: WalletStatus = {
|
const status: WalletStatus = {
|
||||||
hasWebLN: !!webln,
|
|
||||||
hasNWC,
|
hasNWC,
|
||||||
webln,
|
webln,
|
||||||
activeNWC,
|
activeNWC,
|
||||||
|
|||||||
Reference in new issue
Block a user