98 lines
2.6 KiB
TypeScript

/**
* Configuration utilities
* Provides access to Nostr relays, NIP-95 APIs, and platform settings
* All values are stored in IndexedDB with hardcoded defaults
*/
import { configStorage, getPrimaryRelaySync, getPrimaryNip95ApiSync, getPlatformLightningAddressSync } from './configStorage'
/**
* Get primary relay URL
* Uses IndexedDB if available, otherwise returns default
*/
export async function getPrimaryRelay(): Promise<string> {
if (typeof window === 'undefined') {
return getPrimaryRelaySync()
}
try {
return await configStorage.getPrimaryRelay()
} catch (error) {
console.error('Error getting primary relay from IndexedDB:', error)
return getPrimaryRelaySync()
}
}
/**
* Get all enabled relay URLs
* Uses IndexedDB if available, otherwise returns default
*/
export async function getEnabledRelays(): Promise<string[]> {
if (typeof window === 'undefined') {
return [getPrimaryRelaySync()]
}
try {
return await configStorage.getEnabledRelays()
} catch (error) {
console.error('Error getting enabled relays from IndexedDB:', error)
return [getPrimaryRelaySync()]
}
}
/**
* Get primary NIP-95 API URL
* Uses IndexedDB if available, otherwise returns default
*/
export async function getPrimaryNip95Api(): Promise<string> {
if (typeof window === 'undefined') {
return getPrimaryNip95ApiSync()
}
try {
return await configStorage.getPrimaryNip95Api()
} catch (error) {
console.error('Error getting primary NIP-95 API from IndexedDB:', error)
return getPrimaryNip95ApiSync()
}
}
/**
* Get all enabled NIP-95 API URLs
* Uses IndexedDB if available, otherwise returns default
*/
export async function getEnabledNip95Apis(): Promise<string[]> {
if (typeof window === 'undefined') {
return [getPrimaryNip95ApiSync()]
}
try {
return await configStorage.getEnabledNip95Apis()
} catch (error) {
console.error('Error getting enabled NIP-95 APIs from IndexedDB:', error)
return [getPrimaryNip95ApiSync()]
}
}
/**
* Get platform Lightning address
* Uses IndexedDB if available, otherwise returns default
*/
export async function getPlatformLightningAddress(): Promise<string> {
if (typeof window === 'undefined') {
return getPlatformLightningAddressSync()
}
try {
return await configStorage.getPlatformLightningAddress()
} catch (error) {
console.error('Error getting platform Lightning address from IndexedDB:', error)
return getPlatformLightningAddressSync()
}
}
/**
* Re-export synchronous getters from configStorage
*/
export { getPrimaryRelaySync, getPrimaryNip95ApiSync, getPlatformLightningAddressSync } from './configStorage'