- Introduce a new config module to manage Nostr relays, admin pubkeys, and API settings. - Update components to utilize the centralized config instead of environment variables directly. - Refactor relevant files to improve maintainability and reduce reliance on environment variables.
29 lines
No EOL
800 B
TypeScript
29 lines
No EOL
800 B
TypeScript
import type { Event, EventsApiError } from '../types/event'
|
|
import { config } from '@/lib/config'
|
|
|
|
const API_BASE_URL = config.api.baseUrl || 'http://lnbits'
|
|
const API_KEY = config.api.key
|
|
|
|
export async function fetchEvents(allWallets = true): Promise<Event[]> {
|
|
try {
|
|
const response = await fetch(
|
|
`${API_BASE_URL}/events/api/v1/events?all_wallets=${allWallets}`,
|
|
{
|
|
headers: {
|
|
'accept': 'application/json',
|
|
'X-API-KEY': API_KEY,
|
|
},
|
|
}
|
|
)
|
|
|
|
if (!response.ok) {
|
|
const error: EventsApiError = await response.json()
|
|
throw new Error(error.detail[0]?.msg || 'Failed to fetch events')
|
|
}
|
|
|
|
return await response.json() as Event[]
|
|
} catch (error) {
|
|
console.error('Error fetching events:', error)
|
|
throw error
|
|
}
|
|
}
|