web-app/src/composables/useNostr.ts
padreug 236a8a59b9 refactor: Simplify Nostr connection management and enhance store integration
- Refactor useNostr composable to utilize a centralized Pinia store for connection state and client management.
- Update NostrFeed and App components to leverage the new store-based approach for relay configuration and client instantiation.
- Remove direct relay URL handling from components, improving maintainability and consistency across the application.
2025-07-02 19:49:06 +02:00

24 lines
No EOL
618 B
TypeScript

import { storeToRefs } from 'pinia'
import { useNostrStore } from '@/stores/nostr'
import type { NostrClientConfig } from '@/lib/nostr/client'
export function useNostr(config?: NostrClientConfig) {
const store = useNostrStore()
// If custom relays are provided, update the store
if (config?.relays) {
store.setRelayUrls(config.relays)
}
// Return reactive refs from the store
const { isConnected, isConnecting, error } = storeToRefs(store)
return {
isConnected,
isConnecting,
error,
connect: store.connect,
disconnect: store.disconnect,
getClient: store.getClient
}
}