POWR/lib/hooks/useNDK.ts
DocNR 8e68fcf60f Fix Android Amber signer integration and cleanup repo structure
- Added Amber external signer integration for secure private key management on Android

- Fixed authentication issues and NIP-55 protocol implementation

- Added comprehensive documentation in amber-integration-fixes.md

- Moved android_backup to external location to keep repo clean

- Updated .gitignore to exclude APK files
2025-04-01 00:03:41 -04:00

78 lines
1.7 KiB
TypeScript

import { useEffect } from 'react';
import { useNDKStore } from '@/lib/stores/ndk';
import type { NDKUser, NDKEvent, NDKFilter } from '@nostr-dev-kit/ndk-mobile';
// Core hook for NDK access
export function useNDK() {
const { ndk, isLoading, error, init } = useNDKStore(state => ({
ndk: state.ndk,
isLoading: state.isLoading,
error: state.error,
init: state.init
}));
useEffect(() => {
if (!ndk && !isLoading) {
init();
}
}, [ndk, isLoading, init]);
return { ndk, isLoading, error };
}
// Hook for current user info
export function useNDKCurrentUser() {
const { currentUser, isAuthenticated, isLoading } = useNDKStore(state => ({
currentUser: state.currentUser,
isAuthenticated: state.isAuthenticated,
isLoading: state.isLoading
}));
return {
currentUser,
isAuthenticated,
isLoading
};
}
// Hook for authentication actions
export function useNDKAuth() {
const {
login,
loginWithExternalSigner,
logout,
generateKeys,
isAuthenticated,
isLoading
} = useNDKStore(state => ({
login: state.login,
loginWithExternalSigner: state.loginWithExternalSigner,
logout: state.logout,
generateKeys: state.generateKeys,
isAuthenticated: state.isAuthenticated,
isLoading: state.isLoading
}));
return {
login,
loginWithExternalSigner,
logout,
generateKeys,
isAuthenticated,
isLoading
};
}
// New hook for event operations
export function useNDKEvents() {
const { publishEvent, fetchEventsByFilter } = useNDKStore(state => ({
publishEvent: state.publishEvent,
fetchEventsByFilter: state.fetchEventsByFilter
}));
return {
publishEvent,
fetchEventsByFilter
};
}