diff --git a/static/js/index.js b/static/js/index.js index ade58c9..564d131 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -39,10 +39,12 @@ window.app = Vue.createApp({ return 'Amount (sats) *' }, currencyOptions() { + console.log('Computing currencyOptions, this.currencies:', this.currencies) const options = [{label: 'Satoshis (default)', value: null}] this.currencies.forEach(curr => { options.push({label: curr, value: curr}) }) + console.log('Currency options:', options) return options } }, @@ -90,8 +92,12 @@ window.app = Vue.createApp({ '/castle/api/v1/currencies', this.g.user.wallets[0].inkey ) + console.log('Currencies API response:', response) + console.log('Currencies data:', response.data) this.currencies = response.data + console.log('this.currencies:', this.currencies) } catch (error) { + console.error('Error loading currencies:', error) LNbits.utils.notifyApiError(error) } }, diff --git a/views_api.py b/views_api.py index 588bd5f..ceacbb5 100644 --- a/views_api.py +++ b/views_api.py @@ -32,13 +32,13 @@ from .models import ( UserBalance, ) -castle_api_router = APIRouter(prefix="/api/v1", tags=["castle"]) +castle_api_router = APIRouter() # ===== UTILITY ENDPOINTS ===== -@castle_api_router.get("/currencies") +@castle_api_router.get("/api/v1/currencies") async def api_get_currencies() -> list[str]: """Get list of allowed currencies for fiat conversion""" return allowed_currencies() @@ -47,13 +47,13 @@ async def api_get_currencies() -> list[str]: # ===== ACCOUNT ENDPOINTS ===== -@castle_api_router.get("/accounts") +@castle_api_router.get("/api/v1/accounts") async def api_get_accounts() -> list[Account]: """Get all accounts in the chart of accounts""" return await get_all_accounts() -@castle_api_router.post("/accounts", status_code=HTTPStatus.CREATED) +@castle_api_router.post("/api/v1/accounts", status_code=HTTPStatus.CREATED) async def api_create_account( data: CreateAccount, wallet: WalletTypeInfo = Depends(require_admin_key), @@ -62,7 +62,7 @@ async def api_create_account( return await create_account(data) -@castle_api_router.get("/accounts/{account_id}") +@castle_api_router.get("/api/v1/accounts/{account_id}") async def api_get_account(account_id: str) -> Account: """Get a specific account""" account = await get_account(account_id) @@ -73,14 +73,14 @@ async def api_get_account(account_id: str) -> Account: return account -@castle_api_router.get("/accounts/{account_id}/balance") +@castle_api_router.get("/api/v1/accounts/{account_id}/balance") async def api_get_account_balance(account_id: str) -> dict: """Get account balance""" balance = await get_account_balance(account_id) return {"account_id": account_id, "balance": balance} -@castle_api_router.get("/accounts/{account_id}/transactions") +@castle_api_router.get("/api/v1/accounts/{account_id}/transactions") async def api_get_account_transactions(account_id: str, limit: int = 100) -> list[dict]: """Get all transactions for an account""" transactions = await get_account_transactions(account_id, limit) @@ -96,13 +96,13 @@ async def api_get_account_transactions(account_id: str, limit: int = 100) -> lis # ===== JOURNAL ENTRY ENDPOINTS ===== -@castle_api_router.get("/entries") +@castle_api_router.get("/api/v1/entries") async def api_get_journal_entries(limit: int = 100) -> list[JournalEntry]: """Get all journal entries""" return await get_all_journal_entries(limit) -@castle_api_router.get("/entries/user") +@castle_api_router.get("/api/v1/entries/user") async def api_get_user_entries( wallet: WalletTypeInfo = Depends(require_invoice_key), limit: int = 100, @@ -111,7 +111,7 @@ async def api_get_user_entries( return await get_journal_entries_by_user(wallet.wallet.id, limit) -@castle_api_router.get("/entries/{entry_id}") +@castle_api_router.get("/api/v1/entries/{entry_id}") async def api_get_journal_entry(entry_id: str) -> JournalEntry: """Get a specific journal entry""" entry = await get_journal_entry(entry_id) @@ -122,7 +122,7 @@ async def api_get_journal_entry(entry_id: str) -> JournalEntry: return entry -@castle_api_router.post("/entries", status_code=HTTPStatus.CREATED) +@castle_api_router.post("/api/v1/entries", status_code=HTTPStatus.CREATED) async def api_create_journal_entry( data: CreateJournalEntry, wallet: WalletTypeInfo = Depends(require_invoice_key), @@ -137,7 +137,7 @@ async def api_create_journal_entry( # ===== SIMPLIFIED ENTRY ENDPOINTS ===== -@castle_api_router.post("/entries/expense", status_code=HTTPStatus.CREATED) +@castle_api_router.post("/api/v1/entries/expense", status_code=HTTPStatus.CREATED) async def api_create_expense_entry( data: ExpenseEntry, wallet: WalletTypeInfo = Depends(require_invoice_key), @@ -222,7 +222,7 @@ async def api_create_expense_entry( return await create_journal_entry(entry_data, wallet.wallet.id) -@castle_api_router.post("/entries/receivable", status_code=HTTPStatus.CREATED) +@castle_api_router.post("/api/v1/entries/receivable", status_code=HTTPStatus.CREATED) async def api_create_receivable_entry( data: ReceivableEntry, wallet: WalletTypeInfo = Depends(require_admin_key), @@ -270,7 +270,7 @@ async def api_create_receivable_entry( return await create_journal_entry(entry_data, wallet.wallet.id) -@castle_api_router.post("/entries/revenue", status_code=HTTPStatus.CREATED) +@castle_api_router.post("/api/v1/entries/revenue", status_code=HTTPStatus.CREATED) async def api_create_revenue_entry( data: RevenueEntry, wallet: WalletTypeInfo = Depends(require_admin_key), @@ -326,7 +326,7 @@ async def api_create_revenue_entry( # ===== USER BALANCE ENDPOINTS ===== -@castle_api_router.get("/balance") +@castle_api_router.get("/api/v1/balance") async def api_get_my_balance( wallet: WalletTypeInfo = Depends(require_invoice_key), ) -> UserBalance: @@ -334,7 +334,7 @@ async def api_get_my_balance( return await get_user_balance(wallet.wallet.id) -@castle_api_router.get("/balance/{user_id}") +@castle_api_router.get("/api/v1/balance/{user_id}") async def api_get_user_balance(user_id: str) -> UserBalance: """Get a specific user's balance with the Castle""" return await get_user_balance(user_id) @@ -343,7 +343,7 @@ async def api_get_user_balance(user_id: str) -> UserBalance: # ===== PAYMENT ENDPOINTS ===== -@castle_api_router.post("/pay-balance") +@castle_api_router.post("/api/v1/pay-balance") async def api_pay_balance( amount: int, wallet: WalletTypeInfo = Depends(require_invoice_key), @@ -398,7 +398,7 @@ async def api_pay_balance( } -@castle_api_router.post("/pay-user") +@castle_api_router.post("/api/v1/pay-user") async def api_pay_user( user_id: str, amount: int,