From b7db9bba5af38160d948ee4003492d7ed95eda20 Mon Sep 17 00:00:00 2001 From: padreug Date: Tue, 6 Jan 2026 18:48:05 +0100 Subject: [PATCH] Fetch available currencies from LNbits core API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Call /api/v1/currencies endpoint on LNbits core (not nostrmarket extension) - Ensure 'sat' is always first in the currency list and used as default - Add loading state for currency dropdown - Add key prop to Select component for proper reactivity 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../market/components/CreateStoreDialog.vue | 27 ++++++++++++-- src/modules/market/services/nostrmarketAPI.ts | 37 +++++++++++-------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/modules/market/components/CreateStoreDialog.vue b/src/modules/market/components/CreateStoreDialog.vue index 613c005..78ef1b3 100644 --- a/src/modules/market/components/CreateStoreDialog.vue +++ b/src/modules/market/components/CreateStoreDialog.vue @@ -47,10 +47,14 @@ Currency * - - + @@ -275,6 +279,7 @@ const toast = useToast() // Local state const isCreating = ref(false) const createError = ref(null) +const isLoadingCurrencies = ref(false) const availableCurrencies = ref(['sat']) const availableZones = ref([]) const showNewZoneForm = ref(false) @@ -331,11 +336,27 @@ const onSubmit = form.handleSubmit(async (values) => { // Methods const loadAvailableCurrencies = async () => { + isLoadingCurrencies.value = true try { const currencies = await nostrmarketAPI.getCurrencies() - availableCurrencies.value = currencies + if (currencies.length > 0) { + // Ensure 'sat' is always first in the list + const satIndex = currencies.indexOf('sat') + if (satIndex === -1) { + // Add 'sat' at the beginning if not present + availableCurrencies.value = ['sat', ...currencies] + } else if (satIndex > 0) { + // Move 'sat' to the beginning if present but not first + const withoutSat = currencies.filter(c => c !== 'sat') + availableCurrencies.value = ['sat', ...withoutSat] + } else { + availableCurrencies.value = currencies + } + } } catch (error) { console.error('Failed to load currencies:', error) + } finally { + isLoadingCurrencies.value = false } } diff --git a/src/modules/market/services/nostrmarketAPI.ts b/src/modules/market/services/nostrmarketAPI.ts index 4913aa0..60e1fc4 100644 --- a/src/modules/market/services/nostrmarketAPI.ts +++ b/src/modules/market/services/nostrmarketAPI.ts @@ -371,30 +371,35 @@ export class NostrmarketAPI extends BaseService { } /** - * Get available currencies + * Get available currencies from the LNbits core API + * This endpoint returns currencies allowed by the server configuration */ async getCurrencies(): Promise { - const baseCurrencies = ['sat'] + // Call the LNbits core API directly (not under /nostrmarket) + const url = `${this.baseUrl}/api/v1/currencies` try { - const apiCurrencies = await this.request( - '/api/v1/currencies', - '', // No authentication needed for currencies endpoint - { method: 'GET' } - ) + const response = await fetch(url, { + method: 'GET', + headers: { 'Content-Type': 'application/json' } + }) - if (apiCurrencies && Array.isArray(apiCurrencies)) { - // Combine base currencies with API currencies, removing duplicates - const allCurrencies = [...baseCurrencies, ...apiCurrencies.filter(currency => !baseCurrencies.includes(currency))] - this.debug('Retrieved currencies:', { count: allCurrencies.length, currencies: allCurrencies }) - return allCurrencies + if (!response.ok) { + throw new Error(`Failed to fetch currencies: ${response.status}`) } - this.debug('No API currencies returned, using base currencies only') - return baseCurrencies + const apiCurrencies = await response.json() + + if (apiCurrencies && Array.isArray(apiCurrencies)) { + this.debug('Retrieved currencies from LNbits core:', { count: apiCurrencies.length, currencies: apiCurrencies }) + return apiCurrencies + } + + this.debug('No currencies returned from server, using default') + return ['sat'] } catch (error) { - this.debug('Failed to get currencies, falling back to base currencies:', error) - return baseCurrencies + this.debug('Failed to get currencies, using default:', error) + return ['sat'] } }