diff --git a/lnbits/extensions/cashu/config.json b/lnbits/extensions/cashu/config.json index 99838eb4f..af202d43c 100644 --- a/lnbits/extensions/cashu/config.json +++ b/lnbits/extensions/cashu/config.json @@ -1,7 +1,7 @@ { - "name": "Cashu Ecash", + "name": "Cashu", "short_description": "Ecash mint and wallet", - "icon": "approval", - "contributors": ["arcbtc", "calle", "vlad"], + "icon": "account_balance", + "contributors": ["calle", "vlad", "arcbtc"], "hidden": false } diff --git a/lnbits/extensions/cashu/config.json.example b/lnbits/extensions/cashu/config.json.example index e798e2ef3..0cb4043da 100644 --- a/lnbits/extensions/cashu/config.json.example +++ b/lnbits/extensions/cashu/config.json.example @@ -1,7 +1,7 @@ { - "name": "Cashu Ecash", + "name": "Cashu", "short_description": "Ecash mints with LN peg in/out", - "icon": "approval", - "contributors": ["arcbtc", "calle"], + "icon": "account_balance", + "contributors": ["calle", "vlad", "arcbtc"], "hidden": true } diff --git a/lnbits/extensions/cashu/templates/cashu/index.html b/lnbits/extensions/cashu/templates/cashu/index.html index 20ed567ca..f54b39b15 100644 --- a/lnbits/extensions/cashu/templates/cashu/index.html +++ b/lnbits/extensions/cashu/templates/cashu/index.html @@ -46,12 +46,12 @@ unelevated dense size="xs" - icon="launch" + icon="account_balance_wallet" :color="($q.dark.isActive) ? 'grey-7' : 'grey-5'" type="a" - :href="'wallet/?tsh=' + (props.row.tickershort || '') + '&mint_id=' + props.row.id + '&mint_name=' + props.row.name" + :href="'wallet/?' + 'mint_id=' + props.row.id" target="_blank" - >Shareable wallet pageShareable wallet Create invoice + >Receive invoice
@@ -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) } }