Fetches and sets default currency for expenses
Ensures the expense form defaults to the LNbits instance's configured currency. This change retrieves the default currency from the LNbits API and sets it as the initial value in the expense form. If no default is configured, it falls back to the first available currency or EUR.
This commit is contained in:
parent
8dad92f0e5
commit
f6ecbc8faf
2 changed files with 34 additions and 2 deletions
|
|
@ -228,4 +228,26 @@ export class ExpensesAPI extends BaseService {
|
|||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default currency from LNbits instance
|
||||
*/
|
||||
async getDefaultCurrency(): Promise<string | null> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/api/v1/default-currency`, {
|
||||
method: 'GET',
|
||||
signal: AbortSignal.timeout(this.config?.apiConfig?.timeout || 30000)
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch default currency: ${response.statusText}`)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return data.default_currency
|
||||
} catch (error) {
|
||||
console.error('[ExpensesAPI] Error fetching default currency:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue