mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 08:47:23 +00:00
Moves NWC wallet connection (useNWC, NWCContext, WalletModal) along with the WebLN wallet detection (useWallet) and NIP-57 zap stack (useZaps, ZapButton, ZapDialog) out of src/ and into .agents/skills/nwc/ as an opt-in skill. Removes NWCProvider from App.tsx and TestApp.tsx, drops the NWC-only dependencies (@getalby/sdk, @webbtc/webln-types) from package.json, and updates AGENTS.md to stop referencing the extracted hooks and components. The new SKILL.md explains how to reinstall the dependencies, copy the files back into src/, and wire up NWCProvider when a project actually needs Lightning wallet and zap functionality.
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { useNWC } from '@/hooks/useNWCContext';
|
|
import type { WebLNProvider } from '@webbtc/webln-types';
|
|
|
|
export interface WalletStatus {
|
|
hasNWC: boolean;
|
|
webln: WebLNProvider | null;
|
|
activeNWC: ReturnType<typeof useNWC>['getActiveConnection'] extends () => infer T ? T : null;
|
|
preferredMethod: 'nwc' | 'webln' | 'manual';
|
|
}
|
|
|
|
export function useWallet() {
|
|
const { connections, getActiveConnection } = useNWC();
|
|
|
|
// Get the active connection directly - no memoization to avoid stale state
|
|
const activeNWC = getActiveConnection();
|
|
|
|
// Access WebLN directly from browser global scope
|
|
const webln = (globalThis as { webln?: WebLNProvider }).webln || null;
|
|
|
|
// Calculate status values reactively
|
|
const hasNWC = useMemo(() => {
|
|
return connections.length > 0 && connections.some(c => c.isConnected);
|
|
}, [connections]);
|
|
|
|
// Determine preferred payment method
|
|
const preferredMethod: WalletStatus['preferredMethod'] = activeNWC
|
|
? 'nwc'
|
|
: webln
|
|
? 'webln'
|
|
: 'manual';
|
|
|
|
const status: WalletStatus = {
|
|
hasNWC,
|
|
webln,
|
|
activeNWC,
|
|
preferredMethod,
|
|
};
|
|
|
|
return status;
|
|
} |