From 46c7fdddb7ad8ea46daa3d24811a069c53c524cd Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Mon, 5 Aug 2024 16:52:57 +0100 Subject: [PATCH] feat: allow custom memo on invoice --- static/js/tpos.js | 37 ++++++++++++++++++++++++++++--------- views_api.py | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/static/js/tpos.js b/static/js/tpos.js index 8ade174..b92b903 100644 --- a/static/js/tpos.js +++ b/static/js/tpos.js @@ -100,7 +100,8 @@ const tposJS = async () => { searchTerm: '', categoryFilter: '', cart: new Map(), - denomIsSats: tpos.currency == 'sats' + denomIsSats: tpos.currency == 'sats', + customMemo: '' } }, computed: { @@ -408,14 +409,28 @@ const tposJS = async () => { }) return } - - if (this.tip_options && this.tip_options.length) { - this.rounding = false - this.tipRounding = null - this.showTipModal() - } else { - this.showInvoice() - } + this.$q + .dialog({ + title: 'Prompt', + message: 'Add a memo to the invoice?', + prompt: { + model: '', + isValid: val => val.length > 2, + type: 'text' + }, + cancel: true, + persistent: false + }) + .onDismiss(data => { + this.customMemo = data.trim() + if (this.tip_options && this.tip_options.length) { + this.rounding = false + this.tipRounding = null + this.showTipModal() + } else { + this.showInvoice() + } + }) }, showTipModal: function () { if (!this.atmMode) { @@ -436,6 +451,10 @@ const tposJS = async () => { memo: this.amountFormatted, tipAmount: this.tipAmountSat } + + if (this.customMemo && this.customMemo.length > 2) { + params.memo = this.customMemo + } if (this.cart.size) { let details = [...this.cart.values()].map(item => { return { diff --git a/views_api.py b/views_api.py index 7102960..106529e 100644 --- a/views_api.py +++ b/views_api.py @@ -120,7 +120,7 @@ async def api_tpos_create_invoice( payment_hash, payment_request = await create_invoice( wallet_id=tpos.wallet, amount=amount, - memo=f"{memo} to {tpos.name}" if memo else f"{tpos.name}", + memo=f"{memo} - ({tpos.name})" if memo else f"{tpos.name}", extra={ "tag": "tpos", "tipAmount": tip_amount,