@@ -30,8 +31,9 @@ page_container %}
-
+
+
+
+
-
+ > -->
-
+
-
+
@@ -371,8 +376,9 @@ page_container %}
color="primary"
:disable="payInvoiceData.data.request == ''"
type="submit"
- >ReadContinue
+
Cancel
@@ -595,7 +601,7 @@ page_container %}
-
+
@@ -885,20 +891,6 @@ page_container %}
return this.payments.findIndex(payment => payment.pending) !== -1
},
- tokenList: function () {
- const x = this.proofs
- .map(t => t.amount)
- .reduce((acc, amount) => {
- acc[amount] = acc[amount] + amount || 1
- return acc
- }, {})
- return Object.keys(x).map(k => ({
- value: k,
- count: x[k],
- sum: k * x[k]
- }))
- },
-
balance: function () {
return this.proofs
.map(t => t)
@@ -931,7 +923,7 @@ page_container %}
sum: k * x[k]
}))
},
-
+
paymentTableRowKey: function (row) {
return row.payment_hash + row.amount
},
@@ -1376,7 +1368,7 @@ page_container %}
sumProofs: function (proofs) {
return proofs.reduce((s, t) => (s += t.amount), 0)
},
- splitToSend: async function (proofs, amount) {
+ splitToSend: async function (proofs, amount, invlalidate = false) {
try {
const spendableProofs = proofs.filter(p => !p.reserved)
if (this.sumProofs(spendableProofs) < amount) {
@@ -1395,11 +1387,13 @@ page_container %}
this.proofs[i].reserved = true
}
}
+ if (invlalidate) {
+ // delete tokens from db
+ this.proofs = fristProofs
+ // add new fristProofs, scndProofs to this.proofs
+ this.storeProofs()
+ }
- // delete tokens from db
- this.proofs = fristProofs
- // add new fristProofs, scndProofs to this.proofs
- this.storeProofs()
return {fristProofs, scndProofs}
} catch (error) {
console.error(error)
@@ -1508,7 +1502,8 @@ page_container %}
// keep firstProofs, send scndProofs
let {fristProofs, scndProofs} = await this.splitToSend(
this.proofs,
- this.sendData.amount
+ this.sendData.amount,
+ true
)
this.sendData.tokens = ''
this.sendData.tokensBase64 = ''
@@ -1516,11 +1511,39 @@ page_container %}
console.log('### this.sendData.tokens', this.sendData.tokens)
this.sendData.tokensBase64 = btoa(JSON.stringify(this.sendData.tokens))
},
-
+ checkFees: async function (payment_request) {
+ const payload = {
+ pr: payment_request
+ }
+ console.log('#### payload', JSON.stringify(payload))
+ try {
+ const {data} = await LNbits.api.request(
+ 'POST',
+ `/cashu/api/v1/${this.mintId}/checkfees`,
+ '',
+ payload
+ )
+ console.log('#### checkFees', payment_request, data.fee)
+ return data.fee
+ } catch (error) {
+ console.error(error)
+ LNbits.utils.notifyApiError(error)
+ throw error
+ }
+ },
melt: async function () {
// todo: get fees from server and add to inputs
console.log('#### pay lightning')
- const amount = this.payInvoiceData.invoice.sat
+ const amount_invoice = this.payInvoiceData.invoice.sat
+ const amount =
+ amount_invoice +
+ (await this.checkFees(this.payInvoiceData.data.request))
+ console.log(
+ '#### amount invoice',
+ amount_invoice,
+ 'amount with fees',
+ amount
+ )
// if (amount > balance()) {
// LNbits.utils.notifyApiError('Balance too low')
// return
@@ -1547,8 +1570,30 @@ page_container %}
type: 'positive',
message: 'Invoice paid'
})
- this.payInvoiceData.invoice = null
+ // delete tokens from db
+ this.proofs = fristProofs
+ // add new fristProofs, scndProofs to this.proofs
+ this.storeProofs()
+ console.log({
+ amount: -amount,
+ bolt11: this.payInvoiceData.data.request,
+ hash: this.payInvoiceData.data.hash,
+ memo: this.payInvoiceData.data.memo,
+ })
+ this.invoicesCashu.push({
+ amount: -amount,
+ bolt11: this.payInvoiceData.data.request,
+ hash: this.payInvoiceData.data.hash,
+ memo: this.payInvoiceData.data.memo,
+ date: currentDateStr(),
+ status: 'paid'
+ })
+ this.storeinvoicesCashu()
+ this.tab = 'invoices'
+
+ this.payInvoiceData.invoice = false
this.payInvoiceData.show = false
+
} catch (error) {
console.error(error)
LNbits.utils.notifyApiError(error)
@@ -1558,7 +1603,7 @@ page_container %}
recheckPendingInvoices: async function () {
for (const invoice of this.invoicesCashu) {
- if (invoice.status === 'pending') {
+ if (invoice.status === 'pending' && invoice.sat > 0) {
this.recheckInvoice(invoice.hash, false)
}
}