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:
parent
6a5b64a382
commit
2a83972b47
7 changed files with 244 additions and 2 deletions
32
src/composables/useNostr.ts
Normal file
32
src/composables/useNostr.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue