feat(nostr): Add Nostr relay connection and status management

- Integrate nostr-tools for Nostr relay connectivity
- Create NostrClient for managing relay connections
- Implement useNostr composable for reactive connection handling
- Add ConnectionStatus component to display relay connection state
- Configure environment variable for Nostr relay endpoints
- Update App.vue to manage Nostr connection lifecycle
This commit is contained in:
padreug 2025-03-09 14:27:51 +01:00
parent 6a5b64a382
commit 2a83972b47
7 changed files with 244 additions and 2 deletions

View file

@ -0,0 +1,32 @@
import { ref } from 'vue'
import { NostrClient, type NostrClientConfig } from '@/lib/nostr/client'
export function useNostr(config: NostrClientConfig) {
const client = new NostrClient(config)
const isConnected = ref(false)
const error = ref<Error | null>(null)
async function connect() {
try {
error.value = null
await client.connect()
isConnected.value = client.isConnected
} catch (err) {
error.value = err instanceof Error ? err : new Error('Failed to connect')
isConnected.value = false
}
}
function disconnect() {
client.disconnect()
isConnected.value = false
error.value = null
}
return {
isConnected,
error,
connect,
disconnect
}
}