initial commit

This commit is contained in:
padreug 2025-10-22 12:33:45 +02:00
commit 95b8af2360
15 changed files with 1519 additions and 0 deletions

1
static/image/castle.png Normal file
View file

@ -0,0 +1 @@
PNG placeholder - In production, convert the SVG to PNG or use an actual image file

12
static/image/castle.svg Normal file
View file

@ -0,0 +1,12 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
<rect x="20" y="35" width="60" height="50" fill="#8B4513" stroke="#000" stroke-width="2"/>
<rect x="35" y="55" width="15" height="30" fill="#654321"/>
<rect x="30" y="30" width="10" height="15" fill="#8B4513" stroke="#000" stroke-width="1"/>
<rect x="60" y="30" width="10" height="15" fill="#8B4513" stroke="#000" stroke-width="1"/>
<rect x="30" y="25" width="10" height="5" fill="#654321"/>
<rect x="60" y="25" width="10" height="5" fill="#654321"/>
<rect x="42" y="20" width="16" height="20" fill="#A0522D" stroke="#000" stroke-width="1"/>
<polygon points="50,15 46,20 54,20" fill="#654321"/>
<circle cx="42" cy="65" r="1.5" fill="#FFD700"/>
<text x="50" y="92" font-family="Arial" font-size="8" text-anchor="middle" fill="#FFD700"></text>
</svg>

After

Width:  |  Height:  |  Size: 860 B

162
static/js/index.js Normal file
View file

@ -0,0 +1,162 @@
const mapJournalEntry = obj => {
return obj
}
window.app = Vue.createApp({
el: '#vue',
mixins: [windowMixin],
data() {
return {
balance: null,
transactions: [],
accounts: [],
expenseDialog: {
show: false,
description: '',
amount: null,
expenseAccount: '',
isEquity: false,
reference: '',
loading: false
},
payDialog: {
show: false,
amount: null,
loading: false
}
}
},
computed: {
expenseAccounts() {
return this.accounts.filter(a => a.account_type === 'expense')
}
},
methods: {
async loadBalance() {
try {
const response = await LNbits.api.request(
'GET',
'/castle/api/v1/balance',
this.g.user.wallets[0].inkey
)
this.balance = response.data
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
async loadTransactions() {
try {
const response = await LNbits.api.request(
'GET',
'/castle/api/v1/entries/user',
this.g.user.wallets[0].inkey
)
this.transactions = response.data
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
async loadAccounts() {
try {
const response = await LNbits.api.request(
'GET',
'/castle/api/v1/accounts',
this.g.user.wallets[0].inkey
)
this.accounts = response.data
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
async submitExpense() {
this.expenseDialog.loading = true
try {
await LNbits.api.request(
'POST',
'/castle/api/v1/entries/expense',
this.g.user.wallets[0].inkey,
{
description: this.expenseDialog.description,
amount: this.expenseDialog.amount,
expense_account: this.expenseDialog.expenseAccount,
is_equity: this.expenseDialog.isEquity,
user_wallet: this.g.user.wallets[0].id,
reference: this.expenseDialog.reference || null
}
)
this.$q.notify({
type: 'positive',
message: 'Expense added successfully'
})
this.expenseDialog.show = false
this.resetExpenseDialog()
await this.loadBalance()
await this.loadTransactions()
} catch (error) {
LNbits.utils.notifyApiError(error)
} finally {
this.expenseDialog.loading = false
}
},
async submitPayment() {
this.payDialog.loading = true
try {
// First, generate an invoice for the payment
const invoiceResponse = await LNbits.api.request(
'POST',
'/api/v1/payments',
this.g.user.wallets[0].inkey,
{
out: false,
amount: this.payDialog.amount,
memo: `Payment to Castle - ${this.payDialog.amount} sats`,
unit: 'sat'
}
)
// Show the invoice to the user
this.$q.notify({
type: 'positive',
message: 'Invoice generated! Pay it to settle your balance.',
timeout: 5000
})
// TODO: After payment, call /castle/api/v1/pay-balance to record it
// This would typically be done via a webhook or payment verification
this.payDialog.show = false
this.payDialog.amount = null
} catch (error) {
LNbits.utils.notifyApiError(error)
} finally {
this.payDialog.loading = false
}
},
showPayBalanceDialog() {
this.payDialog.amount = Math.abs(this.balance.balance)
this.payDialog.show = true
},
resetExpenseDialog() {
this.expenseDialog.description = ''
this.expenseDialog.amount = null
this.expenseDialog.expenseAccount = ''
this.expenseDialog.isEquity = false
this.expenseDialog.reference = ''
},
formatSats(amount) {
return new Intl.NumberFormat().format(amount)
},
formatDate(dateString) {
return new Date(dateString).toLocaleDateString()
},
getTotalAmount(entry) {
if (!entry.lines || entry.lines.length === 0) return 0
return entry.lines.reduce((sum, line) => sum + line.debit + line.credit, 0) / 2
}
},
async created() {
await this.loadBalance()
await this.loadTransactions()
await this.loadAccounts()
}
})