POWR/lib/hooks/useNDK.ts
DocNR c64ca8bf19 fix: profile stats loading and display issues on iOS and Android
- Enhanced NostrBandService with aggressive cache-busting and better error handling
- Improved useProfileStats hook with optimized refresh settings and platform-specific logging
- Fixed ProfileFollowerStats UI to show actual values with loading indicators
- Added visual feedback during refresh operations
- Updated CHANGELOG.md to document these improvements

This resolves the issue where follower/following counts were not updating properly
on Android and iOS platforms.
2025-04-04 15:46:31 -04:00

73 lines
1.7 KiB
TypeScript

import { useContext } from 'react';
import { NDKContext } from '@/lib/auth/ReactQueryAuthProvider';
import { useNDKStore } from '@/lib/stores/ndk';
import type { NDKUser, NDKEvent, NDKFilter } from '@nostr-dev-kit/ndk-mobile';
// Core hook for NDK access
// Uses the context from ReactQueryAuthProvider rather than Zustand store
export function useNDK() {
const { ndk, isInitialized } = useContext(NDKContext);
return {
ndk,
isLoading: !isInitialized,
error: !ndk && isInitialized ? new Error('NDK initialization failed') : undefined
};
}
// 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
};
}